Example #1
0
 def setUp(self):
     self.border_station = BorderStationFactory.create()
     self.budget_calc_sheet = BorderStationBudgetCalculationFactory.create(
         border_station=self.border_station)
     self.superuser = SuperUserFactory.create()
     self.client = APIClient()
     self.client.force_authenticate(user=self.superuser)
Example #2
0
    def test_when_not_authenticated_should_deny_access(self):
        user = SuperUserFactory.create()
        url = reverse('Account', args=[user.id])

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
        self.assertEqual(response.data['detail'], 'Authentication credentials were not provided.')
Example #3
0
    def test_when_logged_in_and_bad_id_should_return_404(self):
        user = SuperUserFactory.create()
        self.login(user)
        url = reverse('ResendActivationEmail', args=[1000])

        response = self.client.post(url)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
    def test_when_user_is_authenticated_and_does_have_permission_should_return_csv_file(
            self):
        url = reverse('VictimInterviewCsvExport')
        self.client.force_authenticate(user=SuperUserFactory.create())

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
Example #5
0
    def test_when_authenticated_and_has_permission_should_create_new_default_permissions_sets(self):
        url = reverse('DefaultPermissionsSets')
        user = SuperUserFactory.create()
        self.login(user)

        response = self.client.post(url, self.new_permission_set)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(response.data['name'], self.name)
 def setUp(self):
     IntercepteeFactory.create_batch(20)
     self.user = SuperUserFactory.create()
     self.client.force_authenticate(user=self.user)
     ulp = UserLocationPermission()
     ulp.account = self.user
     ulp.permission = Permission.objects.get(permission_group='IRF',
                                             action='VIEW')
     ulp.save()
Example #7
0
    def test_when_authenticated_and_has_permission_and_permissions_set_not_used_by_accounts_should_delete_default_permissions_set(self):
        permission_set = ViewUserDesignation.create()
        url = reverse('DefaultPermissionsSet', args=[permission_set.id])
        user = SuperUserFactory.create()
        self.login(user)

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
Example #8
0
    def test_when_authenticated_and_has_permission_should_delete_account(self):
        user = SuperUserFactory.create()
        user_to_delete = ViewUserFactory.create()
        url = reverse('Account', args=[user_to_delete.id])
        self.login(user)

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
Example #9
0
    def test_when_authenticated_and_has_permission_should_return_all_accounts(self):
        url = reverse('AccountList')
        user = SuperUserFactory.create()
        self.login(user)

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data['results']), 1)
Example #10
0
    def test_email_user(self):
        account = SuperUserFactory.create()
        subject = "foo"

        account.email_user("test_templated_email", "alert",
                           {"subject": subject})

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject, subject)
        self.assertEqual(mail.outbox[0].to[0], account.email)
Example #11
0
    def test_when_authenticated_and_has_permission_should_return_account(self):
        user = SuperUserFactory.create()
        url = reverse('Account', args=[user.id])
        self.login(user)

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['id'], user.id)
        self.assertEqual(response.data['email'], user.email)
Example #12
0
    def test_when_logged_in_and_account_has_not_been_activated_should_return_True(self):
        user = SuperUserFactory.create()
        activated_user = ViewUserFactory.create()
        self.login(user)
        url = reverse('ResendActivationEmail', args=[activated_user.id])

        response = self.client.post(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, True)
Example #13
0
    def test_when_user_authenticated_and_has_permission_should_delete_vif(
            self):
        user = SuperUserFactory.create()
        vif_to_delete = VifFactory.create()
        url = reverse('VictimInterviewDetail', args=[vif_to_delete.id])
        self.login(user)

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
Example #14
0
    def test_when_logged_in_should_return_logged_in_users_account(self):
        user = SuperUserFactory.create()
        self.login(user)
        url = reverse('CurrentUser')

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['id'], user.id)
        self.assertEqual(response.data['email'], user.email)
