예제 #1
0
 def test_object_value(self):
     element = Element('object',
                       content=[
                           Member(key=String(content='key'),
                                  value=String(content='value'))
                       ])
     self.assertEqual(element.defract, {'key': 'value'})
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    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"]'
                                  ']]')
예제 #6
0
    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')})
예제 #7
0
    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)
예제 #8
0
 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'
             }
         }
     })
예제 #9
0
    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'
                }
            }
        })
예제 #10
0
    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'
                }
            }
        })
예제 #11
0
    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'
                        }
                    ]
                }
            }
        })
예제 #12
0
 def test_append(self):
     self.array.append(String(content='final'))
     self.assertEqual(self.array[2].content, 'final')
예제 #13
0
 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"]]]')
예제 #14
0
 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"]]')
예제 #15
0
 def test_serialise_string_element(self):
     payload = self.serialiser.serialise(String(content='Hello'))
     self.assertEqual(payload, '["string", null, null, "Hello"]')
예제 #16
0
    def test_get_key(self):
        key = String('title')
        member = Member(key=key)

        self.assertEqual(member.key, key)
예제 #17
0
 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])
예제 #18
0
 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"]')
예제 #19
0
 def test_contains(self):
     self.assertTrue(self.title in self.array)
     self.assertTrue(String(content='test') not in self.array)
예제 #20
0
    def test_get_value(self):
        key = String('title')
        value = String('hello')
        member = Member(key=key, value=value)

        self.assertEqual(member.value, value)
예제 #21
0
    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'))
예제 #22
0
 def test_repr_subclass(self):
     element = String(content='Hello World')
     self.assertEqual(repr(element), "<String content='Hello World'>")
예제 #23
0
 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"]')
예제 #24
0
 def test_insert(self):
     self.array.insert(0, String(content='final'))
     self.assertEqual(self.array[0].content, 'final')
예제 #25
0
 def setUp(self):
     self.title = String(content='title')
     self.hello = String(content='hello')
     self.array = Array(content=[self.title, self.hello])
예제 #26
0
 def test_refracting_element(self):
     element = String(content='Hello')
     self.assertEqual(refract(element), element)