Ejemplo n.º 1
0
 def test_set_latitude(self):
     service = ServiceFactory(location=None)
     service.latitude = -66.2
     self.assertEqual(Point(0, -66.2), service.location)
     service = ServiceFactory(location='POINT( 1.0 2.0)')
     service.latitude = -66.2
     self.assertEqual(Point(1.0, -66.2), service.location)
Ejemplo n.º 2
0
 def test_cancel_cleans_up_pending_changes(self):
     service1 = ServiceFactory(status=Service.STATUS_CURRENT)
     # Make copy of service1 as an update
     service2 = Service.objects.get(pk=service1.pk)
     service2.pk = None
     service2.update_of = service1
     service2.status = Service.STATUS_DRAFT
     service2.save()
     service1.cancel()
     service2 = Service.objects.get(pk=service2.pk)
     self.assertEqual(Service.STATUS_CANCELED, service2.status)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
    def test_provider_delete_nonexistent_service(self):
        provider = ProviderFactory(user=self.user)
        type = ServiceTypeFactory()
        area = ServiceAreaFactory()
        service = ServiceFactory(provider=provider, 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,
                            "Row 2: service: %d is not a service this user may delete" % service_id,
                            status_code=BAD_REQUEST,
                            msg_prefix=rsp.content.decode('utf-8'))
Ejemplo n.º 8
0
 def setUp(self):
     self.service = ServiceFactory(status=Service.STATUS_DRAFT,
                                   location="POINT (33.0000 35.0000)")
     self.password = '******'
     self.user = EmailUserFactory(is_staff=True, password=self.password)
     assert self.user.is_staff
     group = Group.objects.get(name='Staff')
     self.user.groups.add(group)
     assert self.user.has_perm('services.change_service')
     assert self.client.login(email=self.user.email, password=self.password)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
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'))
Ejemplo n.º 12
0
 def setUp(self):
     self.service_ar = ServiceFactory(
         name_ar='Arabic', name_en='', name_fr='',
         description_ar='language-of-Egypt',
         status=Service.STATUS_CURRENT
     )
     self.service_ar.save()
     self.service_en = ServiceFactory(
         name_en='English', name_ar='', name_fr='',
         description_en='language-of-Australia',
         status=Service.STATUS_CURRENT
     )
     self.service_en.save()
     self.service_fr = ServiceFactory(
         name_fr='French', name_ar='', name_en='',
         description_fr='language-of-France',
         status=Service.STATUS_CURRENT
     )
     self.service_fr.save()
     self.rejected_service_fr = ServiceFactory(
         name_fr='InactiveParis', name_ar='', name_en='',
         status=Service.STATUS_REJECTED
     )
     self.rejected_service_fr.save()
Ejemplo n.º 13
0
 def test_provider_bad_criteria(self):
     provider = ProviderFactory(user=self.user)
     service = ServiceFactory(provider=provider,
                              status=Service.STATUS_CURRENT)
     criterion1 = SelectionCriterionFactory(service=service)
     criterion2 = SelectionCriterionFactory(service=service)
     # Change the 2nd one's text before exporting
     for field in generate_translated_fields('text', False):
         setattr(criterion2, field, '')
     book = get_export_workbook([provider], None, [criterion1, criterion2])
     rsp = self.import_book(book)
     self.assertContains(
         rsp,
         "Selection criterion must have text in at least one language",
         status_code=BAD_REQUEST,
         msg_prefix=rsp.content.decode('utf-8'))
Ejemplo n.º 14
0
    def execute_query(self, user_gql_client, profile_input):
        service = ServiceFactory()

        setup_profile_and_staff_user_to_service(self.profile,
                                                user_gql_client.user,
                                                service,
                                                can_manage_sensitivedata=True)

        profile_input["id"] = to_global_id("ProfileNode", self.profile.id)
        variables = {"profileInput": profile_input}

        return user_gql_client.execute(
            EMAILS_MUTATION,
            service=service,
            variables=variables,
        )
Ejemplo n.º 15
0
class IndexingTest(TestCase):
    def setUp(self):
        self.service_ar = ServiceFactory(name_ar='Arabic',
                                         name_en='',
                                         name_fr='',
                                         description_ar='language-of-Egypt',
                                         status=Service.STATUS_CURRENT)
        self.service_ar.save()
        self.service_en = ServiceFactory(
            name_en='English',
            name_ar='',
            name_fr='',
            description_en='language-of-Australia',
            status=Service.STATUS_CURRENT)
        self.service_en.save()
        self.service_fr = ServiceFactory(name_fr='French',
                                         name_ar='',
                                         name_en='',
                                         description_fr='language-of-France',
                                         status=Service.STATUS_CURRENT)
        self.service_fr.save()
        self.rejected_service_fr = ServiceFactory(
            name_fr='InactiveParis',
            name_ar='',
            name_en='',
            status=Service.STATUS_REJECTED)
        self.rejected_service_fr.save()

    def test_querysets(self):
        index = ServiceIndex()
        self.assertIn(self.service_ar, index.get_index_queryset('ar'))
        self.assertNotIn(self.service_ar, index.get_index_queryset('en'))

        self.assertIn(self.service_fr, index.get_index_queryset('fr'))
        self.assertNotIn(self.service_fr, index.get_index_queryset('ar'))

        self.assertNotIn(self.rejected_service_fr,
                         index.get_index_queryset('fr'))

    def test_search_data(self):
        index = ServiceIndex()
        ar_data = index.get_search_data(self.service_ar, 'ar', None)
        self.assertIn('Egypt', ar_data)
        en_data = index.get_search_data(self.service_en, 'en', None)
        self.assertIn('Australia', en_data)