Example #15
0
    def test_when_authenticated_and_has_permission_and_permissions_set_used_by_accounts_should_not_delete_default_permissions_set(self):
        permission_set = SuperUserDesignation.create()
        url = reverse('DefaultPermissionsSet', args=[permission_set.id])
        user = SuperUserFactory.create()
        self.login(user)

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(response.data['detail'], 'Permission set is currently used by accounts. It cannot be deleted.')
Example #16
0
    def test_when_authenticated_and_has_permission_should_return_default_permissions_set(self):
        name = 'set_to_get'
        permission_set = SuperUserDesignation.create(name=name)
        url = reverse('DefaultPermissionsSet', args=[permission_set.id])
        user = SuperUserFactory.create()
        self.login(user)

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['name'], name)
Example #17
0
    def test_when_authenticated_and_has_permission_should_create_account(self):
        url = reverse('AccountList')
        user = SuperUserFactory.create()
        self.login(user)

        response = self.client.post(url, self.get_user_data(user))

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(response.data['email'], self.email)
        self.assertEqual(response.data['first_name'], self.first_name)
        self.assertEqual(response.data['last_name'], self.last_name)
Example #18
0
    def test_when_user_authenticated_and_has_permission_should_update_vif(
            self):
        user = SuperUserFactory.create()
        vif_to_put = VifFactory.create()
        url = reverse('VictimInterviewDetail', args=[vif_to_put.id])
        self.login(user)

        new_irf = self.get_updated_vif(vif_to_put, "Fred")

        response = self.client.put(url, new_irf)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
Example #19
0
    def test_when_authenticated_and_has_permission_should_update_account(self):
        user = SuperUserFactory.create()
        url = reverse('Account', args=[user.id])
        self.login(user)
        new_email = '*****@*****.**'
        update_user_data = self.get_update_user_data(user, new_email)

        response = self.client.put(url, update_user_data)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['id'], user.id)
        self.assertEqual(response.data['email'], new_email)
Example #20
0
    def setUp(self):
        self.phone_match = '9876543210'
        self.person_list = PersonFactory.create_batch(11)
        self.user = SuperUserFactory.create()
        GenericUserWithPermissions.add_permission(self.user, [
            {
                'group': 'PERSON_MANAGEMENT',
                'action': 'EDIT',
                'country': None,
                'station': None
            },
        ])
        self.client.force_authenticate(user=self.user)
        self.interceptee_list = IntercepteeIndiaNoPhotoFactory.create_batch(3)
        self.pb_list = PersonBoxIndiaFactory.create_batch(2)
        self.irf_list = IrfIndiaFactory.create_batch(2)
        self.cif_list = CifIndiaFactory.create_batch(2)

        self.interceptee_list[0].person = self.person_list[0]
        self.pb_list[0].person = self.person_list[0]
        self.pb_list[1].person = self.person_list[0]
        self.interceptee_list[1].person = self.person_list[1]
        self.cif_list[0].main_pv = self.person_list[2]
        self.interceptee_list[2].person = self.person_list[3]
        self.cif_list[1].main_pv = self.person_list[4]

        self.person_list[3].master_person = self.person_list[4].master_person

        self.person_list[3].phone_contact = self.phone_match + '01'
        self.person_list[4].phone_contact = self.phone_match + '02'

        self.person_list[3].full_name = "Raymond Smith"
        self.person_list[4].full_name = "Raymond Smythe"

        self.interceptee_list[0].interception_record = self.irf_list[0]
        self.interceptee_list[1].interception_record = self.irf_list[1]
        self.interceptee_list[2].interception_record = self.irf_list[1]

        self.pb_list[0].cif = self.cif_list[0]
        self.pb_list[1].cif = self.cif_list[1]

        for idx in range(0, 3):
            self.interceptee_list[idx].save()

        for idx in range(0, 2):
            self.pb_list[idx].save()

        for idx in range(0, 2):
            self.cif_list[idx].save()

        for idx in range(0, 5):
            self.person_list[idx].save()
