def test_should_post_a_location_without_a_parent(self): response = self.client.post(self.LOCATION_ENDPOINT, data=self.district_to_post) self.assertEqual(201, response.status_code) retrieved_location = Location.objects(**self.district) self.assertEqual(1, retrieved_location.count())
def get_non_children_queryset(self): fields = Location._fields_ordered query_params = {key: value or None for key, value in self.request.GET.items() if key in fields} user_profile = UserProfile.objects(user=self.request.user).first() user_group = self.request.user.group.name if user_profile and user_group in getattr(settings, "DISTRICT_GROUPS", []): user_locations = get_user_district_locations(self.request.user) query_params.update({"id__in": user_locations}) return Location.objects(**query_params)
def test_should_post_a_location_with_a_parent(self): response = self.client.post(self.LOCATION_ENDPOINT, data=self.district_to_post) saved_district_id = response.data['id'] self.assertIsNotNone(saved_district_id) village_to_post = dict(name='Bukoto', type='village', parent=saved_district_id) response = self.client.post(self.LOCATION_ENDPOINT, data=village_to_post) self.assertEqual(201, response.status_code) retrieved_message = Location.objects(**village_to_post) self.assertEqual(1, retrieved_message.count())
def test_should_save_location_with_a_parent(self): district = Location(**dict(name='Kampala', parent=None, type='district')) district.save() village = dict(name='Bukoto', parent=district, type='village') Location(**village).save() saved_villages = Location.objects(**village) self.assertEqual(1, saved_villages.count()) saved_village = saved_villages[0] self.assertEqual(village['name'], saved_village.name) self.assertEqual(district['name'], saved_village.parent.name)
def get_non_children_queryset(self): fields = Location._fields_ordered query_params = { key: value or None for key, value in self.request.GET.items() if key in fields } user_profile = UserProfile.objects(user=self.request.user).first() user_group = self.request.user.group.name if user_profile and user_group in getattr(settings, 'DISTRICT_GROUPS', []): user_locations = get_user_district_locations(self.request.user) query_params.update({'id__in': user_locations}) return Location.objects(**query_params)
def test_should_post_a_location_with_a_parent(self): response = self.client.post(self.LOCATION_ENDPOINT, data=self.district_to_post) saved_district_id = response.data['id'] self.assertIsNotNone(saved_district_id) village_to_post = dict(name='Bukoto', type='village', parent=saved_district_id) response = self.client.post(self.LOCATION_ENDPOINT, data=village_to_post) self.assertEqual(201, response.status_code) retrieved_message = Location.objects(**village_to_post) self.assertEqual(1, retrieved_message.count())
def test_should_post_a_location_without_a_parent(self): response = self.client.post(self.LOCATION_ENDPOINT, data=self.district_to_post) self.assertEqual(201, response.status_code) retrieved_location = Location.objects(**self.district) self.assertEqual(1, retrieved_location.count())
def test_should_save_location_with_no_parent(self): district = dict(name='Kampala', parent=None, type='district') Location(**district).save() saved_districts = Location.objects(**district) self.assertEqual(1, saved_districts.count())