Ejemplo n.º 16
0
class JiraApproveServiceTest(MockJiraTestMixin, TestCase):
    def setUp(self):
        self.test_service = ServiceFactory(location='POINT(5 23)')
        self.jira_record = self.test_service.jira_records.get(
            update_type=JiraUpdateRecord.NEW_SERVICE)
        self.staff_user = EmailUserFactory(is_staff=True)

    def test_approving_service_creates_record(self, mock_JIRA):
        self.test_service.staff_approve(self.staff_user)
        self.assertTrue(self.test_service.jira_records.filter(
            update_type=JiraUpdateRecord.APPROVE_SERVICE).exists())

    def test_rejecting_service_creates_record(self, mock_JIRA):
        self.test_service.staff_reject(self.staff_user)
        self.assertTrue(self.test_service.jira_records.filter(
            update_type=JiraUpdateRecord.REJECT_SERVICE).exists())

    def test_approval_comments_on_issue(self, mock_JIRA):
        self.test_service.staff_approve(self.staff_user)
        issue_key = self.setup_issue_key(mock_JIRA)
        self.jira_record.do_jira_work()
        record2 = self.test_service.jira_records.get(
            update_type=JiraUpdateRecord.APPROVE_SERVICE)
        record2.do_jira_work()
        self.assertEqual(self.jira_record.jira_issue_key, record2.jira_issue_key)
        call_args, call_kwargs = mock_JIRA.return_value.add_comment.call_args
        self.assertEqual(
            (issue_key, "The new service was approved by %s." % self.staff_user.email),
            call_args)
        self.assertEqual({}, call_kwargs)

    def test_rejecting_comments_on_issue(self, mock_JIRA):
        self.test_service.staff_reject(self.staff_user)
        issue_key = self.setup_issue_key(mock_JIRA)
        self.jira_record.do_jira_work()
        record2 = self.test_service.jira_records.get(
            update_type=JiraUpdateRecord.REJECT_SERVICE)
        record2.do_jira_work()
        self.assertEqual(self.jira_record.jira_issue_key, record2.jira_issue_key)
        call_args, call_kwargs = mock_JIRA.return_value.add_comment.call_args
        self.assertEqual(
            (issue_key, "The new service was rejected by %s." % self.staff_user.email),
            call_args)
        self.assertEqual({}, call_kwargs)
Ejemplo n.º 17
0
 def test_approval_validation(self):
     service = ServiceFactory(location=None)
     # No location - should not allow approval
     try:
         service.validate_for_approval()
     except ValidationError as e:
         self.assertIn('location', e.error_dict)
     else:
         self.fail("Should have gotten ValidationError")
     # Add location, should be okay
     service.location = 'POINT(5 23)'
     service.validate_for_approval()
     # No name, should fail
     name_fields = generate_translated_fields('name', False)
     for field in name_fields:
         setattr(service, field, '')
     try:
         service.validate_for_approval()
     except ValidationError as e:
         self.assertIn('name', e.error_dict)
     else:
         self.fail("Should have gotten ValidationError")
Ejemplo n.º 18
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'))
Ejemplo n.º 19
0
class IndexingTest(TestCase):

    def setUp(self):
        self.service_ar = ServiceFactory(
            name_ar='Arabic', name_en='', name_fr='',
            description_ar='language-of-Egypt',
            status=Service.STATUS_CURRENT
        )
        self.service_ar.save()
        self.service_en = ServiceFactory(
            name_en='English', name_ar='', name_fr='',
            description_en='language-of-Australia',
            status=Service.STATUS_CURRENT
        )
        self.service_en.save()
        self.service_fr = ServiceFactory(
            name_fr='French', name_ar='', name_en='',
            description_fr='language-of-France',
            status=Service.STATUS_CURRENT
        )
        self.service_fr.save()
        self.rejected_service_fr = ServiceFactory(
            name_fr='InactiveParis', name_ar='', name_en='',
            status=Service.STATUS_REJECTED
        )
        self.rejected_service_fr.save()

    def test_querysets(self):
        index = ServiceIndex()
        self.assertIn(self.service_ar, index.get_index_queryset('ar'))
        self.assertNotIn(self.service_ar, index.get_index_queryset('en'))

        self.assertIn(self.service_fr, index.get_index_queryset('fr'))
        self.assertNotIn(self.service_fr, index.get_index_queryset('ar'))

        self.assertNotIn(self.rejected_service_fr, index.get_index_queryset('fr'))

    def test_search_data(self):
        index = ServiceIndex()
        ar_data = index.get_search_data(self.service_ar, 'ar', None)
        self.assertIn('Egypt', ar_data)
        en_data = index.get_search_data(self.service_en, 'en', None)
        self.assertIn('Australia', en_data)
Ejemplo n.º 20
0
    def execute(
        self,
        *args,
        auth_token_payload=None,
        service=_not_provided,
        context=None,
        **kwargs
    ):
        """
        Custom execute method which adds all of the middlewares defined in the
        settings to the execution. Additionally adds a profile service to the
        context if no service is provided.

        e.g. GQL DataLoaders middleware is used to make the DataLoaders
        available through the context.
        """
        if context is None:
            context = RequestFactory().post("/graphql")

        if not hasattr(context, "user") and hasattr(self, "user"):
            context.user = self.user

        if (
            hasattr(context, "user")
            and context.user.is_authenticated
            and not hasattr(context, "user_auth")
        ):
            context.user_auth = UserAuthorization(
                context.user, auth_token_payload or {}
            )

        if not hasattr(context, "service"):
            context.service = None

        if service is _not_provided:
            context.service = ServiceFactory(name="profile", is_profile_service=True)
        elif service:
            context.service = service

        return super().execute(
            *args,
            context=context,
            middleware=list(instantiate_middleware(graphene_settings.MIDDLEWARE)),
            **kwargs
        )
