Exemplo n.º 1
0
    def test_encodable_attrs(self):
        def attrs():
            return self.alias.getEncodableAttributes(self.model)

        self.assertEqual(attrs(), {'id': None})

        x = models.SimplestModel()

        x.save()
        self.addCleanup(x.delete)

        self.model.bar = x

        self.assertEqual(attrs(), {'id': None, 'bar': x})
Exemplo n.º 2
0
    def test_none(self):
        """
        See #556. Make sure that PK fields with a value of 0 are actually set
        to C{None}.
        """
        alias = adapter.DjangoClassAlias(models.SimplestModel, None)

        x = models.SimplestModel()

        self.assertEqual(x.id, None)

        alias.applyAttributes(x, {'id': 0})

        self.assertEqual(x.id, None)
Exemplo n.º 3
0
    def test_nullable_foreign_keys(self):
        x = models.SimplestModel()
        x.save()
        self.addCleanup(x.delete)

        nfk_alias = adapter.DjangoClassAlias(models.NullForeignKey, None)
        bfk_alias = adapter.DjangoClassAlias(models.BlankForeignKey, None)

        nfk = models.NullForeignKey()
        attrs = nfk_alias.getEncodableAttributes(nfk)

        self.assertEqual(attrs, {'id': None})

        bfk = models.BlankForeignKey()
        attrs = bfk_alias.getEncodableAttributes(bfk)

        self.assertEqual(attrs, {'id': None})
Exemplo n.º 4
0
    def test_dynamic(self):
        """
        Test for dynamic property encoding.
        """
        alias = adapter.DjangoClassAlias(models.SimplestModel, 'Book')

        x = models.SimplestModel()
        x.spam = 'eggs'

        self.assertEqual(alias.getEncodableAttributes(x), {
            'spam': 'eggs',
            'id': None
        })

        # now we test sending the numberOfOddPages attribute
        alias.applyAttributes(x, {'spam': 'foo', 'id': None})

        # test it has been set
        self.assertEqual(x.spam, 'foo')