Python google.appengine.ext.ndb.IntegerProperty() Examples

The following are 30 code examples for showing how to use google.appengine.ext.ndb.IntegerProperty(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module google.appengine.ext.ndb , or try the search function .

Example 1
Project: python-docs-samples   Author: GoogleCloudPlatform   File: snippets.py    License: Apache License 2.0 6 votes vote down vote up
def query_purchase_with_customer_key():
    # [START purchase_with_customer_key_models]
    class Customer(ndb.Model):
        name = ndb.StringProperty()

    class Purchase(ndb.Model):
        customer = ndb.KeyProperty(kind=Customer)
        price = ndb.IntegerProperty()
    # [END purchase_with_customer_key_models]

    def query_purchases_for_customer_via_key(customer_entity):
        purchases = Purchase.query(
            Purchase.customer == customer_entity.key).fetch()
        return purchases

    return Customer, Purchase, query_purchases_for_customer_via_key 
Example 2
Project: python-docs-samples   Author: GoogleCloudPlatform   File: snippets.py    License: Apache License 2.0 6 votes vote down vote up
def query_purchase_with_ancestor_key():
    # [START purchase_with_ancestor_key_models]
    class Customer(ndb.Model):
        name = ndb.StringProperty()

    class Purchase(ndb.Model):
        price = ndb.IntegerProperty()
    # [END purchase_with_ancestor_key_models]

    def create_purchase_for_customer_with_ancestor(customer_entity):
        purchase = Purchase(parent=customer_entity.key)
        return purchase

    def query_for_purchases_of_customer_with_ancestor(customer_entity):
        purchases = Purchase.query(ancestor=customer_entity.key).fetch()
        return purchases

    return (Customer, Purchase,
            create_purchase_for_customer_with_ancestor,
            query_for_purchases_of_customer_with_ancestor) 
Example 3
Project: luci-py   Author: luci   File: monotonic_test.py    License: Apache License 2.0 6 votes vote down vote up
def test_store_new_version_extra(self):
    # Includes an unrelated entity in the PUT. It must be in the same entity
    # group.
    cls = monotonic.get_versioned_root_model('fidoula')
    parent = ndb.Key(cls, 'foo')
    class Unrelated(ndb.Model):
      b = ndb.IntegerProperty()
    unrelated = Unrelated(id='bar', parent=parent, b=42)
    actual = monotonic.store_new_version(
        EntityX(a=1, parent=parent), cls, extra=[unrelated])
    self.assertEqual(
        ndb.Key('fidoula', 'foo', 'EntityX', monotonic.HIGH_KEY_ID), actual)
    actual = monotonic.store_new_version(EntityX(a=2, parent=parent), cls)
    self.assertEqual(
        ndb.Key('fidoula', 'foo', 'EntityX', monotonic.HIGH_KEY_ID - 1), actual)
    self.assertEqual({'b': 42}, unrelated.key.get().to_dict()) 
Example 4
Project: luci-py   Author: luci   File: serializable_test.py    License: Apache License 2.0 6 votes vote down vote up
def _test_repeated_structured_properties_class(self, structured_cls):
    """Common testing for StructuredProperty and LocalStructuredProperty."""
    class Inner(ndb.Model):
      a = ndb.IntegerProperty()

    class Outter(ndb.Model, serializable.SerializableModelMixin):
      inner = structured_cls(Inner, repeated=True)

    # Repeated structured property -> list of dicts.
    entity = Outter()
    entity.inner.extend([Inner(a=1), Inner(a=2)])
    self.assertEqual(
        {'inner': [{'a': 1}, {'a': 2}]},
        entity.to_serializable_dict())

    # Reverse also works.
    self.assertEqual(
        entity,
        Outter.from_serializable_dict({'inner': [{'a': 1}, {'a': 2}]})) 
Example 5
Project: luci-py   Author: luci   File: serializable_test.py    License: Apache License 2.0 6 votes vote down vote up
def test_bad_type_for_repeated_property(self):
    """Trying to deserialize repeated property not from a list -> ValueError."""
    class Entity(ndb.Model, serializable.SerializableModelMixin):
      prop = ndb.IntegerProperty(repeated=True)

    # A list, tuple or nothing should work.
    Entity.from_serializable_dict({'prop': [1]})
    Entity.from_serializable_dict({'prop': (1,)})
    Entity.from_serializable_dict({})

    # A single item shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': 1})
    # 'None' shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': None})
    # Dict shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': {}}) 
Example 6
Project: luci-py   Author: luci   File: serializable_test.py    License: Apache License 2.0 6 votes vote down vote up
def test_bad_type_for_repeated_property(self):
    """Trying to deserialize repeated property not from a list -> ValueError."""
    class Entity(ndb.Model, serializable.SerializableModelMixin):
      prop = ndb.IntegerProperty(repeated=True)

    # A list, tuple or nothing should work.
    Entity.from_serializable_dict({'prop': [1]})
    Entity.from_serializable_dict({'prop': (1,)})
    Entity.from_serializable_dict({})

    # A single item shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': 1})
    # 'None' shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': None})
    # Dict shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': {}}) 
Example 7
Project: luci-py   Author: luci   File: monotonic_test.py    License: Apache License 2.0 6 votes vote down vote up
def test_store_new_version_extra(self):
    # Includes an unrelated entity in the PUT. It must be in the same entity
    # group.
    cls = monotonic.get_versioned_root_model('fidoula')
    parent = ndb.Key(cls, 'foo')
    class Unrelated(ndb.Model):
      b = ndb.IntegerProperty()
    unrelated = Unrelated(id='bar', parent=parent, b=42)
    actual = monotonic.store_new_version(
        EntityX(a=1, parent=parent), cls, extra=[unrelated])
    self.assertEqual(
        ndb.Key('fidoula', 'foo', 'EntityX', monotonic.HIGH_KEY_ID), actual)
    actual = monotonic.store_new_version(EntityX(a=2, parent=parent), cls)
    self.assertEqual(
        ndb.Key('fidoula', 'foo', 'EntityX', monotonic.HIGH_KEY_ID - 1), actual)
    self.assertEqual({'b': 42}, unrelated.key.get().to_dict()) 
Example 8
Project: luci-py   Author: luci   File: serializable_test.py    License: Apache License 2.0 6 votes vote down vote up
def _test_repeated_structured_properties_class(self, structured_cls):
    """Common testing for StructuredProperty and LocalStructuredProperty."""
    class Inner(ndb.Model):
      a = ndb.IntegerProperty()

    class Outter(ndb.Model, serializable.SerializableModelMixin):
      inner = structured_cls(Inner, repeated=True)

    # Repeated structured property -> list of dicts.
    entity = Outter()
    entity.inner.extend([Inner(a=1), Inner(a=2)])
    self.assertEqual(
        {'inner': [{'a': 1}, {'a': 2}]},
        entity.to_serializable_dict())

    # Reverse also works.
    self.assertEqual(
        entity,
        Outter.from_serializable_dict({'inner': [{'a': 1}, {'a': 2}]})) 
Example 9
Project: luci-py   Author: luci   File: serializable_test.py    License: Apache License 2.0 6 votes vote down vote up
def test_bad_type_for_repeated_property(self):
    """Trying to deserialize repeated property not from a list -> ValueError."""
    class Entity(ndb.Model, serializable.SerializableModelMixin):
      prop = ndb.IntegerProperty(repeated=True)

    # A list, tuple or nothing should work.
    Entity.from_serializable_dict({'prop': [1]})
    Entity.from_serializable_dict({'prop': (1,)})
    Entity.from_serializable_dict({})

    # A single item shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': 1})
    # 'None' shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': None})
    # Dict shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': {}}) 
Example 10
Project: luci-py   Author: luci   File: serializable_test.py    License: Apache License 2.0 6 votes vote down vote up
def test_bad_type_for_repeated_property(self):
    """Trying to deserialize repeated property not from a list -> ValueError."""
    class Entity(ndb.Model, serializable.SerializableModelMixin):
      prop = ndb.IntegerProperty(repeated=True)

    # A list, tuple or nothing should work.
    Entity.from_serializable_dict({'prop': [1]})
    Entity.from_serializable_dict({'prop': (1,)})
    Entity.from_serializable_dict({})

    # A single item shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': 1})
    # 'None' shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': None})
    # Dict shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': {}}) 
Example 11
Project: luci-py   Author: luci   File: monotonic_test.py    License: Apache License 2.0 6 votes vote down vote up
def test_store_new_version_extra(self):
    # Includes an unrelated entity in the PUT. It must be in the same entity
    # group.
    cls = monotonic.get_versioned_root_model('fidoula')
    parent = ndb.Key(cls, 'foo')
    class Unrelated(ndb.Model):
      b = ndb.IntegerProperty()
    unrelated = Unrelated(id='bar', parent=parent, b=42)
    actual = monotonic.store_new_version(
        EntityX(a=1, parent=parent), cls, extra=[unrelated])
    self.assertEqual(
        ndb.Key('fidoula', 'foo', 'EntityX', monotonic.HIGH_KEY_ID), actual)
    actual = monotonic.store_new_version(EntityX(a=2, parent=parent), cls)
    self.assertEqual(
        ndb.Key('fidoula', 'foo', 'EntityX', monotonic.HIGH_KEY_ID - 1), actual)
    self.assertEqual({'b': 42}, unrelated.key.get().to_dict()) 
Example 12
Project: luci-py   Author: luci   File: serializable_test.py    License: Apache License 2.0 6 votes vote down vote up
def _test_repeated_structured_properties_class(self, structured_cls):
    """Common testing for StructuredProperty and LocalStructuredProperty."""
    class Inner(ndb.Model):
      a = ndb.IntegerProperty()

    class Outter(ndb.Model, serializable.SerializableModelMixin):
      inner = structured_cls(Inner, repeated=True)

    # Repeated structured property -> list of dicts.
    entity = Outter()
    entity.inner.extend([Inner(a=1), Inner(a=2)])
    self.assertEqual(
        {'inner': [{'a': 1}, {'a': 2}]},
        entity.to_serializable_dict())

    # Reverse also works.
    self.assertEqual(
        entity,
        Outter.from_serializable_dict({'inner': [{'a': 1}, {'a': 2}]})) 
Example 13
Project: luci-py   Author: luci   File: serializable_test.py    License: Apache License 2.0 6 votes vote down vote up
def test_bad_type_for_repeated_property(self):
    """Trying to deserialize repeated property not from a list -> ValueError."""
    class Entity(ndb.Model, serializable.SerializableModelMixin):
      prop = ndb.IntegerProperty(repeated=True)

    # A list, tuple or nothing should work.
    Entity.from_serializable_dict({'prop': [1]})
    Entity.from_serializable_dict({'prop': (1,)})
    Entity.from_serializable_dict({})

    # A single item shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': 1})
    # 'None' shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': None})
    # Dict shouldn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': {}}) 
Example 14
Project: loaner   Author: google   File: bigquery_test.py    License: Apache License 2.0 5 votes vote down vote up
def test_generate_entity_schema(self):

    class NestedTestModel(ndb.Model):
      nested_string_attribute = ndb.StringProperty()

    class TestModel(ndb.Model):
      string_attribute = ndb.StringProperty()
      integer_attribute = ndb.IntegerProperty()
      boolean_attribute = ndb.BooleanProperty()
      nested_attribute = ndb.StructuredProperty(NestedTestModel)

    schema = bigquery._generate_entity_schema(TestModel())
    expected_schema_names = _populate_schema_names(self.entity_schema)
    schema_names = _populate_schema_names(schema)
    self.assertCountEqual(expected_schema_names, schema_names) 
Example 15
Project: jbox   Author: jpush   File: ndb.py    License: MIT License 5 votes vote down vote up
def get_IntegerField(kwargs):
    """
    Returns an ``IntegerField``, applying the ``ndb.IntegerProperty`` range
    limits.
    """
    v = validators.NumberRange(min=-0x8000000000000000, max=0x7fffffffffffffff)
    kwargs['validators'].append(v)
    return f.IntegerField(**kwargs) 
Example 16
Project: jbox   Author: jpush   File: ndb.py    License: MIT License 5 votes vote down vote up
def convert_IntegerProperty(self, model, prop, kwargs):
        """Returns a form field for a ``ndb.IntegerProperty``."""
        if prop._repeated:
            return IntegerListPropertyField(**kwargs)
        return get_IntegerField(kwargs) 
Example 17
Project: locality-sensitive-hashing   Author: singhj   File: db_datastore.py    License: MIT License 5 votes vote down vote up
def __call__(cls, *args, **kwds):
        if kwds:
            #logging.info('Table called cls = %s, kwds = %s', cls, kwds)
            pass
        if cls not in cls._instances:
            cls._instances[cls] = super(Table, cls).__call__(*args, **{})
            datastore_type = {
                'text': ndb.StringProperty(),
                'list<bigint>': ndb.IntegerProperty(repeated = True),
                'list<int>': ndb.IntegerProperty(repeated = True),
                'int': ndb.IntegerProperty(),
                'ascii': ndb.StringProperty(indexed = False),
            }
            attr_list = kwds['attrs']
            attrs = {}
            for attr in attr_list:
                (name, typ) = tuple(attr.split())
                attrs[name] = copy.copy(datastore_type[typ])
            StorageProxy = type(cls.__name__, (ndb.Model,), attrs)

            setattr(cls._instances[cls], 'StorageProxy', StorageProxy)
            setattr(cls._instances[cls], 'attrs', kwds['attrs'])
            setattr(cls._instances[cls], 'p_keys', kwds['p_keys'])

            gql = "SELECT * FROM {name} WHERE {cond}"\
                .format(name = cls.__name__, cond = ' AND '.join([kwds['p_keys'][c]+'=:%d'%(c+1) for c in xrange(len(kwds['p_keys']))]))
            select = ndb.gql(gql)
            setattr(cls._instances[cls], 'select', select)

            parent_keys = kwds['p_keys'][1:]
            if parent_keys:
                gql = "SELECT * FROM {name} WHERE {cond}"\
                    .format(name = cls.__name__, cond = ' AND '.join([parent_keys[c]+'=:%d'%(c+1) for c in xrange(len(parent_keys))]))
                select_all_with_parent = ndb.gql(gql)
                setattr(cls._instances[cls], 'select_all_with_parent', select_all_with_parent)

        return cls._instances[cls] 
Example 18
Project: RSSNewsGAE   Author: liantian-cn   File: ndb.py    License: Apache License 2.0 5 votes vote down vote up
def get_IntegerField(kwargs):
    """
    Returns an ``IntegerField``, applying the ``ndb.IntegerProperty`` range
    limits.
    """
    v = validators.NumberRange(min=-0x8000000000000000, max=0x7fffffffffffffff)
    kwargs['validators'].append(v)
    return f.IntegerField(**kwargs) 
Example 19
Project: RSSNewsGAE   Author: liantian-cn   File: ndb.py    License: Apache License 2.0 5 votes vote down vote up
def convert_IntegerProperty(self, model, prop, kwargs):
        """Returns a form field for a ``ndb.IntegerProperty``."""
        if prop._repeated:
            return IntegerListPropertyField(**kwargs)
        return get_IntegerField(kwargs) 
Example 20
Project: graphene-gae   Author: graphql-python   File: test_converter.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def testIntProperty_shouldConvertToString(self):
        self.__assert_conversion(ndb.IntegerProperty, graphene.Int) 
Example 21
Project: googleapps-message-recall   Author: google   File: ndb.py    License: Apache License 2.0 5 votes vote down vote up
def get_IntegerField(kwargs):
    """
    Returns an ``IntegerField``, applying the ``ndb.IntegerProperty`` range
    limits.
    """
    v = validators.NumberRange(min=-0x8000000000000000, max=0x7fffffffffffffff)
    kwargs['validators'].append(v)
    return f.IntegerField(**kwargs) 
Example 22
Project: googleapps-message-recall   Author: google   File: ndb.py    License: Apache License 2.0 5 votes vote down vote up
def convert_IntegerProperty(self, model, prop, kwargs):
        """Returns a form field for a ``ndb.IntegerProperty``."""
        if prop._repeated:
            return IntegerListPropertyField(**kwargs)
        return get_IntegerField(kwargs) 
Example 23
Project: luci-py   Author: luci   File: monotonic.py    License: Apache License 2.0 5 votes vote down vote up
def get_versioned_root_model(model_name):
  """Returns a root model that can be used for versioned entities.

  Using this entity for get_versioned_most_recent(),
  get_versioned_most_recent_with_root() and store_new_version() is optional. Any
  entity with cls.current as an ndb.IntegerProperty will do.
  """
  assert isinstance(model_name, str), model_name
  class _Root(Root):
    @classmethod
    def _get_kind(cls):
      return model_name

  return _Root 
Example 24
Project: luci-py   Author: luci   File: serializable_test.py    License: Apache License 2.0 5 votes vote down vote up
def test_repeated_properties(self):
    """Test that properties with repeated=True are handled."""
    class IntsEntity(ndb.Model, serializable.SerializableModelMixin):
      ints = ndb.IntegerProperty(repeated=True)
    class DatesEntity(ndb.Model, serializable.SerializableModelMixin):
      dates = ndb.DateTimeProperty(repeated=True)

    # Same point in time as datetime and as timestamp.
    dt = datetime.datetime(2012, 1, 2, 3, 4, 5)
    ts = 1325473445000000

    # Repeated properties that are not set are converted to empty lists.
    self.assertEqual({'ints': []}, IntsEntity().to_serializable_dict())
    self.assertEqual({'dates': []}, DatesEntity().to_serializable_dict())

    # List of ints works (as an example of simple repeated property).
    self.assertEqual(
        {'ints': [1, 2]},
        IntsEntity(ints=[1, 2]).to_serializable_dict())
    self.assertEqual(
        {'ints': [1, 2]},
        IntsEntity.convert_serializable_dict({'ints': [1, 2]}))

    # List of datetimes works (as an example of not-so-simple property).
    self.assertEqual(
        {'dates': [ts, ts]},
        DatesEntity(dates=[dt, dt]).to_serializable_dict())
    self.assertEqual(
        {'dates': [dt, dt]},
        DatesEntity.convert_serializable_dict({'dates': [ts, ts]})) 
Example 25
Project: luci-py   Author: luci   File: serializable_test.py    License: Apache License 2.0 5 votes vote down vote up
def _test_structured_properties_class(self, structured_cls):
    """Common testing for StructuredProperty and LocalStructuredProperty."""
    # Plain ndb.Model.
    class InnerSimple(ndb.Model):
      a = ndb.IntegerProperty()

    # With SerializableModelMixin.
    class InnerSmart(ndb.Model, serializable.SerializableModelMixin):
      serializable_properties = {
        'a': serializable.READABLE | serializable.WRITABLE,
      }
      a = ndb.IntegerProperty()
      b = ndb.IntegerProperty()

    class Outter(ndb.Model, serializable.SerializableModelMixin):
      simple = structured_cls(InnerSimple)
      smart = structured_cls(InnerSmart)

    # InnerSimple gets serialized entirely, while only readable fields
    # on InnerSmart are serialized.
    entity = Outter()
    entity.simple = InnerSimple(a=1)
    entity.smart = InnerSmart(a=2, b=3)
    self.assertEqual(
        {'simple': {'a': 1}, 'smart': {'a': 2}},
        entity.to_serializable_dict())

    # Works backwards as well. Note that 'convert_serializable_dict' returns
    # a dictionary that can be fed to entity's 'populate' or constructor. Entity
    # by itself is smart enough to transform subdicts into structured
    # properties.
    self.assertEqual(
        Outter(simple=InnerSimple(a=1), smart=InnerSmart(a=2)),
        Outter.from_serializable_dict({'simple': {'a': 1}, 'smart': {'a': 2}})) 
Example 26
Project: luci-py   Author: luci   File: serializable_test.py    License: Apache License 2.0 5 votes vote down vote up
def test_exclude_works(self):
    """|exclude| argument of to_serializable_dict() is respected."""
    class Entity(ndb.Model, serializable.SerializableModelMixin):
      prop1 = ndb.IntegerProperty()
      prop2 = ndb.IntegerProperty()
      prop3 = ndb.IntegerProperty()

    entity = Entity(prop1=1, prop2=2, prop3=3)
    self.assertEqual(
        {'prop1': 1, 'prop3': 3},
        entity.to_serializable_dict(exclude=['prop2'])) 
Example 27
Project: luci-py   Author: luci   File: serializable_test.py    License: Apache License 2.0 5 votes vote down vote up
def test_from_serializable_dict_kwargs_work(self):
    """Keyword arguments in from_serializable_dict are passed to constructor."""
    class Entity(ndb.Model, serializable.SerializableModelMixin):
      prop = ndb.IntegerProperty()

    # Pass entity key via keyword parameters.
    entity = Entity.from_serializable_dict(
        {'prop': 123}, id='my id', parent=ndb.Key('Fake', 'parent'))
    self.assertEqual(123, entity.prop)
    self.assertEqual(ndb.Key('Fake', 'parent', 'Entity', 'my id'), entity.key) 
Example 28
Project: luci-py   Author: luci   File: serializable_test.py    License: Apache License 2.0 5 votes vote down vote up
def test_bad_type_for_simple_property(self):
    """Trying to deserialize non-number into IntegerProperty -> ValueError."""
    class Entity(ndb.Model, serializable.SerializableModelMixin):
      prop = ndb.IntegerProperty()

    # Works.
    Entity.from_serializable_dict({'prop': 123})
    # Doesn't.
    with self.assertRaises(ValueError):
      Entity.from_serializable_dict({'prop': 'abc'}) 
Example 29
Project: luci-py   Author: luci   File: monotonic.py    License: Apache License 2.0 5 votes vote down vote up
def get_versioned_root_model(model_name):
  """Returns a root model that can be used for versioned entities.

  Using this entity for get_versioned_most_recent(),
  get_versioned_most_recent_with_root() and store_new_version() is optional. Any
  entity with cls.current as an ndb.IntegerProperty will do.
  """
  assert isinstance(model_name, str), model_name
  class _Root(Root):
    @classmethod
    def _get_kind(cls):
      return model_name

  return _Root 
Example 30
Project: luci-py   Author: luci   File: serializable_test.py    License: Apache License 2.0 5 votes vote down vote up
def test_repeated_properties(self):
    """Test that properties with repeated=True are handled."""
    class IntsEntity(ndb.Model, serializable.SerializableModelMixin):
      ints = ndb.IntegerProperty(repeated=True)
    class DatesEntity(ndb.Model, serializable.SerializableModelMixin):
      dates = ndb.DateTimeProperty(repeated=True)

    # Same point in time as datetime and as timestamp.
    dt = datetime.datetime(2012, 1, 2, 3, 4, 5)
    ts = 1325473445000000

    # Repeated properties that are not set are converted to empty lists.
    self.assertEqual({'ints': []}, IntsEntity().to_serializable_dict())
    self.assertEqual({'dates': []}, DatesEntity().to_serializable_dict())

    # List of ints works (as an example of simple repeated property).
    self.assertEqual(
        {'ints': [1, 2]},
        IntsEntity(ints=[1, 2]).to_serializable_dict())
    self.assertEqual(
        {'ints': [1, 2]},
        IntsEntity.convert_serializable_dict({'ints': [1, 2]}))

    # List of datetimes works (as an example of not-so-simple property).
    self.assertEqual(
        {'dates': [ts, ts]},
        DatesEntity(dates=[dt, dt]).to_serializable_dict())
    self.assertEqual(
        {'dates': [dt, dt]},
        DatesEntity.convert_serializable_dict({'dates': [ts, ts]}))