Ejemplo n.º 21
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())
Ejemplo n.º 22
0
    def test_text_list_search(self):
        """Find services by text based search."""

        service = ServiceFactory(status=Service.STATUS_CURRENT)
        self.load_page_and_set_language()
        menu = self.wait_for_element('menu')
        search = menu.find_elements_by_link_text('Search')[0]
        search.click()
        form = self.wait_for_element('search_controls')
        self.assertHashLocation('/search')
        form.find_element_by_name('filtered-search').send_keys(
            service.provider.name_en[:5])
        # Results are updated automatically as search characters are entered
        # Wait a sec to make sure we have the final results
        time.sleep(1)
        result = self.wait_for_element('.search-result-list > li', match=By.CSS_SELECTOR)
        name = result.find_element_by_class_name('name')
        self.assertEqual(name.text, service.name_en)
Ejemplo n.º 23
0
 def test_approval_validation(self):
     service = ServiceFactory(location=None)
     # No location - should not allow approval
     try:
         service.validate_for_approval()
     except ValidationError as e:
         self.assertIn('location', e.error_dict)
     else:
         self.fail("Should have gotten ValidationError")
     # Add location, should be okay
     service.location = 'POINT(5 23)'
     service.validate_for_approval()
     # No name, should fail
     service.name_en = service.name_ar = service.name_fr = ''
     try:
         service.validate_for_approval()
     except ValidationError as e:
         self.assertIn('name', e.error_dict)
     else:
         self.fail("Should have gotten ValidationError")
Ejemplo n.º 24
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'))
Ejemplo n.º 25
0
 def test_provider_add_criteria(self):
     provider = ProviderFactory(user=self.user)
     service = ServiceFactory(provider=provider,
                              status=Service.STATUS_CURRENT)
     criterion1 = SelectionCriterionFactory(service=service)
     criterion2 = SelectionCriterionFactory.build(service=service,
                                                  text_en="New Criterion!")
     book = get_export_workbook([provider], None, [criterion1, criterion2])
     rsp = self.import_book(book)
     self.assertEqual(OK, rsp.status_code, msg=rsp.content.decode('utf-8'))
     # Existing one still there
     self.assertTrue(
         SelectionCriterion.objects.filter(service=service,
                                           text_en=criterion1.text_en,
                                           id=criterion1.id).exists())
     # New one added
     self.assertTrue(
         SelectionCriterion.objects.filter(
             service=service, text_en=criterion2.text_en).exists())
Ejemplo n.º 26
0
 def test_services_pagination(self):
     # We can paginate the service search results
     for x in range(10):
         ServiceFactory(status=Service.STATUS_CURRENT)
     rsp = self.client.get(self.url + "?limit=5")  # not authed
     self.assertEqual(OK, rsp.status_code, msg=rsp.content.decode('utf-8'))
     response = json.loads(rsp.content.decode('utf-8'))
     records_returned = response['results']
     self.assertEqual(5, len(records_returned))
     first_five = records_returned
     rsp = self.client.get(self.url + "?limit=5&offset=5")  # not authed
     self.assertEqual(OK, rsp.status_code, msg=rsp.content.decode('utf-8'))
     response = json.loads(rsp.content.decode('utf-8'))
     records_returned = response['results']
     self.assertEqual(5, len(records_returned))
     last_five = records_returned
     records_in_both = set(r['id']
                           for r in first_five) & set(r['id']
                                                      for r in last_five)
     self.assertFalse(records_in_both)
Ejemplo n.º 27
0
 def test_provider_change_criteria(self):
     provider = ProviderFactory(user=self.user)
     service = ServiceFactory(provider=provider,
                              status=Service.STATUS_CURRENT)
     criterion1 = SelectionCriterionFactory(service=service)
     criterion2 = SelectionCriterionFactory(service=service)
     # Change the 2nd one's text before exporting
     criterion2.text_en = criterion2.text_ar = criterion2.text_fr = 'Oh dear me'
     book = get_export_workbook([provider], None, [criterion1, criterion2])
     rsp = self.import_book(book)
     self.assertEqual(OK, rsp.status_code, msg=rsp.content.decode('utf-8'))
     # 1st one still there
     self.assertTrue(
         SelectionCriterion.objects.filter(service=service,
                                           text_en=criterion1.text_en,
                                           id=criterion1.id).exists())
     # 2nd one changed
     crit2 = SelectionCriterion.objects.get(id=criterion2.id)
     self.assertEqual(crit2.text_en, criterion2.text_en)
     self.assertEqual(crit2.text_ar, criterion2.text_ar)
     self.assertEqual(crit2.text_fr, criterion2.text_fr)
Ejemplo n.º 28
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)
def test_services_are_ordered_by_id(user_gql_client):
    allowed_data_field = AllowedDataFieldFactory()
    services = ServiceFactory.create_batch(3)
    for service in services:
        service.allowed_data_fields.set([allowed_data_field])

    profile = ProfileFactory(user=user_gql_client.user)
    ServiceConnectionFactory(profile=profile, service=services[0])

    executed = user_gql_client.execute(QUERY)

    connection_edges = executed["data"]["myProfile"]["serviceConnections"]["edges"]

    assert len(connection_edges) == 1
    service_node = connection_edges[0]["node"]["service"]
    allowed_data_field_edges = service_node["allowedDataFields"]["edges"]
    assert len(allowed_data_field_edges) == 1
    service_edges = allowed_data_field_edges[0]["node"]["serviceSet"]["edges"]

    for service_edge, service in zip(service_edges, services):
        assert service_edge["node"]["name"] == service.name
