def setUp(self): form_data_file = settings.BASE_DIR + '/fixtures/initial-required-data/form_data.json' call_command('loaddata', form_data_file, verbosity=0) self.irf_list = IrfIndiaFactory.create_batch(20) self.user = GenericUserWithPermissions.create([{ 'group': 'IRF', 'action': 'VIEW', 'country': None, 'station': None }, { 'group': 'IRF', 'action': 'EDIT', 'country': None, 'station': None }, { 'group': 'IRF', 'action': 'ADD', 'country': None, 'station': None }]) for name in [ 'create master person', 'add to master person', 'create match', 'update match', 'remove from master person', 'merge master persons', 'deactivate master person' ]: match_action = MatchAction() match_action.name = name match_action.save() self.client.force_authenticate(user=self.user) self.form = Form.objects.get(form_name='irfIndia') self.form.stations.add(MbzStationFactory())
def setUp(self): self.factory = APIRequestFactory() self.user = GenericUserWithPermissions.create([ { 'group': 'BUDGETS', 'action': 'VIEW', 'country': None, 'station': None }, { 'group': 'BUDGETS', 'action': 'ADD', 'country': None, 'station': None }, { 'group': 'BUDGETS', 'action': 'EDIT', 'country': None, 'station': None }, { 'group': 'BUDGETS', 'action': 'DELETE', 'country': None, 'station': None }, ]) self.client = APIClient() self.client.force_authenticate(user=self.user) self.border_station = BorderStationFactory()
def test_doesnt_have_permission(self): self.bad_user = GenericUserWithPermissions.create([]) self.client.force_authenticate(user=self.bad_user) # get url = reverse('irfNew') response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['count'], 0)
def testUpdateBudgetSheetStation(self): user = GenericUserWithPermissions.create([ { 'group': 'BUDGETS', 'action': 'VIEW', 'country': None, 'station': None }, { 'group': 'BUDGETS', 'action': 'ADD', 'country': None, 'station': None }, { 'group': 'BUDGETS', 'action': 'EDIT', 'country': None, 'station': self.border_station }, ]) client = APIClient() client.force_authenticate(user=user) response = client.post( '/api/budget/', { "border_station": self.border_station.pk, "month_year": "2017-04-15T23:53:08.996000Z" }) budget_id = response.data.get('id') self.assertEqual(response.status_code, 201) response = client.get('/api/budget/' + str(budget_id) + '/') budget_id = response.data.get('id') self.assertEqual(response.status_code, 200) response = client.put( '/api/budget/' + str(budget_id) + '/', { "border_station": self.border_station.pk, "shelter_water_amount": 2, "month_year": "2017-04-15T23:53:08.996000Z" }) budget_id = response.data.get('id') self.assertEqual(response.status_code, 200) response = client.get('/api/budget/' + str(budget_id) + '/') shelter_water_amount = response.data["shelter_water_amount"] self.assertEqual(response.data.get('id'), budget_id) self.assertEqual(response.status_code, 200) self.assertEqual(shelter_water_amount, '2.00')
def testRemoveBudgetSheetStationNoPermission(self): border_station = BorderStationFactory() user = GenericUserWithPermissions.create([ { 'group': 'BUDGETS', 'action': 'VIEW', 'country': None, 'station': None }, { 'group': 'BUDGETS', 'action': 'ADD', 'country': None, 'station': None }, { 'group': 'BUDGETS', 'action': 'DELETE', 'country': None, 'station': border_station }, ]) client = APIClient() client.force_authenticate(user=user) response = client.get('/api/budget/') self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data['results']), 0) response = client.post( '/api/budget/', { "border_station": self.border_station.pk, "month_year": "2017-04-15T23:53:08.996000Z" }) budget_id = response.data.get('id') self.assertEqual(response.status_code, 201) response = client.get('/api/budget/') self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data['results']), 1) # delete the form response = client.delete('/api/budget/' + str(budget_id) + '/') self.assertEqual(response.status_code, 403) # count the remaining forms response = client.get('/api/budget/') self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data['results']), 1)
def testCreateBudgetSheetNoPermission(self): user = GenericUserWithPermissions.create([ { 'group': 'BUDGETS', 'action': 'VIEW', 'country': None, 'station': None }, ]) client = APIClient() client.force_authenticate(user=user) response = client.post( '/api/budget/', { "border_station": self.border_station.pk, "month_year": "2017-05-15T23:53:08.996000Z" }) self.assertEqual(response.status_code, 403)