nailgun.entity_fields¶
The basic components of the NailGun ORM.
Each of the fields in this module corresponds to some type of information that
Satellite tracks. When paired the classes in nailgun.entity_mixins, it
is possible to represent the entities that Satellite manages. For a concrete
example of how this works, see nailgun.entity_mixins.Entity.
Fields are typically used declaratively in an entity’s __init__ function
and are otherwise left untouched, except by the mixin methods. For example,
nailgun.entity_mixins.EntityReadMixin.read() looks at the fields on an
entity to determine what information it should expect the server to return.
A secondary use of fields is to generate random data. For example, you could
call User.get_fields()['login'].gen_value() to generate a random login.
(gen_value is implemented at StringField.gen_value()) Beware that the
gen_value methods strive to produce the most outrageous values that are
still legal, so they will often return nonsense UTF-8 values, which is
unpleasant to work with manually.
-
class
nailgun.entity_fields.BooleanField(required=False, choices=None, default=<object object>, unique=False, parent=False)¶ Field that represents a boolean
-
gen_value()¶ Return a value suitable for a
BooleanField.
-
-
class
nailgun.entity_fields.DateField(min_date=None, max_date=None, *args, **kwargs)¶ Field that represents a date
-
class
nailgun.entity_fields.DateTimeField(min_date=None, max_date=None, *args, **kwargs)¶ Field that represents a datetime
-
gen_value()¶ Return a value suitable for a
DateTimeField.
-
-
class
nailgun.entity_fields.DictField(required=False, choices=None, default=<object object>, unique=False, parent=False)¶ Field that represents a set of key-value pairs.
-
class
nailgun.entity_fields.EmailField(required=False, choices=None, default=<object object>, unique=False, parent=False)¶ Field that represents an email
-
gen_value()¶ Return a value suitable for a
EmailField.
-
-
class
nailgun.entity_fields.Field(required=False, choices=None, default=<object object>, unique=False, parent=False)¶ Base class to implement other fields
Record this field’s attributes.
Parameters: - required – A boolean. Determines whether a value must be submitted to the server when creating or updating an entity.
- choices – A tuple of values that this field may be populated with.
- default – Entity classes that inherit from
nailgun.entity_mixins.EntityCreateMixinuse this field. - unique – A boolean. Determines if the entity should be unique with its name.
- parent – A boolean. Determines if the Entity is a parent entity to one_to_one mapped entity
-
class
nailgun.entity_fields.FloatField(required=False, choices=None, default=<object object>, unique=False, parent=False)¶ Field that represents a float
-
gen_value()¶ Return a value suitable for a
FloatField.
-
-
class
nailgun.entity_fields.IPAddressField(length=(1, 30), str_type=('utf8', ), *args, **kwargs)¶ Field that represents an IP address
-
gen_value()¶ Return a value suitable for a
IPAddressField.
-
-
class
nailgun.entity_fields.IntegerField(min_val=None, max_val=None, *args, **kwargs)¶ Field that represents an integer.
-
gen_value()¶ Return a value suitable for a
IntegerField.
-
-
class
nailgun.entity_fields.ListField(required=False, choices=None, default=<object object>, unique=False, parent=False)¶ Field that represents a list of strings
-
class
nailgun.entity_fields.MACAddressField(length=(1, 30), str_type=('utf8', ), *args, **kwargs)¶ Field that represents a MAC address
-
gen_value()¶ Return a value suitable for a
MACAddressField.
-
-
class
nailgun.entity_fields.NetmaskField(length=(1, 30), str_type=('utf8', ), *args, **kwargs)¶ Field that represents an netmask
-
gen_value()¶ Return a value suitable for a
NetmaskField.
-
-
class
nailgun.entity_fields.OneToManyField(entity, *args, **kwargs)¶ Field that represents a reference to zero or more other entities.
Parameters: entity (nailgun.entity_mixins.Entity) – The entities to which this field points. -
gen_value()¶ Return the class that this field references.
-
-
class
nailgun.entity_fields.OneToOneField(entity, *args, **kwargs)¶ Field that represents a reference to another entity.
All parameters not documented here are passed to
Field.Parameters: entity (nailgun.entity_mixins.Entity) – The entity to which this field points. -
gen_value()¶ Return the class that this field references.
-
-
class
nailgun.entity_fields.StringField(length=(1, 30), str_type=('utf8', ), *args, **kwargs)¶ Field that represents a string.
The default
lengthof string fields is short for two reasons:- Foreman’s database backend limits many fields to 255 bytes in length. As
a result,
lengthshould be no longer than 85 characters long, as 85 unicode characters may be up to 255 bytes long. - Humans have to read through the error messages produced by this library.
Long error messages are hard to read through, and that hurts
productivity. Thus, a
lengtheven shorter than 85 chars is desirable.
Parameters: - length – Either a
(min_len, max_len)tuple or anexact_leninteger. - str_type – The types of characters to generate when
StringField.gen_value()is called. May be a single string type (e.g.'utf8') or a tuple of string types. This argument is passed through to FauxFactory’sgen_stringmethod, so this method accepts all string types which that method does.
-
gen_value()¶ Return a value suitable for a
StringField.
- Foreman’s database backend limits many fields to 255 bytes in length. As
a result,