Ejemplo n.º 30
0
    def test_get_failure(self):
        a_type = ServiceType.objects.first()
        service = ServiceFactory(type=a_type)
        FeedbackFactory(service=service,
                        delivered=True,
                        non_delivery_explained='no')
        FeedbackFactory(service=service,
                        delivered=True,
                        non_delivery_explained='no')
        FeedbackFactory(service=service,
                        delivered=True,
                        non_delivery_explained='yes')
        url = reverse('report-failure')
        rsp = self.get_with_token(url)
        self.assertEqual(OK, rsp.status_code)
        result = json.loads(rsp.content.decode('utf-8'))
        self.assertEqual(len(result), ServiceType.objects.all().count())
        for r in result:
            if r['number'] == a_type.number:
                # 1, 2, 3, 4, 5
                expected_totals = [
                    2,
                    0,
                    0,
                    1,
                ]
            else:
                expected_totals = [
                    0,
                    0,
                    0,
                    0,
                ]
            field = Feedback._meta.get_field('non_delivery_explained')

            expected_labels = [str(label) for value, label in field.choices]
            self.assertIn('totals', r)
            totals = r['totals']
            self.assertEqual([t['label_en'] for t in totals], expected_labels)
            self.assertEqual([t['total'] for t in totals], expected_totals)
Ejemplo n.º 31
0
    def test_filtered_list_search(self):
        """Find services by type."""

        service = ServiceFactory(status=Service.STATUS_CURRENT)
        self.load_page_and_set_language()
        menu = self.wait_for_element('menu')
        search = menu.find_elements_by_link_text('Search')[0]
        search.click()
        form = self.wait_for_element('search_controls')
        self.assertHashLocation('/search')
        Select(form.find_element_by_name('type')).select_by_visible_text(
            service.type.name_en)
        controls = self.wait_for_element('map-toggle', match=By.CLASS_NAME)
        controls.find_element_by_name('map-toggle-list').click()
        try:
            result = self.wait_for_element('.search-result-list > li', match=By.CSS_SELECTOR)
            name = result.find_element_by_class_name('name')
        except StaleElementReferenceException:
            # Hit a race where we got a search element but then the page replaced it
            result = self.wait_for_element('.search-result-list > li', match=By.CSS_SELECTOR)
            name = result.find_element_by_class_name('name')
        self.assertEqual(name.text, service.name_en)
Ejemplo n.º 32
0
    def test_search_list_results_limited(self):
        """No more than MAX_RESULTS services in result"""
        for i in range(MAX_RESULTS + 5):
            ServiceFactory(status=Service.STATUS_CURRENT)
        self.load_page_and_set_language()
        menu = self.wait_for_element('menu')
        search = menu.find_elements_by_link_text('Search')[0]
        search.click()
        self.wait_for_element('search_controls')
        self.assertHashLocation('/search')
        self.wait_for_element('.search-result-list > li', match=By.CSS_SELECTOR)
        results = self.browser.find_elements_by_css_selector('.search-result-list > li')
        self.assertEqual(MAX_RESULTS, len(results))

        # While we're here, make sure the "request new service" button
        # has shown up
        button = self.wait_for_element('#request_service_button', match=By.CSS_SELECTOR)

        # Clicking it should go to the request a service page
        button.click()
        self.wait_for_element('#service-request', match=By.CSS_SELECTOR)
        self.assertHashLocation('/service/request')
Ejemplo n.º 33
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)
Ejemplo n.º 34
0
    def test_provider_remove_criteria(self):
        provider = ProviderFactory(user=self.user)
        service = ServiceFactory(provider=provider,
                                 status=Service.STATUS_CURRENT)
        criterion1 = SelectionCriterionFactory(service=service)
        criterion2 = SelectionCriterionFactory(service=service)
        book = get_export_workbook([provider],
                                   None, [criterion1, criterion2],
                                   cell_overwrite_ok=True)

        # Blank out the 2nd one's data to indicate it should be deleted
        blank_out_row_for_testing(book, sheet_num=2, row_num=2)

        rsp = self.import_book(book)
        self.assertEqual(OK, rsp.status_code, msg=rsp.content.decode('utf-8'))
        # 1st one still there
        self.assertTrue(
            SelectionCriterion.objects.filter(service=service,
                                              text_en=criterion1.text_en,
                                              id=criterion1.id).exists())
        # 2nd one removed
        self.assertFalse(
            SelectionCriterion.objects.filter(id=criterion2.id).exists())
Ejemplo n.º 35
0
 def test_get_wait_times(self):
     a_type = ServiceType.objects.first()
     service = ServiceFactory(type=a_type)
     FeedbackFactory(service=service, delivered=True, wait_time='lesshour')
     FeedbackFactory(service=service, delivered=True, wait_time='lesshour')
     FeedbackFactory(service=service, delivered=True, wait_time='more')
     url = reverse('report-wait-times')
     rsp = self.get_with_token(url)
     self.assertEqual(OK, rsp.status_code)
     result = json.loads(rsp.content.decode('utf-8'))
     self.assertEqual(len(result), ServiceType.objects.all().count())
     for r in result:
         if r['number'] == a_type.number:
             # less than hour, 1-2 days, 3-7 days, 1-2 weeks, more than 2 weeks
             expected_totals = [
                 2,
                 0,
                 0,
                 0,
                 1,
             ]
         else:
             expected_totals = [
                 0,
                 0,
                 0,
                 0,
                 0,
             ]
         expected_labels = [
             'Less than 1 hour', 'Up to 2 days', '3-7 days', '1-2 weeks',
             'More than 2 weeks'
         ]
         self.assertIn('totals', r)
         totals = r['totals']
         self.assertEqual([t['label_en'] for t in totals], expected_labels)
         self.assertEqual([t['total'] for t in totals], expected_totals)
