コード例 #1
0
class ServiceAreaAPITest(APITestMixin, TestCase):
    def setUp(self):
        super().setUp()
        ServiceArea.objects.all().delete()
        # Area 1 will be a parent
        self.area1 = ServiceAreaFactory()
        # 2 & 3 will be children of that parent and therefore lowest-level areas
        self.area2 = ServiceAreaFactory(parent=self.area1)
        self.area3 = ServiceAreaFactory(parent=self.area1)
        # 4 is not a parent of anything so also a lowest-level area
        self.area4 = ServiceAreaFactory()

    def test_get_areas(self):
        # Should get all, whether top-level or not
        rsp = self.get_with_token(reverse('servicearea-list'))
        self.assertEqual(OK, rsp.status_code)
        result = json.loads(rsp.content.decode('utf-8'))
        results = result
        result_names = [item['name_en'] for item in results]
        self.assertIn(self.area1.name_en, result_names)
        self.assertIn(self.area2.name_en, result_names)
        self.assertIn(self.area3.name_en, result_names)
        self.assertIn(self.area4.name_en, result_names)

    def test_get_area(self):
        rsp = self.get_with_token(self.area2.get_api_url())
        result = json.loads(rsp.content.decode('utf-8'))
        self.assertEqual(self.area2.id, result['id'])
        self.assertEqual('http://testserver%s' % self.area1.get_api_url(),
                         result['parent'])
コード例 #2
0
class ServiceAreaAPITest(APITestMixin, TestCase):
    def setUp(self):
        super().setUp()
        ServiceArea.objects.all().delete()
        # Area 1 will be a parent
        self.area1 = ServiceAreaFactory()
        # 2 & 3 will be children of that parent and therefore lowest-level areas
        self.area2 = ServiceAreaFactory(parent=self.area1)
        self.area3 = ServiceAreaFactory(parent=self.area1)
        # 4 is not a parent of anything so also a lowest-level area
        self.area4 = ServiceAreaFactory()

    def test_get_areas(self):
        # Should get all, whether top-level or not
        rsp = self.get_with_token(reverse('servicearea-list'))
        self.assertEqual(OK, rsp.status_code)
        result = json.loads(rsp.content.decode('utf-8'))
        results = result
        result_names = [item['name_en'] for item in results]
        self.assertIn(self.area1.name_en, result_names)
        self.assertIn(self.area2.name_en, result_names)
        self.assertIn(self.area3.name_en, result_names)
        self.assertIn(self.area4.name_en, result_names)

    def test_get_area(self):
        rsp = self.get_with_token(self.area2.get_api_url())
        result = json.loads(rsp.content.decode('utf-8'))
        self.assertEqual(self.area2.id, result['id'])
        self.assertEqual('http://testserver%s' % self.area1.get_api_url(), result['parent'])
コード例 #3
0
 def setUp(self):
     super().setUp()
     ServiceArea.objects.all().delete()
     # Area 1 will be a parent
     self.area1 = ServiceAreaFactory()
     # 2 & 3 will be children of that parent and therefore lowest-level areas
     self.area2 = ServiceAreaFactory(parent=self.area1)
     self.area3 = ServiceAreaFactory(parent=self.area1)
     # 4 is not a parent of anything so also a lowest-level area
     self.area4 = ServiceAreaFactory()
コード例 #4
0
 def test_staff_add_services(self):
     # Staff can add services to any provider
     self.user.is_staff = True
     self.user.save()
     provider = ProviderFactory()
     type = ServiceTypeFactory()
     area = ServiceAreaFactory()
     service = ServiceFactory.build(provider=provider,
                                    type=type,
                                    area_of_service=area)
     book = get_export_workbook([provider], [service])
     rsp = self.import_book(book)
     self.assertEqual(OK, rsp.status_code, msg=rsp.content.decode('utf-8'))
     new_service = Service.objects.get(name_en=service.name_en)
     self.assertEqual(new_service.name_en, service.name_en)
コード例 #5
0
 def setUp(self):
     super().setUp()
     ServiceArea.objects.all().delete()
     # Area 1 will be a parent
     self.area1 = ServiceAreaFactory()
     # 2 & 3 will be children of that parent and therefore lowest-level areas
     self.area2 = ServiceAreaFactory(parent=self.area1)
     self.area3 = ServiceAreaFactory(parent=self.area1)
     # 4 is not a parent of anything so also a lowest-level area
     self.area4 = ServiceAreaFactory()