Example #21
0
    def test_when_user_authenticated_and_has_permission_and_vif_does_not_exist_should_return_error(
            self):
        user = SuperUserFactory.create()
        vif_to_put = VifFactory.create()
        url = reverse('VictimInterviewDetail', args=[2342534])
        self.login(user)

        new_irf = self.get_updated_vif(vif_to_put, "Fred")

        response = self.client.put(url, new_irf)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        self.assertEqual(response.data['detail'], 'Not found.')
Example #22
0
 def setUp(self):
     # timezone.now() gets utc time but timezone.now().now() gets local Nepal time
     self.superuser = SuperUserFactory.create()
     self.day1 = timezone.now().now()
     self.day2 = timezone.now().now() - timedelta(days=1)
     self.irf_one = IrfFactory.create(date_time_of_interception=self.day1)
     self.irf_two = IrfFactory.create(date_time_of_interception=self.day2)
     self.int1 = IntercepteeFactory.create(interception_record=self.irf_one)
     self.int2 = IntercepteeFactory.create(interception_record=self.irf_one)
     self.int3 = IntercepteeFactory.create(interception_record=self.irf_two)
     self.days = [
         'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
         'Sunday'
     ]
    def setUp(self):
        self.phone_match = '9876543210'
        self.person_list = PersonFactory.create_batch(11)
        self.user = SuperUserFactory.create()
        self.client.force_authenticate(user=self.user)
        self.interceptee_list = IntercepteeNoPhotoFactory.create_batch(3)
        self.pb_list = PersonBoxFactory.create_batch(2)
        self.irf_list = IrfFactory.create_batch(2)
        self.vif_list = VifFactory.create_batch(2)
        self.alias_list = AliasGroupFactory.create_batch(1)

        self.interceptee_list[0].person = self.person_list[0]
        self.pb_list[0].person = self.person_list[0]
        self.pb_list[1].person = self.person_list[0]
        self.interceptee_list[1].person = self.person_list[1]
        self.vif_list[0].victim = self.person_list[2]
        self.interceptee_list[2].person = self.person_list[3]
        self.vif_list[1].victim = self.person_list[4]

        self.person_list[3].alias_group = self.alias_list[0]
        self.person_list[4].alias_group = self.alias_list[0]

        self.person_list[3].phone_contact = self.phone_match + '01'
        self.person_list[4].phone_contact = self.phone_match + '02'

        self.person_list[3].full_name = "Raymond Smith"
        self.person_list[4].full_name = "Raymond Smythe"

        self.interceptee_list[0].interception_record = self.irf_list[0]
        self.interceptee_list[1].interception_record = self.irf_list[1]
        self.interceptee_list[2].interception_record = self.irf_list[1]

        self.pb_list[0].victim_interview = self.vif_list[0]
        self.pb_list[1].victim_interview = self.vif_list[1]

        for idx in range(0,3):
            self.interceptee_list[idx].save()

        for idx in range(0,2):
            self.pb_list[idx].save()

        for idx in range(0,2):
            self.vif_list[idx].save()

        for idx in range(0,5):
            self.person_list[idx].save()