Ejemplo n.º 36
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)
Ejemplo n.º 37
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)
Ejemplo n.º 38
0
class ServiceAdminTest(TestCase):
    def setUp(self):
        self.service = ServiceFactory(status=Service.STATUS_DRAFT,
                                      location="POINT (33.0000 35.0000)")
        self.password = '******'
        self.user = EmailUserFactory(is_staff=True, password=self.password)
        assert self.user.is_staff
        group = Group.objects.get(name='Staff')
        self.user.groups.add(group)
        assert self.user.has_perm('services.change_service')
        assert self.client.login(email=self.user.email, password=self.password)

    def test_permissions(self):
        # Must have Staff group to access services in the admin
        self.user.groups.remove(Group.objects.get(name='Staff'))
        rsp = self.client.get(reverse('admin:services_service_change', args=[self.service.pk]))
        self.assertEqual(403, rsp.status_code)
        rsp = self.save_service_in_form()
        self.assertEqual(403, rsp.status_code)

    def save_service_in_form(self, **kwargs):
        """
        Simulate loading the service in a change form in the admin, updating
        some data from **kwargs, and submitting.
        Returns the response returned by the post.
        """
        data = model_to_dict(self.service)
        data['location'] = str(data['location'])
        # inline data
        data["selection_criteria-TOTAL_FORMS"] = 0
        data["selection_criteria-INITIAL_FORMS"] = 0
        data["selection_criteria-MIN_NUM_FORMS"] = 0
        data["selection_criteria-MAX_NUM_FORMS"] = 0
        # Drop any None values
        data = {k: v for k, v in data.items() if v is not None}
        # Update with caller data
        data.update(**kwargs)
        rsp = self.client.post(reverse('admin:services_service_change', args=[self.service.pk]),
                               data=data)
        return rsp

    def test_edit_service(self):
        # Make a change to the data
        rsp = self.save_service_in_form(name_en="New service name")
        self.assertEqual(302, rsp.status_code, msg=rsp.content.decode('utf-8'))
        service = Service.objects.get(pk=self.service.pk)
        self.assertEqual("New service name", service.name_en)

    def test_approve_button(self):
        rsp = self.save_service_in_form(name_en="New service name",
                                        _approve=True,  # the button we "clicked"
                                        )
        self.assertEqual(302, rsp.status_code, msg=rsp.content.decode('utf-8'))
        service = Service.objects.get(pk=self.service.pk)
        self.assertEqual("New service name", service.name_en)
        self.assertEqual(Service.STATUS_CURRENT, service.status)

    def test_approve_button_with_bad_data(self):
        rsp = self.save_service_in_form(name_en="New service name",
                                        location="not a valid location",
                                        _approve=True,  # the button we "clicked"
                                        )
        self.assertEqual(200, rsp.status_code, msg=rsp.content.decode('utf-8'))
        self.assertIn('<ul class="errorlist"><li>Invalid geometry value.</li></ul>',
                      rsp.context['errors'])
        service = Service.objects.get(pk=self.service.pk)
        self.assertEqual(Service.STATUS_DRAFT, service.status)

    def test_approve_button_with_missing_data(self):
        rsp = self.save_service_in_form(name_en="New service name",
                                        location='',
                                        _approve=True,  # the button we "clicked"
                                        )
        self.assertEqual(200, rsp.status_code, msg=rsp.content.decode('utf-8'))
        self.assertIn('<ul class="errorlist"><li>No geometry value provided.</li></ul>',
                      rsp.context['errors'])
        service = Service.objects.get(pk=self.service.pk)
        self.assertEqual(Service.STATUS_DRAFT, service.status)

    def test_reject_button(self):
        rsp = self.save_service_in_form(name_en="New service name",
                                        _reject=True,  # the button we "clicked"
                                        )
        self.assertEqual(302, rsp.status_code, msg=rsp.content.decode('utf-8'))
        service = Service.objects.get(pk=self.service.pk)
        self.assertEqual("New service name", service.name_en)
        self.assertEqual(Service.STATUS_REJECTED, service.status)

    def test_actions_appear(self):
        rsp = self.client.get(reverse('admin:services_service_changelist'))
        self.assertContains(rsp, "Approve new or changed service")
        self.assertContains(rsp, "Reject new or changed service")

    def test_buttons_appear(self):
        rsp = self.client.get(reverse('admin:services_service_change', args=[self.service.pk]))
        self.assertContains(rsp, "Save and approve")
        self.assertContains(rsp, "Save and reject")

    def test_approve_action(self):
        self.service.validate_for_approval()
        data = {
            'index': '0',  # "Go" button
            'action': 'approve',  # selected action
            '_selected_action': [
                str(self.service.pk),  # selected checkbox
            ]
        }
        rsp = self.client.post(reverse('admin:services_service_changelist'), data)
        self.assertEqual(302, rsp.status_code, msg=rsp.content.decode('utf-8'))
        new_url = rsp['Location']
        rsp = self.client.get(new_url)
        self.assertEqual(200, rsp.status_code, msg=rsp.content.decode('utf-8'))
        service = Service.objects.get(pk=self.service.pk)
        self.assertEqual(Service.STATUS_CURRENT, service.status)

    def test_reject_action(self):
        data = {
            'index': '0',  # "Go" button
            'action': 'reject',  # selected action
            '_selected_action': [
                str(self.service.pk),  # selected checkbox
            ]
        }
        rsp = self.client.post(reverse('admin:services_service_changelist'), data)
        self.assertEqual(302, rsp.status_code, msg=rsp.content.decode('utf-8'))
        new_url = rsp['Location']
        rsp = self.client.get(new_url)
        self.assertEqual(200, rsp.status_code, msg=rsp.content.decode('utf-8'))
        service = Service.objects.get(pk=self.service.pk)
        self.assertEqual(Service.STATUS_REJECTED, service.status)

    def test_approve_action_wrong_status(self):
        self.service.status = Service.STATUS_CURRENT
        self.service.save()
        data = {
            'index': '0',  # "Go" button
            'action': 'approve',  # selected action
            '_selected_action': [
                str(self.service.pk),  # selected checkbox
            ]
        }
        rsp = self.client.post(reverse('admin:services_service_changelist'), data, follow=True)
        self.assertEqual(200, rsp.status_code)
        self.assertIn('Only services in draft status may be approved',
                      [str(msg) for msg in rsp.context['messages']])

    def test_reject_action_wrong_status(self):
        self.service.status = Service.STATUS_CURRENT
        self.service.save()
        data = {
            'index': '0',  # "Go" button
            'action': 'reject',  # selected action
            '_selected_action': [
                str(self.service.pk),  # selected checkbox
            ]
        }
        rsp = self.client.post(reverse('admin:services_service_changelist'), data, follow=True)
        self.assertEqual(200, rsp.status_code)
        self.assertIn('Only services in draft status may be rejected',
                      [str(msg) for msg in rsp.context['messages']])

    def test_show_image_in_changelist(self):
        rsp = self.client.get(reverse('admin:services_service_changelist'))
        image_tag = '<img src="%s">' % self.service.get_thumbnail_url()
        self.assertContains(rsp, image_tag, html=True)

    def test_show_no_image_if_not_set(self):
        self.service.image = ''
        self.service.save()
        rsp = self.client.get(reverse('admin:services_service_changelist'))
        self.assertContains(rsp, 'no image')
