def test_object_value(self): element = Element('object', content=[ Member(key=String(content='key'), value=String(content='value')) ]) self.assertEqual(element.defract, {'key': 'value'})
def test_initialisation(self): key = String('title') value = String('hello') member = Member(key=key, value=value) self.assertEqual(member.content.key, key) self.assertEqual(member.content.value, value)
def test_set_key(self): key = String('title') new_key = String('description') member = Member(key=key) member.key = new_key self.assertEqual(member.key, new_key)
def test_set_value(self): key = String('title') value = String('hello') new_value = String('hello world') member = Member(key=key, value=value) member.value = new_value self.assertEqual(member.value, new_value)
def test_serialise_key_value_pair_element(self): pair = KeyValuePair( key=String(content='name'), value=String(content='Doe') ) payload = self.serialiser.serialise(Element('member', content=pair)) self.assertEqual(payload, '["member", null, null, ["pair", ' '["string", null, null, "name"], ' '["string", null, null, "Doe"]' ']]')
def test_deserialise_attributes(self): payload = '["string", null, {"title": ' \ '["string", null, null, "Test"]}, "Hello"]' element = self.deserialiser.deserialise(payload) self.assertIsInstance(element, String) self.assertEqual(element.content, 'Hello') self.assertEqual(element.attributes, {'title': String(content='Test')})
def test_repr(self): element = Element('string', content='Hello World') self.assertEqual(repr(element), "<Element(string) content='Hello World'>") element = Element('array', content=[String('Hello World')]) desc = "<Element(array) content=[<String content=None>]>" self.assertEqual(repr(element), desc)
def test_serialise_meta_id(self): element = Element('string', meta=Metadata(id=String(content='Test'))) self.assertEqual(self.serialise(element), { 'element': 'string', 'meta': { 'id': { 'element': 'string', 'content': 'Test' } } })
def test_serialise_meta_description(self): meta = Metadata(description=String(content='Test')) element = Element('string', meta=meta) self.assertEqual(self.serialise(element), { 'element': 'string', 'meta': { 'description': { 'element': 'string', 'content': 'Test' } } })
def test_serialise_meta_title(self): meta = Metadata(title=String(content='Test')) element = Element('string', meta=meta) self.assertEqual(self.serialise(element), { 'element': 'string', 'meta': { 'title': { 'element': 'string', 'content': 'Test' } } })
def test_serialise_meta_classes(self): element = Element('string', meta=Metadata(classes=Array(content=[ String(content='warning') ]))) self.assertEqual(self.serialise(element), { 'element': 'string', 'meta': { 'classes': { 'element': 'array', 'content': [ { 'element': 'string', 'content': 'warning' } ] } } })
def test_append(self): self.array.append(String(content='final')) self.assertEqual(self.array[2].content, 'final')
def test_serialise_array_element(self): payload = self.serialiser.serialise(Element('array', content=[String(content='value')])) self.assertEqual(payload, '["array", null, null, ' '[["string", null, null, "value"]]]')
def test_serialise_element_element(self): payload = self.serialiser.serialise(Element('test', content=String(content='value'))) self.assertEqual(payload, '["test", null, null, ' '["string", null, null, "value"]]')
def test_serialise_string_element(self): payload = self.serialiser.serialise(String(content='Hello')) self.assertEqual(payload, '["string", null, null, "Hello"]')
def test_get_key(self): key = String('title') member = Member(key=key) self.assertEqual(member.key, key)
def setUp(self): self.key = String(content='title') self.value = String(content='hello') self.member = Member(key=self.key, value=self.value) self.object = Object(content=[self.member])
def test_serialise_meta(self): element = String(content='Hello') element.title = 'Title' payload = self.serialiser.serialise(element) self.assertEqual(payload, '["string", {"title": ["string", null, ' 'null, "Title"]}, null, "Hello"]')
def test_contains(self): self.assertTrue(self.title in self.array) self.assertTrue(String(content='test') not in self.array)
def test_get_value(self): key = String('title') value = String('hello') member = Member(key=key, value=value) self.assertEqual(member.value, value)
def test_key_value_pair_value(self): element = Element('element', content=KeyValuePair(key=String(content='key'), value=String(content='value'))) self.assertEqual(element.defract, ('key', 'value'))
def test_repr_subclass(self): element = String(content='Hello World') self.assertEqual(repr(element), "<String content='Hello World'>")
def test_serialise_attributes(self): element = String(content='Hello') element.attributes = {'contentType': String(content='text')} payload = self.serialiser.serialise(element) self.assertEqual(payload, '["string", null, {"contentType": ' '["string", null, null, "text"]}, "Hello"]')
def test_insert(self): self.array.insert(0, String(content='final')) self.assertEqual(self.array[0].content, 'final')
def setUp(self): self.title = String(content='title') self.hello = String(content='hello') self.array = Array(content=[self.title, self.hello])
def test_refracting_element(self): element = String(content='Hello') self.assertEqual(refract(element), element)