Example #24
0
    def test_superuser_are_authenticated(self):
        self.user = SuperUserFactory.create()
        self.client.force_authenticate(user=self.user)

        # get
        url = reverse('SiteSettings')
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # put detail
        data = {
            "data": '{"hello": "1"}',
            "date_time_last_updated": "2016-09-17T19:54:08.820420Z"
        }
        url = reverse('SiteSettingsUpdate', args=[self.site_settings.id])
        response = self.client.put(url, data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data["data"], data["data"])
    def setUp(self):
        user = SuperUserFactory.create()
        self.client = APIClient()
        self.client.force_authenticate(user=user)

        self.globalCount += 1
        self.nepal = self.get_or_create_country('Nepal')
        self.south_africa = self.get_or_create_country('South Africa')
        self.thailand = self.get_or_create_country('Thailand')

        self.nepal_bs1 = self.get_or_create_station("nepal1", "NP1",
                                                    self.nepal)
        self.nepal_bs2 = self.get_or_create_station("nepal2", "NP2",
                                                    self.nepal)
        self.nepal_bs3 = self.get_or_create_station("nepal3", "NP3",
                                                    self.nepal)
        self.south_africa_bs = self.nepal_bs3 = self.get_or_create_station(
            "sa", "SA1", self.south_africa)
        self.thailand_bs = self.nepal_bs3 = self.get_or_create_station(
            "thai", "TL1", self.thailand)

        self.account = SuperUserFactory.create()

        self.permissions = []

        tmp = UserLocationPermission()
        tmp.account = self.account
        tmp.country = None
        tmp.station = None
        tmp.permission = Permission.objects.get(permission_group='IRF',
                                                action='VIEW')
        tmp.save()
        self.permissions.append(tmp)

        tmp = UserLocationPermission()
        tmp.account = self.account
        tmp.country = None
        tmp.station = self.nepal_bs2
        tmp.permission = Permission.objects.get(permission_group='IRF',
                                                action='ADD')
        tmp.save()
        self.permissions.append(tmp)

        tmp = UserLocationPermission()
        tmp.account = self.account
        tmp.country = None
        tmp.station = self.thailand_bs
        tmp.permission = Permission.objects.get(permission_group='IRF',
                                                action='ADD')
        tmp.save()
        self.permissions.append(tmp)

        tmp = UserLocationPermission()
        tmp.account = self.account
        tmp.country = None
        tmp.station = self.nepal_bs2
        tmp.permission = Permission.objects.get(permission_group='IRF',
                                                action='EDIT')
        tmp.save()
        self.permissions.append(tmp)

        tmp = UserLocationPermission()
        tmp.account = self.account
        tmp.country = None
        tmp.station = self.thailand_bs
        tmp.permission = Permission.objects.get(permission_group='IRF',
                                                action='EDIT')
        tmp.save()
        self.permissions.append(tmp)

        tmp = UserLocationPermission()
        tmp.account = self.account
        tmp.country = self.nepal
        tmp.station = None
        tmp.permission = Permission.objects.get(permission_group='VIF',
                                                action='VIEW')
        tmp.save()
        self.permissions.append(tmp)

        tmp = UserLocationPermission()
        tmp.account = self.account
        tmp.country = self.nepal
        tmp.station = None
        tmp.permission = Permission.objects.get(permission_group='VIF',
                                                action='ADD')
        tmp.save()
        self.permissions.append(tmp)

        tmp = UserLocationPermission()
        tmp.account = self.account
        tmp.country = self.nepal
        tmp.station = None
        tmp.permission = Permission.objects.get(permission_group='VIF',
                                                action='EDIT')
        tmp.save()
        self.permissions.append(tmp)
Example #26
0
 def setUp(self):
     self.irf_list = IrfFactory.create_batch(20)
     self.user = SuperUserFactory.create()
     self.client.force_authenticate(user=self.user)
Example #27
0
    def test_get_username(self):
        account = SuperUserFactory.create()

        result = account.get_username()

        self.assertEqual(result, account.email)
Example #28
0
 def setUp(self):
     IntercepteeFactory.create_batch(20)
     self.user = SuperUserFactory.create()
     self.client.force_authenticate(user=self.user)
Example #29
0
    def test_send_activation_email(self):
        account = SuperUserFactory.create()

        account.send_activation_email('activate')

        self.assertEqual(mail.outbox[1].to[0], account.email)
Example #30
0
    def test_get_full_name(self):
        account = SuperUserFactory.create()

        result = account.get_full_name()

        self.assertEqual(result, account.first_name + ' ' + account.last_name)