Ejemplo n.º 39
0
class ServiceAdminTest(TestCase):
    def setUp(self):
        self.service = ServiceFactory(status=Service.STATUS_DRAFT,
                                      location="POINT (33.0000 35.0000)")
        self.password = '******'
        self.user = EmailUserFactory(is_staff=True, password=self.password)
        assert self.user.is_staff
        group = Group.objects.get(name='Staff')
        self.user.groups.add(group)
        assert self.user.has_perm('services.change_service')
        assert self.client.login(email=self.user.email, password=self.password)

    def test_permissions(self):
        # Must have Staff group to access services in the admin
        self.user.groups.remove(Group.objects.get(name='Staff'))
        rsp = self.client.get(
            reverse('admin:services_service_change', args=[self.service.pk]))
        self.assertEqual(403, rsp.status_code)
        rsp = self.save_service_in_form()
        self.assertEqual(403, rsp.status_code)

    def save_service_in_form(self, **kwargs):
        """
        Simulate loading the service in a change form in the admin, updating
        some data from **kwargs, and submitting.
        Returns the response returned by the post.
        """
        data = model_to_dict(self.service)
        data['location'] = str(data['location'])
        # inline data
        data["selection_criteria-TOTAL_FORMS"] = 0
        data["selection_criteria-INITIAL_FORMS"] = 0
        data["selection_criteria-MIN_NUM_FORMS"] = 0
        data["selection_criteria-MAX_NUM_FORMS"] = 0
        # Drop any None values
        data = {k: v for k, v in data.items() if v is not None}
        # Update with caller data
        data.update(**kwargs)
        rsp = self.client.post(reverse('admin:services_service_change',
                                       args=[self.service.pk]),
                               data=data)
        return rsp

    def test_edit_service(self):
        # Make a change to the data
        rsp = self.save_service_in_form(name_en="New service name")
        self.assertEqual(302, rsp.status_code, msg=rsp.content.decode('utf-8'))
        service = Service.objects.get(pk=self.service.pk)
        self.assertEqual("New service name", service.name_en)

    def test_approve_button(self):
        rsp = self.save_service_in_form(
            name_en="New service name",
            _approve=True,  # the button we "clicked"
        )
        self.assertEqual(302, rsp.status_code, msg=rsp.content.decode('utf-8'))
        service = Service.objects.get(pk=self.service.pk)
        self.assertEqual("New service name", service.name_en)
        self.assertEqual(Service.STATUS_CURRENT, service.status)

    def test_approve_button_with_bad_data(self):
        rsp = self.save_service_in_form(
            name_en="New service name",
            location="not a valid location",
            _approve=True,  # the button we "clicked"
        )
        self.assertEqual(200, rsp.status_code, msg=rsp.content.decode('utf-8'))
        self.assertIn(
            '<ul class="errorlist"><li>Invalid geometry value.</li></ul>',
            rsp.context['errors'])
        service = Service.objects.get(pk=self.service.pk)
        self.assertEqual(Service.STATUS_DRAFT, service.status)

    def test_approve_button_with_missing_data(self):
        rsp = self.save_service_in_form(
            name_en="New service name",
            location='',
            _approve=True,  # the button we "clicked"
        )
        self.assertEqual(200, rsp.status_code, msg=rsp.content.decode('utf-8'))
        self.assertIn(
            '<ul class="errorlist"><li>No geometry value provided.</li></ul>',
            rsp.context['errors'])
        service = Service.objects.get(pk=self.service.pk)
        self.assertEqual(Service.STATUS_DRAFT, service.status)

    def test_reject_button(self):
        rsp = self.save_service_in_form(
            name_en="New service name",
            _reject=True,  # the button we "clicked"
        )
        self.assertEqual(302, rsp.status_code, msg=rsp.content.decode('utf-8'))
        service = Service.objects.get(pk=self.service.pk)
        self.assertEqual("New service name", service.name_en)
        self.assertEqual(Service.STATUS_REJECTED, service.status)

    def test_actions_appear(self):
        rsp = self.client.get(reverse('admin:services_service_changelist'))
        self.assertContains(rsp, "Approve new or changed service")
        self.assertContains(rsp, "Reject new or changed service")

    def test_buttons_appear(self):
        rsp = self.client.get(
            reverse('admin:services_service_change', args=[self.service.pk]))
        self.assertContains(rsp, "Save and approve")
        self.assertContains(rsp, "Save and reject")

    def test_approve_action(self):
        self.service.validate_for_approval()
        data = {
            'index': '0',  # "Go" button
            'action': 'approve',  # selected action
            '_selected_action': [
                str(self.service.pk),  # selected checkbox
            ]
        }
        rsp = self.client.post(reverse('admin:services_service_changelist'),
                               data)
        self.assertEqual(302, rsp.status_code, msg=rsp.content.decode('utf-8'))
        new_url = rsp['Location']
        rsp = self.client.get(new_url)
        self.assertEqual(200, rsp.status_code, msg=rsp.content.decode('utf-8'))
        service = Service.objects.get(pk=self.service.pk)
        self.assertEqual(Service.STATUS_CURRENT, service.status)

    def test_reject_action(self):
        data = {
            'index': '0',  # "Go" button
            'action': 'reject',  # selected action
            '_selected_action': [
                str(self.service.pk),  # selected checkbox
            ]
        }
        rsp = self.client.post(reverse('admin:services_service_changelist'),
                               data)
        self.assertEqual(302, rsp.status_code, msg=rsp.content.decode('utf-8'))
        new_url = rsp['Location']
        rsp = self.client.get(new_url)
        self.assertEqual(200, rsp.status_code, msg=rsp.content.decode('utf-8'))
        service = Service.objects.get(pk=self.service.pk)
        self.assertEqual(Service.STATUS_REJECTED, service.status)

    def test_approve_action_wrong_status(self):
        self.service.status = Service.STATUS_CURRENT
        self.service.save()
        data = {
            'index': '0',  # "Go" button
            'action': 'approve',  # selected action
            '_selected_action': [
                str(self.service.pk),  # selected checkbox
            ]
        }
        rsp = self.client.post(reverse('admin:services_service_changelist'),
                               data,
                               follow=True)
        self.assertEqual(200, rsp.status_code)
        self.assertIn('Only services in draft status may be approved',
                      [str(msg) for msg in rsp.context['messages']])

    def test_reject_action_wrong_status(self):
        self.service.status = Service.STATUS_CURRENT
        self.service.save()
        data = {
            'index': '0',  # "Go" button
            'action': 'reject',  # selected action
            '_selected_action': [
                str(self.service.pk),  # selected checkbox
            ]
        }
        rsp = self.client.post(reverse('admin:services_service_changelist'),
                               data,
                               follow=True)
        self.assertEqual(200, rsp.status_code)
        self.assertIn('Only services in draft status may be rejected',
                      [str(msg) for msg in rsp.context['messages']])
