Exemplo n.º 1
0
def test_autouuid_get_base_type():
    ('AutoUUID#get_base_type() should return the __base_type__')

    # Given an instance of autouuid
    autouuid = AutoUUID()

    # When I call get_base_type
    result = autouuid.get_base_type()

    # Then the result should be bytes
    result.should.equal(UUID)
Exemplo n.º 2
0
def test_autouuid_to_string():
    ('AutoUUID#to_string() should have cast the value as string')

    # Given an instance of autouuid
    autouuid = AutoUUID()

    # When I call to_string
    result = autouuid.to_string(str(test_uuid))

    # Then the result should be a string
    result.should.be.a(bytes)
Exemplo n.º 3
0
def test_autouuid_from_string():
    ('AutoUUID#from_string() should have cast the value as string')

    # Given an instance of autouuid
    autouuid = AutoUUID()

    # When I call from_string
    result = autouuid.from_string('3112edba-4b5d-11e5-b02e-6c4008a70392')

    # Then the result should be a UUID
    result.should.be.a(UUID)
Exemplo n.º 4
0
def test_autouuid_get_base_type():
    ('AutoUUID#get_base_type() should return the __base_type__')

    # Given an instance of autouuid
    autouuid = AutoUUID()

    # When I call get_base_type
    result = autouuid.get_base_type()

    # Then the result should be bytes
    result.should.equal(UUID)
Exemplo n.º 5
0
def test_autouuid_from_string():
    ('AutoUUID#from_string() should have cast the value as string')

    # Given an instance of autouuid
    autouuid = AutoUUID()

    # When I call from_string
    result = autouuid.from_string('3112edba-4b5d-11e5-b02e-6c4008a70392')

    # Then the result should be a UUID
    result.should.be.a(UUID)
Exemplo n.º 6
0
def test_autouuid_to_string():
    ('AutoUUID#to_string() should have cast the value as string')

    # Given an instance of autouuid
    autouuid = AutoUUID()

    # When I call to_string
    result = autouuid.to_string(str(test_uuid))

    # Then the result should be a string
    result.should.be.a(bytes)
Exemplo n.º 7
0
def test_autouuid_to_json():
    ('AutoUUID.to_json() should deserialize the given dict into a value')

    # Given an instance of autouuid
    autouuid = AutoUUID()

    # When I call to_json
    result = autouuid.to_json('3112edba-4b5d-11e5-b02e-6c4008a70392')

    # Then the result should be a value
    result.should.equal(
        '{"type": "AutoUUID", "value": "3112edba-4b5d-11e5-b02e-6c4008a70392", "module": "repocket.attributes"}'
    )
Exemplo n.º 8
0
def test_autouuid_to_json():
    ('AutoUUID.to_json() should deserialize the given dict into a value')

    # Given an instance of autouuid
    autouuid = AutoUUID()

    # When I call to_json
    result = autouuid.to_json('3112edba-4b5d-11e5-b02e-6c4008a70392')

    # Then the result should be a value
    result.should.equal(
        '{"type": "AutoUUID", "value": "3112edba-4b5d-11e5-b02e-6c4008a70392", "module": "repocket.attributes"}'
    )
Exemplo n.º 9
0
def test_autouuid_from_json():
    ('AutoUUID.from_json() should deserialize the given dict into a value')

    # Given an instance of autouuid
    autouuid = AutoUUID()

    # When I call from_json
    result = autouuid.from_json(json.dumps({
        b'module': b'repocket.attributes',
        b'type': b'AutoUUID',
        b'value': b'3112edba-4b5d-11e5-b02e-6c4008a70392',
    }))

    # Then the result should be a value
    result.should.equal(test_uuid)
Exemplo n.º 10
0
def test_autouuid_to_python():
    ('AutoUUID#to_python() should prepare data to be serialized')

    # Given an instance of autouuid
    autouuid = AutoUUID()

    # When I call to_python
    result = autouuid.to_python('3112edba-4b5d-11e5-b02e-6c4008a70392')

    # Then the result should be a dictionary with metadata
    result.should.equal({
        'module': 'repocket.attributes',
        'type': 'AutoUUID',
        'value': '3112edba-4b5d-11e5-b02e-6c4008a70392',
    })
Exemplo n.º 11
0
def test_autouuid_to_python():
    ('AutoUUID#to_python() should prepare data to be serialized')

    # Given an instance of autouuid
    autouuid = AutoUUID()

    # When I call to_python
    result = autouuid.to_python('3112edba-4b5d-11e5-b02e-6c4008a70392')

    # Then the result should be a dictionary with metadata
    result.should.equal({
        'module': 'repocket.attributes',
        'type': 'AutoUUID',
        'value': '3112edba-4b5d-11e5-b02e-6c4008a70392',
    })
Exemplo n.º 12
0
def test_autouuid_from_json():
    ('AutoUUID.from_json() should deserialize the given dict into a value')

    # Given an instance of autouuid
    autouuid = AutoUUID()

    # When I call from_json
    result = autouuid.from_json(
        json.dumps({
            b'module': b'repocket.attributes',
            b'type': b'AutoUUID',
            b'value': b'3112edba-4b5d-11e5-b02e-6c4008a70392',
        }))

    # Then the result should be a value
    result.should.equal(test_uuid)
Exemplo n.º 13
0
    def configure_fields(ActiveRecordClass, members):
        hash_fields = OrderedDict()
        string_fields = OrderedDict()
        primary_key_attribute = None

        for attribute, value in members.items():
            if isinstance(value, AutoUUID):
                if primary_key_attribute is not None:
                    msg = '{0} already defined the primary key: {1}, but you also defined {2}'
                    raise RepocketActiveRecordDefinitionError(
                        msg.format(
                            ActiveRecordClass,
                            primary_key_attribute,
                            attribute,
                        ))

                primary_key_attribute = attribute

            elif isinstance(value, ByteStream):
                field_name = str(attribute)
                string_fields[field_name] = value
                append_method_name = 'append_{0}'.format(attribute)
                setattr(
                    ActiveRecordClass, append_method_name,
                    lambda self, string_value: ActiveRecordClass.
                    append_to_bytestream(self, field_name, string_value))

            if isinstance(value, Attribute):
                hash_fields[str(attribute)] = value
                members.pop(attribute, None)
                try:
                    delattr(ActiveRecordClass, attribute)
                except AttributeError:
                    pass

        if primary_key_attribute is None:
            primary_key_attribute = 'id'
            hash_fields['id'] = AutoUUID()

        ActiveRecordClass.__fields__ = hash_fields
        ActiveRecordClass.__string_fields__ = string_fields
        ActiveRecordClass.__primary_key__ = primary_key_attribute

        return members