How to use the pynamodb.attributes.UnicodeSetAttribute function in pynamodb

To help you get started, we’ve selected a few pynamodb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pynamodb / PynamoDB / tests / test_attributes.py View on Github external
def test_round_trip_unicode_set(self):
        """
        Round trip a unicode set
        """
        attr = UnicodeSetAttribute()
        orig = {six.u('foo'), six.u('bar')}
        assert orig == attr.deserialize(attr.serialize(orig))

        orig = {six.u('true'), six.u('false')}
        assert orig == attr.deserialize(attr.serialize(orig))

        orig = {six.u('1'), six.u('2.8')}
        assert orig == attr.deserialize(attr.serialize(orig))

        orig = {six.u('[1,2,3]'), six.u('2.8')}
        assert orig == attr.deserialize(attr.serialize(orig))
github pynamodb / PynamoDB / tests / test_attributes.py View on Github external
def test_unicode_set_attribute(self):
        """
        UnicodeSetAttribute.default
        """
        attr = UnicodeSetAttribute()
        assert attr is not None
        assert attr.attr_type == STRING_SET
        attr = UnicodeSetAttribute(default={six.u('foo'), six.u('bar')})
        assert attr.default == {six.u('foo'), six.u('bar')}
github pynamodb / PynamoDB / tests / test_model.py View on Github external
icons = BinarySetAttribute()


class LocalIndexedModel(Model):
    """
    A model with an index
    """

    class Meta:
        table_name = 'LocalIndexedModel'

    user_name = UnicodeAttribute(hash_key=True)
    email = UnicodeAttribute()
    email_index = LocalEmailIndex()
    numbers = NumberSetAttribute()
    aliases = UnicodeSetAttribute()
    icons = BinarySetAttribute()


class SimpleUserModel(Model):
    """
    A hash key only model
    """

    class Meta:
        table_name = 'SimpleModel'

    user_name = UnicodeAttribute(hash_key=True)
    email = UnicodeAttribute()
    numbers = NumberSetAttribute()
    custom_aliases = UnicodeSetAttribute(attr_name='aliases')
    icons = BinarySetAttribute()
github pynamodb / PynamoDB / tests / test_attributes.py View on Github external
def test_unicode_set_attribute(self):
        """
        UnicodeSetAttribute.default
        """
        attr = UnicodeSetAttribute()
        assert attr is not None
        assert attr.attr_type == STRING_SET
        attr = UnicodeSetAttribute(default={six.u('foo'), six.u('bar')})
        assert attr.default == {six.u('foo'), six.u('bar')}
github pynamodb / PynamoDB / tests / test_attributes.py View on Github external
UTC = tzutc()


class AttributeTestModel(Model):

    class Meta:
        host = 'http://localhost:8000'
        table_name = 'test'

    binary_attr = BinaryAttribute()
    binary_set_attr = BinarySetAttribute()
    number_attr = NumberAttribute()
    number_set_attr = NumberSetAttribute()
    unicode_attr = UnicodeAttribute()
    unicode_set_attr = UnicodeSetAttribute()
    datetime_attr = UTCDateTimeAttribute()
    bool_attr = BooleanAttribute()
    json_attr = JSONAttribute()
    map_attr = MapAttribute()
    ttl_attr = TTLAttribute()


class CustomAttrMap(MapAttribute):
    overridden_number_attr = NumberAttribute(attr_name="number_attr")
    overridden_unicode_attr = UnicodeAttribute(attr_name="unicode_attr")


class DefaultsMap(MapAttribute):
    map_field = MapAttribute(default={})
    string_field = UnicodeAttribute(null=True)
github communitybridge / easycla / cla-backend / cla / models / dynamo_models.py View on Github external
gerrit = Gerrit()
            gerrit.model = gerrit_model
            ret.append(gerrit)
        return ret

class UserPermissionsModel(BaseModel):
    """
    Represents user permissions in the database.
    """
    class Meta:
        """Meta class for User Permissions."""
        table_name = 'cla-{}-user-permissions'.format(stage)
        if stage == 'local':
            host = 'http://localhost:8000'
    username = UnicodeAttribute(hash_key=True)
    projects = UnicodeSetAttribute(default=set())

class UserPermissions(model_interfaces.UserPermissions): # pylint: disable=too-many-public-methods
    """
    ORM-agnostic wrapper for the DynamoDB UserPermissions model.
    """
    def __init__(self, username=None, projects=None):
        super(UserPermissions).__init__()
        self.model = UserPermissionsModel()
        self.model.username = username
        if projects is not None:
            self.model.projects = set(projects)

    def add_project(self, project_id: str):
        if self.model is not None and self.model.projects is not None:
            self.model.projects.add(project_id)