Ejemplo n.º 40
0
    def test_random_data(self):
        provider = ProviderFactory()
        service1 = ServiceFactory(provider=provider, status=Service.STATUS_CURRENT)
        service2 = ServiceFactory(provider=provider, status=Service.STATUS_CURRENT)
        ServiceFactory(provider=provider, status=Service.STATUS_CURRENT)
        # Some additional services that should not show up
        ServiceFactory(status=Service.STATUS_CURRENT)  # not one of the providers we want
        ServiceFactory(provider=provider, status=Service.STATUS_DRAFT)  # Draft mode
        SelectionCriterionFactory(service=service1)
        SelectionCriterionFactory(service=service2)
        SelectionCriterionFactory()  # unwanted service

        # Querysets of just the objects we expect to be exported
        providers = Provider.objects.order_by('id')
        services = Service.objects.filter(status=Service.STATUS_CURRENT,
                                          provider__in=providers).order_by('id')
        criteria = SelectionCriterion.objects.filter(service__status=Service.STATUS_CURRENT,
                                                     service__provider__in=providers).order_by('id')

        xlwt_book = get_export_workbook(providers)
        book = save_and_read_book(xlwt_book)

        # First sheet - providers
        sheet = book.get_sheet(0)
        self.assertEqual(providers.count(), sheet.nrows - 1)
        self.assertEqual(PROVIDER_HEADINGS, sheet.row_values(0))
        for i, rownum in enumerate(range(1, sheet.nrows)):
            values = sheet.row_values(rownum)
            provider = providers[i]
            data = dict(zip(PROVIDER_HEADINGS, values))
            self.assertEqual(provider.id, data['id'])
            self.assertEqual(provider.name_ar, data['name_ar'])

        # Second sheet = services
        sheet = book.get_sheet(1)
        self.assertEqual(services.count(), sheet.nrows - 1)
        self.assertEqual(SERVICE_HEADINGS, sheet.row_values(0))
        for i, rownum in enumerate(range(1, sheet.nrows)):
            values = sheet.row_values(rownum)
            service = services[i]
            data = dict(zip(SERVICE_HEADINGS, values))
            self.assertEqual(service.id, data['id'])
            self.assertEqual(service.name_ar, data['name_ar'])
            provider = Provider.objects.get(id=data['provider__id'])
            self.assertEqual(provider, service.provider)

        # Third sheet - selection criteria
        sheet = book.get_sheet(2)
        self.assertEqual(SELECTION_CRITERIA_HEADINGS, sheet.row_values(0))
        self.assertEqual(criteria.count(), sheet.nrows - 1)
        for i, rownum in enumerate(range(1, sheet.nrows)):
            values = sheet.row_values(rownum)
            criterion = criteria[i]
            data = dict(zip(SELECTION_CRITERIA_HEADINGS, values))
            self.assertEqual(criterion.id, data['id'])
            self.assertEqual(criterion.text_ar, data['text_ar'])
            service = Service.objects.get(id=data['service__id'])
            self.assertEqual(service, criterion.service)

        # The exported workbook should also be valid for import by
        # a staff user
        user = EmailUserFactory(is_staff=True)
        validate_and_import_data(user, get_book_bits(xlwt_book))
Ejemplo n.º 41
0
 def test_non_mobile_services_dont_have_location_set(self):
     # If a service is not mobile, we don't set its location on save
     area = ServiceArea.objects.first()  # Mount Lebanon/Baabda
     service = ServiceFactory(location=None, area_of_service=area)
     self.assertIsNone(service.location)
