

def test_one_to_many(self):
    r = models.Reporter(first_name='John', last_name='Smith', email='john@example.com')
    r.save()
    self.addCleanup(r.delete)
    r2 = models.Reporter(first_name='Paul', last_name='Jones', email='paul@example.com')
    r2.save()
    self.addCleanup(r2.delete)
    a = models.Article(headline='This is a test', reporter=r)
    a.save()
    self.addCleanup(a.delete)
    self.assertEqual(a.id, 1)
    del a
    a = models.Article.objects.filter(pk=1)[0]
    self.assertFalse(('_reporter_cache' in a.__dict__))
    a.reporter
    self.assertTrue(('_reporter_cache' in a.__dict__))
    del a
    a = models.Article.objects.filter(pk=1)[0]
    alias = adapter.DjangoClassAlias(models.Article, defer=True)
    self.assertFalse(hasattr(alias, 'fields'))
    attrs = alias.getEncodableAttributes(attrs)
    self.assertEqual(attrs, {
        'headline': 'This is a test',
        'id': 1,
        'publications': [],
    })
    self.assertFalse(('_reporter_cache' in a.__dict__))
    self.assertEqual(pyamf.encode(a, encoding=pyamf.AMF3).getvalue(), '\n\x0b\x01\x11headline\x06\x1dThis is a test\x05id\x04\x01\x19publications\t\x01\x01\x01')
    del a
    a = models.Article.objects.select_related('reporter').filter(pk=1)[0]
    alias = adapter.DjangoClassAlias(models.Article, defer=True)
    self.assertFalse(hasattr(alias, 'fields'))
    self.assertEqual(alias.getEncodableAttributes(a), {
        'headline': 'This is a test',
        'id': 1,
        'reporter': r,
        'publications': [],
    })
    self.assertTrue(('_reporter_cache' in a.__dict__))
    self.assertEqual(pyamf.encode(a, encoding=pyamf.AMF3).getvalue(), '\n\x0b\x01\x11reporter\n\x0b\x01\x15first_name\x06\tJohn\x13last_name\x06\x0bSmith\x05id\x04\x01\x0bemail\x06!john@example.com\x01\x11headline\x06\x1dThis is a test\x19publications\t\x01\x01\n\x04\x01\x01')

dataset/ETHPy150Open AppScale/appscale/AppServer/lib/PyAMF-0.6.1/pyamf/tests/adapters/test_django.py ForeignKeyTestCase.test_one_to_many/VarMisuse@224/291 `a`->`attrs`