コード例 #6
0
 def test_provider_change_service(self):
     # A provider can change their existing service
     provider = ProviderFactory(user=self.user)
     type = ServiceTypeFactory()
     area = ServiceAreaFactory()
     service = ServiceFactory(provider=provider,
                              type=type,
                              area_of_service=area)
     service.name_en = 'Radiator Repair'
     service.name_fr = 'Le Marseilles'
     book = get_export_workbook([provider], [service])
     rsp = self.import_book(book)
     self.assertEqual(OK, rsp.status_code, msg=rsp.content.decode('utf-8'))
     new_service = Service.objects.get(id=service.id)
     self.assertEqual(service.name_en, new_service.name_en)
     self.assertEqual(service.name_fr, new_service.name_fr)
コード例 #7
0
 def test_provider_change_nonexistent_service(self):
     provider = ProviderFactory(user=self.user)
     type = ServiceTypeFactory()
     area = ServiceAreaFactory()
     service = ServiceFactory(provider=provider,
                              type=type,
                              area_of_service=area)
     service.name_en = 'Radiator Repair'
     service.name_fr = 'Le Marseilles'
     book = get_export_workbook([provider], [service])
     service_id = service.id
     service.delete()
     rsp = self.import_book(book)
     self.assertContains(rsp,
                         "%d is not a service this user may import" %
                         service_id,
                         status_code=BAD_REQUEST)
コード例 #8
0
 def test_provider_add_bad_service(self):
     provider = ProviderFactory(user=self.user)
     type = ServiceTypeFactory()
     area = ServiceAreaFactory()
     service = ServiceFactory.build(provider=provider,
                                    type=type,
                                    area_of_service=area,
                                    name_en=VERY_LONG_STRING,
                                    tuesday_open=time(6, 59),
                                    tuesday_close=time(21, 2))
     self.assertIsNotNone(service.location)
     criterion = SelectionCriterionFactory.build(service=service)
     book = get_export_workbook([provider], [service], [criterion])
     rsp = self.import_book(book)
     self.assertEqual(BAD_REQUEST,
                      rsp.status_code,
                      msg=rsp.content.decode('utf-8'))
コード例 #9
0
    def test_staff_delete_service(self):
        # A staffer can delete someone else's service
        self.user.is_staff = True
        self.user.save()
        provider = ProviderFactory(user=self.user)
        type = ServiceTypeFactory()
        area = ServiceAreaFactory()
        service = ServiceFactory(type=type, area_of_service=area)
        self.assertTrue(Service.objects.filter(id=service.id).exists())
        book = get_export_workbook([provider], [service],
                                   cell_overwrite_ok=True)

        # Now blank out everything about the service except its 'id'
        blank_out_row_for_testing(book, sheet_num=1, row_num=1)

        rsp = self.import_book(book)
        self.assertEqual(OK, rsp.status_code, msg=rsp.content.decode('utf-8'))
        self.assertFalse(Service.objects.filter(id=service.id).exists())
コード例 #10
0
 def test_staff_change_services(self):
     # Staff can change anyone's service
     self.user.is_staff = True
     self.user.save()
     provider = ProviderFactory()
     type = ServiceTypeFactory()
     area = ServiceAreaFactory()
     service = ServiceFactory(provider=provider,
                              type=type,
                              area_of_service=area)
     service.name_en = 'Radiator Repair'
     service.name_fr = 'Le Marseilles'
     book = get_export_workbook([provider], [service])
     rsp = self.import_book(book)
     self.assertEqual(OK, rsp.status_code, msg=rsp.content.decode('utf-8'))
     new_service = Service.objects.get(id=service.id)
     self.assertEqual(service.name_en, new_service.name_en)
     self.assertEqual(service.name_fr, new_service.name_fr)