Ejemplo n.º 42
0
 def test_get_latitude(self):
     service = ServiceFactory(location=None)
     self.assertIsNone(service.latitude)
     service = ServiceFactory(location='POINT( 1.0 2.0)')
     self.assertEqual(2.0, service.latitude)
Ejemplo n.º 43
0
    def setUp(self):
        self.test_service = ServiceFactory()

        from .set_up import create_mock_data
        create_mock_data()
Ejemplo n.º 44
0
 def test_email_provider_about_approval(self):
     service = ServiceFactory()
     with patch('services.models.email_provider_about_service_approval_task'
                ) as mock_task:
         service.email_provider_about_approval()
     mock_task.delay.assert_called_with(service.pk)
Ejemplo n.º 45
0
 def setUp(self):
     self.user = EmailUserFactory()
     self.provider = ProviderFactory(user=self.user)
     self.service = ServiceFactory(provider=self.provider)
Ejemplo n.º 46
0
    def test_feedback_page_delivered(self):
        self.assertFalse(Feedback.objects.all().exists())

        service = ServiceFactory(status=Service.STATUS_CURRENT)
        self.load_page_and_set_language()
        menu = self.wait_for_element('menu')
        feedback = menu.find_elements_by_link_text('Give Feedback')[0]
        feedback.click()
        form = self.wait_for_element('search_controls')
        self.assertHashLocation('/feedback/list')
        service_name = self.wait_for_element('a[href="#/service/%d"]' %
                                             service.id,
                                             match=By.CSS_SELECTOR)
        service_name.click()

        feedback_button = self.wait_for_element(
            'a[href="#/feedback/%d"] button' % service.id,
            match=By.CSS_SELECTOR)
        feedback_button.click()

        self.wait_for_element('input[name=anonymous]', match=By.CSS_SELECTOR)

        # Fill in the form
        form = self.wait_for_element('form', match=By.CSS_SELECTOR)

        def click_element(selector):
            form.find_element(value=selector, by=By.CSS_SELECTOR).click()

        def type_in_element(selector, text):
            try:
                self.wait_for_element(selector,
                                      match=By.CSS_SELECTOR,
                                      must_be_visible=True).send_keys(text)
            except TimeoutException:
                print("Timeout waiting for %s to appear, continuing anyway" %
                      selector)

        type_in_element('[name=name]', 'John Doe')
        type_in_element('[name=phone_number]', '12-345678')
        iraqi_nationality = Nationality.objects.get(name_en='Iraqi')
        click_element('select[name=nationality] option[value$="/%d/"]' %
                      iraqi_nationality.id)

        area = ServiceArea.objects.first()
        click_element('select[name=area_of_residence] option[value$="/%d/"]' %
                      area.id)
        click_element('input[name=anonymous][value="1"]')
        click_element('input[name=delivered][value="1"]')

        # Wait for javascript to display the "delivered" fields
        self.wait_for_element('input[name=quality][value="4"]',
                              match=By.CSS_SELECTOR,
                              must_be_visible=True)

        click_element('input[name=quality][value="4"]')
        click_element('input[name=staff_satisfaction][value="2"]')
        click_element('select[name=wait_time] option[value="3-7days"]')
        click_element('input[name=wait_time_satisfaction][value="1"]')
        click_element('select[name=difficulty_contacting] option[value=other]')
        # Wait for JS again
        self.wait_for_element('textarea[name=other_difficulties]',
                              match=By.CSS_SELECTOR,
                              must_be_visible=True)
        type_in_element('textarea[name=other_difficulties]',
                        'Other difficulties')

        type_in_element('textarea[name=extra_comments]', 'Other comments')

        self.browser.get_screenshot_as_file("pre_submit.png")

        # Submit
        self.wait_for_element('button.form-btn-submit',
                              match=By.CSS_SELECTOR).click()

        # Wait
        try:
            self.wait_for_element('a[href="#/feedback/list"]',
                                  match=By.CSS_SELECTOR)
        except WebDriverException as e:
            self.browser.get_screenshot_as_file("screenshot.png")
            print(
                "ERROR waiting for feedback confirmation page, ignoring for now."
            )
            print("Screenshot in screenshot.png")
            print(e)

        self.browser.get_screenshot_as_file("post_submit.png")

        # Did we get a Feedback object?
        if not Feedback.objects.exists():
            self.fail(
                "SOME error occurred, see screenshots pre_submit.png and post_submit.png"
            )

        # Find the submitted form
        self.assertEqual(1, Feedback.objects.all().count())
        feedback = Feedback.objects.first()
        self.assertEqual('John Doe', feedback.name)
        self.assertEqual('12-345678', feedback.phone_number)
        self.assertEqual(iraqi_nationality, feedback.nationality)
        self.assertEqual(area, feedback.area_of_residence)
        self.assertEqual(service, feedback.service)
        self.assertEqual(True, feedback.delivered)
        self.assertEqual(4, feedback.quality)
        self.assertFalse(feedback.non_delivery_explained)
        self.assertEqual('3-7days', feedback.wait_time)
        self.assertEqual(1, feedback.wait_time_satisfaction)
        self.assertEqual('other', feedback.difficulty_contacting)
        self.assertEqual('Other difficulties', feedback.other_difficulties)
        self.assertEqual(2, feedback.staff_satisfaction)
        self.assertEqual('Other comments', feedback.extra_comments)
        self.assertEqual(True, feedback.anonymous)
Ejemplo n.º 47
0
 def test_email_provider_about_approval(self):
     service = ServiceFactory()
     with patch('services.models.email_provider_about_service_approval_task') as mock_task:
         service.email_provider_about_approval()
     mock_task.delay.assert_called_with(service.pk)