Exemplo n.º 1
0
 def test_serialize(self):
     attr = VersionAttribute()
     assert attr.attr_type == NUMBER
     assert attr.serialize(3.141) == '3'
     assert attr.serialize(1) == '1'
     assert attr.serialize(12345678909876543211234234324234
                           ) == '12345678909876543211234234324234'
Exemplo n.º 2
0
class Poll(Model):
    """
    A DynamoDB User
    """
    class Meta:
        table_name = DYNAMO_DB_TABLE_NAME
    key = UnicodeAttribute(hash_key=True)

    question = UnicodeAttribute()
    author = JSONAttribute()
    # option_id is index of the option in the list
    options = ListAttribute(default=list)
    votes = MapAttribute(default=dict)  # user_id -> option_id
    users = MapAttribute(default=dict)   # user_id -> data
    # see https://pynamodb.readthedocs.io/en/latest/optimistic_locking.html
    version = VersionAttribute()
    # information about poll message in telegram
    telegram_version = NumberAttribute()
    telegram_datetime = UTCDateTimeAttribute()

    def get_users_by_option_id(self):
        users_by_option_id = {}
        for user_id in self.votes:
            option_id = self.votes[user_id]
            users_by_option_id.setdefault(option_id, [])
            users_by_option_id[option_id].append(self.users[user_id])
        return users_by_option_id
Exemplo n.º 3
0
        class TestModelC(TestModelA):
            class Meta:
                region = 'us-east-1'
                table_name = 'pynamodb-ci-c'
                host = ddb_url

            version_invalid = VersionAttribute()
Exemplo n.º 4
0
class MockModel(Model):
    class Meta:
        table_name = 'mock'

    mock_hash = NumberAttribute(hash_key=True)
    mock_range = NumberAttribute(range_key=True)
    mock_toot = UnicodeAttribute(null=True)
    mock_version = VersionAttribute()
Exemplo n.º 5
0
class Foo(Model):
    class Meta:
        region = 'us-east-1'
        table_name = 'foo'

    bar = NumberAttribute(hash_key=True)
    star = UnicodeAttribute(null=True)
    version = VersionAttribute()
Exemplo n.º 6
0
class Office(Model):
    class Meta:
        read_capacity_units = 1
        write_capacity_units = 1
        table_name = 'Office'
        host = "http://localhost:8000"
    office_id = UnicodeAttribute(hash_key=True)
    employees = ListAttribute(of=OfficeEmployeeMap)
    name = UnicodeAttribute()
    version = VersionAttribute()
Exemplo n.º 7
0
    class TestModelA(Model):
        """
        A model for testing
        """
        class Meta:
            region = 'us-east-1'
            table_name = 'pynamodb-ci-a'
            host = ddb_url

        forum = UnicodeAttribute(hash_key=True)
        thread = UnicodeAttribute(range_key=True)
        scores = NumberAttribute()
        version = VersionAttribute()
Exemplo n.º 8
0
    class TestModel(Model):
        """
        A model for testing
        """
        class Meta:
            region = 'us-east-1'
            table_name = 'pynamodb-ci'
            host = ddb_url

        forum = UnicodeAttribute(hash_key=True)
        thread = UnicodeAttribute(range_key=True)
        view = NumberAttribute(default=0)
        view_index = LSIndex()
        epoch_index = GSIndex()
        epoch = UTCDateTimeAttribute(default=datetime.now)
        content = BinaryAttribute(null=True)
        scores = NumberSetAttribute()
        version = VersionAttribute()
Exemplo n.º 9
0
 def test_deserialize(self):
     attr = VersionAttribute()
     assert attr.deserialize('1') == 1
     assert attr.deserialize('3.141') == 3
     assert attr.deserialize('12345678909876543211234234324234'
                             ) == 12345678909876543211234234324234
class MyDocument(BaseDocument, discriminator="my_document"):
    status = UnicodeEnumAttribute(MyStatus, default=MyStatus.CREATED)
    content = UnicodeAttribute()
    tokens = BinarySetAttribute()
    version = VersionAttribute(null=True)
    cls = DiscriminatorAttribute()