コード例 #11
0
    def test_provider_delete_anothers_service(self):
        # A provider cannot delete someone else's service
        provider = ProviderFactory(user=self.user)
        type = ServiceTypeFactory()
        area = ServiceAreaFactory()
        service = ServiceFactory(type=type, area_of_service=area)
        self.assertTrue(Service.objects.filter(id=service.id).exists())
        book = get_export_workbook([provider], [service],
                                   cell_overwrite_ok=True)

        # Now blank out everything about the service except its 'id'
        blank_out_row_for_testing(book, sheet_num=1, row_num=1)

        rsp = self.import_book(book)
        self.assertContains(rsp,
                            "%d is not a service this user may delete" %
                            service.id,
                            status_code=BAD_REQUEST,
                            msg_prefix=rsp.content.decode('utf-8'))
コード例 #12
0
    def test_staff_delete_nonexistent_service(self):
        self.user.is_staff = True
        self.user.save()
        provider = ProviderFactory(user=self.user)
        type = ServiceTypeFactory()
        area = ServiceAreaFactory()
        service = ServiceFactory(type=type, area_of_service=area)
        self.assertTrue(Service.objects.filter(id=service.id).exists())
        book = get_export_workbook([provider], [service],
                                   cell_overwrite_ok=True)
        service_id = service.id
        service.delete()

        # Now blank out everything about the service except its 'id'
        blank_out_row_for_testing(book, sheet_num=1, row_num=1)

        rsp = self.import_book(book)
        self.assertContains(rsp,
                            "No service with id=%d" % service_id,
                            status_code=BAD_REQUEST,
                            msg_prefix=rsp.content.decode('utf-8'))
コード例 #13
0
 def test_provider_add_anothers_service(self):
     # A provider can't add a service to another provider
     provider = ProviderFactory()
     type = ServiceTypeFactory()
     area = ServiceAreaFactory()
     service = ServiceFactory.build(provider=provider,
                                    type=type,
                                    area_of_service=area)
     book = get_export_workbook([provider], [service])
     rsp = self.import_book(book)
     self.assertEqual(BAD_REQUEST,
                      rsp.status_code,
                      msg=rsp.content.decode('utf-8'))
     self.assertContains(rsp,
                         "%d is not a provider this user may import" %
                         provider.id,
                         status_code=BAD_REQUEST)
     self.assertContains(
         rsp,
         "Non-staff users may not create services for other providers",
         status_code=BAD_REQUEST)
コード例 #14
0
 def test_provider_change_anothers_service(self):
     # A provider cannot change another provider's existing service
     provider = ProviderFactory()
     type = ServiceTypeFactory()
     area = ServiceAreaFactory()
     service = ServiceFactory(provider=provider,
                              type=type,
                              area_of_service=area)
     service.name_en = 'Radiator Repair'
     service.name_fr = 'Le Marseilles'
     book = get_export_workbook([provider], [service])
     rsp = self.import_book(book)
     # self.fail(rsp.content.decode('utf-8'))
     self.assertEqual(BAD_REQUEST,
                      rsp.status_code,
                      msg=rsp.content.decode('utf-8'))
     self.assertContains(rsp,
                         "%d is not a provider this user may import" %
                         provider.id,
                         status_code=BAD_REQUEST)
     self.assertContains(rsp,
                         "%d is not a service this user may import" %
                         service.id,
                         status_code=BAD_REQUEST)
コード例 #15
0
 def test_provider_add_service(self):
     # A provider can create a new service for themselves
     provider = ProviderFactory(user=self.user)
     type = ServiceTypeFactory()
     area = ServiceAreaFactory()
     service = ServiceFactory.build(provider=provider,
                                    type=type,
                                    area_of_service=area,
                                    tuesday_open=time(6, 59),
                                    tuesday_close=time(21, 2))
     self.assertIsNotNone(service.location)
     criterion = SelectionCriterionFactory.build(service=service)
     book = get_export_workbook([provider], [service], [criterion])
     rsp = self.import_book(book)
     self.assertEqual(OK, rsp.status_code, msg=rsp.content.decode('utf-8'))
     new_service = Service.objects.get(name_en=service.name_en)
     self.assertEqual(new_service.name_en, service.name_en)
     self.assertTrue(
         SelectionCriterion.objects.filter(
             service=new_service, text_en=criterion.text_en).exists())
     self.assertIsNotNone(new_service.location)
     self.assertEqual(service.location, new_service.location)
     self.assertEqual(service.tuesday_open, new_service.tuesday_open)
     self.assertEqual(service.tuesday_close, new_service.tuesday_close)