|
5 | 5 |
|
6 | 6 | from binder.json import jsonloads, jsondumps |
7 | 7 |
|
8 | | -from .testapp.models import Zoo, ZooEmployee, Country, City, PermanentCity, CityState |
| 8 | +from .testapp.models import Zoo, ZooEmployee, Country, City, PermanentCity, CityState, Animal |
9 | 9 |
|
10 | 10 | from binder.json import jsondumps |
11 | 11 | from django.contrib.auth.models import User, Group |
@@ -692,3 +692,53 @@ def test_multiput_with_deletions_no_perm(self): |
692 | 692 | self.assertEquals(403, res.status_code) |
693 | 693 |
|
694 | 694 | country.refresh_from_db() |
| 695 | + |
| 696 | + |
| 697 | +class TestColumnScoping(TestCase): |
| 698 | + def setUp(self): |
| 699 | + super().setUp() |
| 700 | + |
| 701 | + u = User(username='testuser_for_not_all_fields', is_active=True, is_superuser=False) |
| 702 | + u.set_password('test') |
| 703 | + u.save() |
| 704 | + |
| 705 | + self.client = Client() |
| 706 | + r = self.client.login(username='testuser_for_not_all_fields', password='test') |
| 707 | + self.assertTrue(r) |
| 708 | + |
| 709 | + self.zoo = Zoo(name='Artis') |
| 710 | + self.zoo.save() |
| 711 | + |
| 712 | + |
| 713 | + def test_column_scoping_excludes_columns(self): |
| 714 | + res = self.client.get('/zoo/{}/'.format(self.zoo.id)) |
| 715 | + self.assertEqual(res.status_code, 200) |
| 716 | + |
| 717 | + columns = jsonloads(res.content)['data'].keys() |
| 718 | + |
| 719 | + for field in ['name', 'founding_date', 'django_picture']: |
| 720 | + self.zoo._meta.get_field(field) # check if those fields exist, otherwise throw error |
| 721 | + self.assertTrue(field not in columns) |
| 722 | + |
| 723 | + for annotation in ['zoo_name']: |
| 724 | + self.assertTrue(annotation not in columns) |
| 725 | + |
| 726 | + for property in ['animal_count']: |
| 727 | + self.assertTrue(property not in columns) |
| 728 | + |
| 729 | + |
| 730 | + def test_column_scoping_includes_columns(self): |
| 731 | + res = self.client.get('/zoo/{}/'.format(self.zoo.id)) |
| 732 | + self.assertEqual(res.status_code, 200) |
| 733 | + |
| 734 | + columns = jsonloads(res.content)['data'].keys() |
| 735 | + |
| 736 | + for field in ['id', 'floor_plan']: |
| 737 | + self.zoo._meta.get_field(field) # check if those fields exist, otherwise throw error |
| 738 | + self.assertTrue(field in columns) |
| 739 | + |
| 740 | + for annotation in ['another_zoo_name']: |
| 741 | + self.assertTrue(annotation in columns) |
| 742 | + |
| 743 | + for property in ['another_animal_count']: |
| 744 | + self.assertTrue(property in columns) |
0 commit comments