def test_attribute_get_base_type(): ('Attribute#get_base_type() should return the __base_type__') # Given an instance of attribute attribute = Attribute() # When I call get_base_type result = attribute.get_base_type() # Then the result should be bytes result.should.equal(bytes)
def test_attribute_from_string(): ('Attribute#from_string() should have cast the value as string') # Given an instance of attribute attribute = Attribute() # When I call from_string result = attribute.from_string('100') # Then the result should be a string result.should.be.a(bytes)
def test_attribute_to_json(): ('Attribute.to_json() should deserialize the given dict into a value') # Given an instance of attribute attribute = Attribute() # When I call to_json result = attribute.to_json('chucknorris') # Then the result should be a value result.should.equal( '{"type": "Attribute", "value": "chucknorris", "module": "repocket.attributes"}' )
def test_attribute_to_python(): ('Attribute#to_python() should prepare data to be serialized') # Given an instance of attribute attribute = Attribute() # When I call to_python result = attribute.to_python('the value') # Then the result should be a dictionary with metadata result.should.equal({ 'module': 'repocket.attributes', 'type': 'Attribute', 'value': 'the value', })
def test_attribute_from_python(): ('Attribute.from_python() should deserialize the given dict into a value') # Given an instance of attribute attribute = Attribute() # When I call from_python result = attribute.from_python({ b'module': b'repocket.attributes', b'type': b'Attribute', b'value': b'foobar', }) # Then the result should be a value result.should.equal(b'foobar')
def test_attribute_from_json(): ('Attribute.from_json() should deserialize the given dict into a value') # Given an instance of attribute attribute = Attribute() # When I call from_json result = attribute.from_json(json.dumps({ b'module': b'repocket.attributes', b'type': b'Attribute', b'value': b'foobar', })) # Then the result should be a value result.should.equal( b'foobar' )
def deserialize_raw_item(self, raw_item): data = {} for key, raw_value in raw_item.iteritems(): try: value = Attribute.from_json(raw_value) except TypeError as e: logger.error( 'Failed to deserialize field {0}.{1} because: {2}'.format( self.model.__class__.__name__, key, str(e))) raise data[key] = value return data
def deserialize_raw_item(self, raw_item): data = {} for key, raw_value in raw_item.iteritems(): try: value = Attribute.from_json(raw_value) except TypeError as e: logger.error('Failed to deserialize field {0}.{1} because: {2}'.format( self.model.__class__.__name__, key, str(e) )) raise data[key] = value return data