Beispiel #1
0
    def test_dynamic_property_referenced_object(self):
        a = test_models.Author(name='Jane Austen')
        self.put(a)

        b = test_models.Novel(title='Sense and Sensibility', author=a)
        self.put(b)

        x = db.get(b.key())
        foo = [1, 2, 3]

        x.author.bar = foo

        ek = self.encodeKey(x, pyamf.AMF0)
        el = self.encodeKey(a, pyamf.AMF0)

        bytes = (
            '\x03', (
                '\x00\x05title\x02\x00\x15Sense and Sensibility',
                '\x00\x04_key' + ek,
                '\x00\x06author\x03', (
                    '\x00\x03bar\n\x00\x00\x00\x03\x00?\xf0\x00\x00\x00\x00'
                    '\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00\x00@\x08\x00'
                    '\x00\x00\x00\x00\x00',
                    '\x00\x04name\x02\x00\x0bJane Austen',
                    '\x00\x04_key' + el
                ),
                '\x00\x00\t'
            ),
            '\x00\x00\t')

        self.assertEncodes(x, bytes, encoding=pyamf.AMF0)
Beispiel #2
0
    def test_nullreference(self):
        c = test_models.Novel(title='Pride and Prejudice', author=None)
        self.put(c)

        encoder = pyamf.get_encoder(encoding=pyamf.AMF3)
        alias = adapter_db.DataStoreClassAlias(test_models.Novel, None)

        attrs = alias.getEncodableAttributes(c, codec=encoder)

        self.assertEqual(attrs, {
            '_key': str(c.key()),
            'title': 'Pride and Prejudice',
            'author': None
        })
Beispiel #3
0
    def test_model(self):
        a = test_models.Author(name='Jane Austen')
        self.put(a)
        k = str(a.key())

        amf0_k = self.encodeKey(a, pyamf.AMF0)
        amf3_k = self.encodeKey(a, pyamf.AMF3)

        b = test_models.Novel(title='Sense and Sensibility', author=a)

        self.assertIdentical(b.author, a)

        bytes = ('\x03', ('\x00\x05title\x02\x00\x15Sense and Sensibility',
                          '\x00\x04_key' + amf0_k, '\x00\x06author\x03',
                          ('\x00\x04name\x02\x00\x0bJane Austen',
                           '\x00\x04_key\x05'), '\x00\x00\t'), '\x00\x00\t')

        self.assertEncodes(b, bytes, encoding=pyamf.AMF0)

        bytes = ('\n\x0b\x01',
                 (('\rauthor\n\x0b\x01', ('\t_key' + amf3_k,
                                          '\tname\x06\x17Jane Austen'),
                   '\x01\x06\x01'),
                  '\x0btitle\x06+Sense and Sensibility'), '\x01')

        self.assertEncodes(b, bytes, encoding=pyamf.AMF3)

        # now test with aliases ..
        pyamf.register_class(test_models.Author, 'Author')
        pyamf.register_class(test_models.Novel, 'Novel')

        bytes = ('\x10\x00\x05Novel',
                 ('\x00\x05title\x02\x00\x15Sense and Sensibility',
                  '\x00\x04_key' + amf0_k, '\x00\x06author\x10\x00\x06Author',
                  ('\x00\x04name\x02\x00\x0bJane Austen',
                   '\x00\x04_key\x05'), '\x00\x00\t'), '\x00\x00\t')

        self.assertEncodes(b, bytes, encoding=pyamf.AMF0)

        bytes = ('\n\x0b\x0bNovel',
                 (('\rauthor\n\x0b\rAuthor', ('\t_key' + amf3_k,
                                              '\tname\x06\x17Jane Austen'),
                   '\x01\n\x01'),
                  '\x0btitle\x06+Sense and Sensibility'), '\x01')

        self.assertEncodes(b, bytes, encoding=pyamf.AMF3)