github communitybridge / easycla / cla-backend / cla / models / dynamo_models.py View on Github external
class UserPermissionsModel(BaseModel):
    """
    Represents user permissions in the database.
    """

    class Meta:
        """Meta class for User Permissions."""

        table_name = "cla-{}-user-permissions".format(stage)
        if stage == "local":
            host = "http://localhost:8000"

    username = UnicodeAttribute(hash_key=True)
    projects = UnicodeSetAttribute(default=set())


class UserPermissions(model_interfaces.UserPermissions):  # pylint: disable=too-many-public-methods
    """
    ORM-agnostic wrapper for the DynamoDB UserPermissions model.
    """

    def __init__(self, username=None, projects=None):
        super(UserPermissions).__init__()
        self.model = UserPermissionsModel()
        self.model.username = username
        if projects is not None:
            self.model.projects = set(projects)

    def add_project(self, project_id: str):
        if self.model is not None and self.model.projects is not None:
github communitybridge / easycla / cla-backend / cla / models / dynamo_models.py View on Github external
"""
    class Meta:
        """Meta class for Project."""
        table_name = 'cla-{}-projects'.format(stage)
        if stage == 'local':
            host = 'http://localhost:8000'      
    project_id = UnicodeAttribute(hash_key=True)
    project_external_id = UnicodeAttribute()
    project_name = UnicodeAttribute()
    project_individual_documents = ListAttribute(of=DocumentModel, default=[])
    project_corporate_documents = ListAttribute(of=DocumentModel, default=[])
    project_icla_enabled = BooleanAttribute(default=True)
    project_ccla_enabled = BooleanAttribute(default=True)
    project_ccla_requires_icla_signature = BooleanAttribute(default=False)
    project_external_id_index = ExternalProjectIndex()
    project_acl = UnicodeSetAttribute(default=set())

class Project(model_interfaces.Project): # pylint: disable=too-many-public-methods
    """
    ORM-agnostic wrapper for the DynamoDB Project model.
    """
    def __init__(self, project_id=None, project_external_id=None, project_name=None,
                 project_icla_enabled=True, project_ccla_enabled=True,
                 project_ccla_requires_icla_signature=False,
                 project_acl=None):
        super(Project).__init__()
        self.model = ProjectModel()
        self.model.project_id = project_id
        self.model.project_external_id = project_external_id
        self.model.project_name = project_name
        self.model.project_icla_enabled = project_icla_enabled
        self.model.project_ccla_enabled = project_ccla_enabled
github communitybridge / easycla / cla-backend / cla / models / dynamo_models.py View on Github external
Represents an company in the database.
    """

    class Meta:
        """Meta class for Company."""

        table_name = "cla-{}-companies".format(stage)
        if stage == "local":
            host = "http://localhost:8000"

    company_id = UnicodeAttribute(hash_key=True)
    company_external_id = UnicodeAttribute(null=True)
    company_manager_id = UnicodeAttribute(null=True)
    company_name = UnicodeAttribute()
    company_external_id_index = ExternalCompanyIndex()
    company_acl = UnicodeSetAttribute(default=set())


class Company(model_interfaces.Company):  # pylint: disable=too-many-public-methods
    """
    ORM-agnostic wrapper for the DynamoDB Company model.
    """

    def __init__(
            self,  # pylint: disable=too-many-arguments
            company_id=None,
            company_external_id=None,
            company_manager_id=None,
            company_name=None,
            company_acl=None,
    ):
        super(Company).__init__()
github pynamodb / PynamoDB / examples / model.py View on Github external
print("-"*80)


# A model that uses aliased attribute names
class AliasedModel(Model):
    class Meta:
        table_name = "AliasedModel"
        host = "http://localhost:8000"
    forum_name = UnicodeAttribute(hash_key=True, attr_name='fn')
    subject = UnicodeAttribute(range_key=True, attr_name='s')
    views = NumberAttribute(default=0, attr_name='v')
    replies = NumberAttribute(default=0, attr_name='rp')
    answered = NumberAttribute(default=0, attr_name='an')
    tags = UnicodeSetAttribute(attr_name='t')
    last_post_datetime = UTCDateTimeAttribute(attr_name='lp')

if not AliasedModel.exists():
    AliasedModel.create_table(read_capacity_units=1, write_capacity_units=1, wait=True)

# Create a thread
thread_item = AliasedModel(
    'Some Forum',
    'Some Subject',
    tags=['foo', 'bar'],
    last_post_datetime=datetime.now()
)

# Save the thread
thread_item.save()