def test_provider_change_nonexistent_criterion(self): provider = ProviderFactory(user=self.user) service = ServiceFactory(provider=provider, status=Service.STATUS_CURRENT) criterion1 = SelectionCriterionFactory(service=service) book = get_export_workbook([provider], None, [criterion1]) crit_id = criterion1.id criterion1.delete() rsp = self.import_book(book) self.assertContains(rsp, "Row 2: id: No selection criterion with id = %s" % crit_id, status_code=BAD_REQUEST, msg_prefix=rsp.content.decode('utf-8'))
def test_create_issue_kwargs(self, mock_JIRA): self.test_service.sunday_open = datetime.time(11, 10) self.test_service.sunday_close = datetime.time(12, 10) self.test_service.saturday_open = datetime.time(17, 18) self.test_service.saturday_close = datetime.time(19, 18) self.test_service.save() self.test_service.provider.focal_point_phone_number = '12-345678' self.test_service.provider.number_of_monthly_beneficiaries = '31415' self.test_service.provider.save() SelectionCriterionFactory( service=self.test_service, text_en="Must be 18", text_ar="Must have passport", text_fr="Must have transportation" ) SelectionCriterionFactory( service=self.test_service, text_en="Must be 21", text_ar="Must have shoes", text_fr="Must be citizen" ) self.setup_issue_key(mock_JIRA) self.jira_record = JiraUpdateRecord.objects.get(pk=self.jira_record.pk) self.jira_record.do_jira_work() call_args, call_kwargs = mock_JIRA.return_value.create_issue.call_args # Expecting: summary, project, issuetype, description, duedate self.assertTrue('summary' in call_kwargs) self.assertTrue('new service' in call_kwargs['summary'].lower()) self.assertTrue(self.test_service.provider.name_en in call_kwargs['summary']) self.assertTrue('project' in call_kwargs) self.assertEqual({'key': settings.JIRA_SERVICES_PROJECT_KEY}, call_kwargs['project']) self.assertTrue('issuetype' in call_kwargs) self.assertEqual({'name': 'Task'}, call_kwargs['issuetype']) self.assertTrue('description' in call_kwargs) admin_url = absolute_url(self.test_service.get_admin_edit_url()) self.assertTrue( admin_url in call_kwargs['description'], msg='%s not found in %s' % (admin_url, call_kwargs['description'])) self.assertIn('11:10', call_kwargs['description']) self.assertIn('17:18', call_kwargs['description']) self.assertIn('Must be 18', call_kwargs['description']) self.assertIn('Must have shoes', call_kwargs['description']) self.assertIn('12-345678', call_kwargs['description']) self.assertIn('31415', call_kwargs['description']) self.assertTrue('duedate' in call_kwargs) expected_duedate = datetime.date.today() + datetime.timedelta(days=settings.JIRA_DUEIN_DAYS) self.assertEqual(str(expected_duedate), call_kwargs['duedate']) # We've tested 5, ensure that is all that were passed self.assertEqual(5, len(call_kwargs)) self.assertEqual((), call_args)
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 criterion2.text_en = criterion2.text_ar = criterion2.text_fr = '' 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'))
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'))
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())
def test_provider_bad_criterion_id(self): provider = ProviderFactory(user=self.user) service = ServiceFactory(provider=provider, status=Service.STATUS_CURRENT) criterion1 = SelectionCriterionFactory.build(service=service) criterion1.id = 'abc' book = get_export_workbook([provider], None, [criterion1]) rsp = self.import_book(book) self.assertContains(rsp, "Row 2: id: %s is not a valid ID" % criterion1.id, status_code=BAD_REQUEST, msg_prefix=rsp.content.decode('utf-8'))
def test_provider_add_criterion_bad_service(self): provider = ProviderFactory(user=self.user) criterion1 = SelectionCriterionFactory.build() service = criterion1.service book = get_export_workbook([provider], None, [criterion1]) rsp = self.import_book(book) self.assertContains(rsp, "Row 2: service__id: Selection criterion refers to service with ID " "or name '%s' that is not in the 2nd sheet" % service.name_en, status_code=BAD_REQUEST, msg_prefix=rsp.content.decode('utf-8'))
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)
def test_provider_add_criterion_bad_service(self): provider = ProviderFactory(user=self.user) criterion1 = SelectionCriterionFactory.build() service = criterion1.service book = get_export_workbook([provider], None, [criterion1]) rsp = self.import_book(book) self.assertContains( rsp, "Row 2: service__id: Selection criterion refers to service with ID " "or name '%s' that is not in the 2nd sheet" % service.name_en, status_code=BAD_REQUEST, msg_prefix=rsp.content.decode('utf-8'))
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())
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'))
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'))
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())
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)
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)
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))