def test_convert_contenttypes(self): out = jsmodels(applications=['contenttypes']) self.assertEquals(sorted(out['models'].keys()), ['ContentType']) self.assertEquals( list(filter(lambda x: x.get('name','')=='logentry', out['models']['ContentType']['fields']))[0]['rel']['reverse_fk'], True)
def test_human_shortnames(self): out = jsmodels(applications=['test',]) out = shortnames(out, mapping=MAPPING) self.assertTrue( filter(lambda x: 'short_name' in x, out['models']['Person']['fields'])) for field in out['models']['Person']['fields']: if field['field'] == 'CharField': self.assertEquals(field['short_name'], 'text')
def test_human_urls(self): self.assertTrue(reverse('person-list')) self.assertTrue(reverse('person-detail', kwargs=dict(pk=1))) out = jsmodels(applications=['test',], prepare=False) out = drf(out) f = get_field(out['models']['Account']['fields'], 'person') self.assertEqual(f['url']['id'], '/api/account/:id') f = get_field(out['models']['Account']['fields'], 'name') self.assertEqual(f['url']['id'], '/api/account/:id')
def test_human_shortnames(self): out = jsmodels(applications=[ 'test', ]) out = shortnames(out, mapping=MAPPING) self.assertTrue( filter(lambda x: 'short_name' in x, out['models']['Person']['fields'])) for field in out['models']['Person']['fields']: if field['field'] == 'CharField': self.assertEquals(field['short_name'], 'text')
def test_human_urls(self): self.assertTrue(reverse('person-list')) self.assertTrue(reverse('person-detail', kwargs=dict(pk=1))) out = jsmodels(applications=[ 'test', ], prepare=False) out = drf(out) f = get_field(out['models']['Account']['fields'], 'person') self.assertEqual(f['url']['id'], '/api/account/:id') f = get_field(out['models']['Account']['fields'], 'name') self.assertEqual(f['url']['id'], '/api/account/:id')
def test_implied_content_type(self): implied = [{ 'model': ContentType, 'field': 'content_type', 'relname': 'contenttype', 'verbose_name': 'Content Type',}] out = jsmodels(applications=['test',]) out = add_relations(out, implied) self.assertTrue( filter(lambda x: x['name'] =='content_type', out['models']['Person']['fields'])) self.assertTrue( filter(lambda x: x['name'] =='content_type', out['models']['Computer']['fields']))
def test_convert_test(self): out = jsmodels(applications=['test',]) self.assertEquals(sorted(out['models'].keys()), ['Account', 'Computer', 'Person']) self.assertEquals( sorted([k['name'] for k in out['models']['Person']['fields']]), ['account', 'age','computers','created','id','name'])
def test_json(self): out = jsmodels(applications=['test',]) self.assertTrue(to_json(out))