def test_renew_licence(self): """ Testing that a user can renew a licence and restart the application process based on the previous licence's application data """ application = helpers.create_and_lodge_application(user=self.customer) licence = helpers.issue_licence(application, licence_data = { 'end_date': date.today() + relativedelta(days=30), 'is_renewable': True }) self.client.login(self.customer.email) response = self.client.get(reverse('wl_applications:renew_licence', args=(licence.pk,)), follow=True) # check that client will be redirected to the enter details page self.assertRedirects(response, reverse('wl_applications:enter_details'), status_code=302, target_status_code=200) self.assertNotEquals(application.id, response.context['application'].id) self.assertEquals(response.context['application'].application_type, 'renewal') # check that the data contained in the context is the same as the application data self.assertEquals(application.data, response.context['application'].data) helpers.delete_application_session(self.client) # check that a licence that isn't due to expire within 30 days is not cannot be renewed application = helpers.create_and_lodge_application(user=self.customer) licence = helpers.issue_licence(application, licence_data = { 'end_date': date.today() + relativedelta(days=31), 'is_renewable': True }) response = self.client.get(reverse('wl_applications:renew_licence', args=(licence.pk,)), follow=True) self.assertEqual(response.status_code, 403) # check that a licence that isn't renewable cannot be renewed application = helpers.create_and_lodge_application(user=self.customer) licence = helpers.issue_licence(application, licence_data = { 'end_date': date.today() + relativedelta(days=30), 'is_renewable': False }) response = self.client.get(reverse('wl_applications:renew_licence', args=(licence.pk,)), follow=True) self.assertEqual(response.status_code, 403)
def setUp(self): self.client = main_helpers.SocialClient() self.user = main_helpers.get_or_create_default_customer() self.officer = main_helpers.get_or_create_default_officer() self.assessor = main_helpers.get_or_create_default_assessor() self.lodged_application = app_helpers.create_and_lodge_application( self.user, **{'data': { 'title': 'Lodged Application' }}) self.issued_application = app_helpers.create_and_lodge_application( self.user, **{'data': { 'title': 'Issued Application' }}) self.licence = app_helpers.issue_licence(self.issued_application, self.officer) self.assertIsNotNone(self.licence) self.issue_urls_get = [ { 'url': reverse('wl_applications:issue_licence', args=[self.lodged_application.pk]), 'data': None }, { 'url': reverse('wl_applications:reissue_licence', args=[self.licence.pk]), 'data': None }, { 'url': reverse('wl_applications:preview_licence', args=[self.issued_application.pk]), 'data': app_helpers.get_minimum_data_for_issuing_licence() }, ] self.issue_urls_post = [ { 'url': reverse('wl_applications:issue_licence', args=[self.lodged_application.pk]), 'data': app_helpers.get_minimum_data_for_issuing_licence() }, ]
def test_issued_declined_licences_cannot_be_assessed(self): """ Test that if a licence has been issued or application declined, assessments can no longer be done. @see https://kanboard.dpaw.wa.gov.au/?controller=TaskViewController&action=show&task_id=2743&project_id=24 """ # create application to issue application = create_and_lodge_application(self.user) # send out assessment assessment = get_or_create_assessment(application) self.assertEquals(assessment.status, 'awaiting_assessment') self.client.login(self.officer.email) # issue licence url = reverse('wl_applications:issue_licence', args=[application.pk]) today = datetime.date.today() tomorrow = today + datetime.timedelta(days=1) data = { 'regions': [G(Region).pk], 'return_frequency': -1, 'issue_date': str(today), 'start_date': str(today), 'end_date': str(tomorrow) } resp = self.client.post(url, data=data, follow=True) self.assertEquals(200, resp.status_code) application.refresh_from_db() self.assertEquals(application.processing_status, 'issued') assessment.refresh_from_db() self.assertEquals(assessment.status, 'assessment_expired') # create application to decline application = create_and_lodge_application(self.user) # send out assessment assessment = get_or_create_assessment(application) self.assertEquals(assessment.status, 'awaiting_assessment') # decline licence resp = self.client.post(reverse('wl_applications:process', args=[application.pk]), data={'decline': True}, follow=True) self.assertEquals(200, resp.status_code) assessment.refresh_from_db() self.assertEquals(assessment.status, 'assessment_expired')
def test_default_licence_period(self): """ Test that a licence default period correctly calculates the end date of a licence. """ default_period = 183 self.client.login(self.officer.email) licence_type = main_helpers.get_or_create_licence_type('test') licence_type.default_period = default_period licence_type.save() application = app_helpers.create_and_lodge_application( self.user, licence_type=licence_type) response = self.client.get( reverse('wl_applications:issue_licence', args=[application.pk])) todays_date_string = ( datetime.date.today() + relativedelta(days=default_period)).strftime(DATE_FORMAT) self.assertIn( todays_date_string, response.context['issue_licence_form']['end_date'].initial) # test that end date not set when default_period is not set licence_type.default_period = None licence_type.save() response = self.client.get( reverse('wl_applications:issue_licence', args=[application.pk])) self.assertIsNone( response.context['issue_licence_form']['end_date'].initial)
def test_default_licence_period(self): """ Test that a licence default period correctly calculates the end date of a licence. """ default_period = 183 self.client.login(self.officer.email) licence_type = main_helpers.get_or_create_licence_type('test') licence_type.default_period = default_period licence_type.save() application = app_helpers.create_and_lodge_application(self.user, licence_type=licence_type) response = self.client.get(reverse('wl_applications:issue_licence', args=[application.pk])) todays_date_string = (datetime.date.today() + relativedelta(days=default_period)).strftime(DATE_FORMAT) self.assertIn(todays_date_string, response.context['issue_licence_form']['end_date'].initial) # test that end date not set when default_period is not set licence_type.default_period = None licence_type.save() response = self.client.get(reverse('wl_applications:issue_licence', args=[application.pk])) self.assertIsNone(response.context['issue_licence_form']['end_date'].initial)
def test_issue_licence(self): """ Test that a licence can be issued """ # create application to issue application = app_helpers.create_and_lodge_application(self.user) self.client.login(self.officer.email) # issue licence url = reverse('wl_applications:issue_licence', args=[application.pk]) today = datetime.date.today() tomorrow = today + datetime.timedelta(days=1) data = { 'regions': [G(Region).pk], 'return_frequency': -1, 'issue_date': str(today), 'start_date': str(today), 'end_date': str(tomorrow) } resp = self.client.post(url, data=data, follow=True) self.assertEquals(200, resp.status_code) application.refresh_from_db() self.assertEquals(application.processing_status, 'issued') self.assertIsNotNone(application.licence) self.assertTrue(application.licence.is_issued)
def test_character_check(self): """ Test that the character check shows for questionable characters """ self.user.character_flagged = True self.user.save() application = create_and_lodge_application(self.user) self.assertEquals(application.character_check_status, 'not_checked') self.client.login(self.officer.email) response = self.client.get( reverse('wl_applications:process', args=(application.pk, ))) self.assertContains(response, '<span class="glyphicon glyphicon-user"></span>') post_data = {'applicationID': application.id, 'status': 'accepted'} response = self.client.post( reverse('wl_applications:set_character_check_status'), post_data) self.assertEquals(response.status_code, 200) application.refresh_from_db() self.assertEquals(application.character_check_status, 'accepted')
def test_declined_applications_status(self): """ Test that if an application has been declined, the officer and customer will both have a declined status @see https://kanboard.dpaw.wa.gov.au/?controller=TaskViewController&action=show&task_id=2741&project_id=24 """ # create application to decline application = create_and_lodge_application(self.user) self.client.login(self.officer.email) # decline licence resp = self.client.post(reverse('wl_applications:process', args=[application.pk]), data={'decline': True, 'reason': 'N/A'}, follow=True) self.assertEquals(200, resp.status_code) application.refresh_from_db() self.assertEquals(application.customer_status, 'declined') self.assertEquals(application.processing_status, 'declined') # Test that the reason is stored details = ApplicationDeclinedDetails.objects.filter(application=application).first() self.assertIsNotNone(details) self.assertEqual(application, details.application) self.assertEqual(self.officer, details.officer) self.assertEquals('N/A', details.reason)
def test_character_check(self): """ Test that the character check shows for questionable characters """ self.user.character_flagged = True self.user.save() application = create_and_lodge_application(self.user) self.assertEquals(application.character_check_status, 'not_checked') self.client.login(self.officer.email) response = self.client.get(reverse('wl_applications:process', args=(application.pk,))) self.assertContains(response, '<span class="glyphicon glyphicon-user"></span>') post_data = { 'applicationID': application.id, 'status': 'accepted' } response = self.client.post(reverse('wl_applications:set_character_check_status'), post_data) self.assertEquals(response.status_code, 200) application.refresh_from_db() self.assertEquals(application.character_check_status, 'accepted')
def test_declined_applications_status(self): """ Test that if an application has been declined, the officer and customer will both have a declined status @see https://kanboard.dpaw.wa.gov.au/?controller=TaskViewController&action=show&task_id=2741&project_id=24 """ # create application to decline application = create_and_lodge_application(self.user) self.client.login(self.officer.email) # decline licence resp = self.client.post(reverse('wl_applications:process', args=[application.pk]), data={ 'decline': True, 'reason': 'N/A' }, follow=True) self.assertEquals(200, resp.status_code) application.refresh_from_db() self.assertEquals(application.customer_status, 'declined') self.assertEquals(application.processing_status, 'declined') # Test that the reason is stored details = ApplicationDeclinedDetails.objects.filter( application=application).first() self.assertIsNotNone(details) self.assertEqual(application, details.application) self.assertEqual(self.officer, details.officer) self.assertEquals('N/A', details.reason)
def test_submitted_draft_cannot_be_deleted(self): """ Use case: Applicant lodge an application. Officer send it back to him with amendments requested Applicant reopen it and save it as a draft At this stage the user should not be able to delete it because it has already been lodged """ # lodge application application = helpers.create_and_lodge_application(self.applicant) # application should not be discardable self.assertFalse(application.is_discardable) # and not deletable self.assertFalse(application.is_deletable) # officer request amendment url = reverse('wl_applications:amendment_request') self.client.login(self.officer.email) resp = self.client.post(url, data={ 'application': application.pk, 'officer': self.officer.pk, 'reason': 'missing_information' }) self.assertEquals(resp.status_code, 200) application.refresh_from_db() self.client.logout() self.client.login(self.applicant.email) url = reverse('wl_applications:edit_application', args=[application.pk]) self.client.get(url, follow=True) # save as draft data = { 'draft': 'draft', 'data': application.data } url = reverse('wl_applications:enter_details') resp = self.client.post(url, data, follow=True) self.assertEqual(resp.status_code, 200) application.refresh_from_db() self.assertEqual(application.customer_status, 'draft') # application should now be discardable self.assertTrue(application.is_discardable) # and not deletable self.assertFalse(application.is_deletable) # actual discard url = reverse('wl_applications:discard_application', args=[application.pk]) resp = self.client.post(url, follow=True) # application should not be deleted application = Application.objects.filter(pk=application.pk).first() self.assertIsNotNone(application) # but in a discarded state self.assertEqual(application.processing_status, 'discarded') self.assertEqual(application.customer_status, 'discarded') # there should be a message self.assertTrue(has_response_messages(resp)) self.assertFalse(has_response_error_messages(resp))
def setUp(self): self.customer = get_or_create_default_customer( include_default_profile=True) self.officer = get_or_create_default_officer() self.assessor = get_or_create_default_assessor() self.not_allowed_customer = create_random_customer() self.assertNotEqual(self.not_allowed_customer, self.customer) self.client = SocialClient() self.application = create_and_lodge_application(self.customer)
def test_pushed_back_application_discarded_not_deleted(self): # lodge application application = helpers.create_and_lodge_application(self.applicant) self.assertFalse(application.is_discardable) # officer request amendment url = reverse('wl_applications:amendment_request') self.client.login(self.officer.email) resp = self.client.post(url, data={ 'application': application.pk, 'officer': self.officer.pk, 'reason': 'missing_information' }) self.assertEquals(resp.status_code, 200) application.refresh_from_db() # application should now be discardable self.assertTrue(application.is_discardable) # but not deletable self.assertFalse(application.is_deletable) # discard self.client.logout() clear_mailbox() self.client.login(self.applicant.email) self.assertTrue(is_client_authenticated(self.client)) url = reverse('wl_applications:discard_application', args=[application.pk]) # the get should not discard but return a confirm page previous_processing_status = application.processing_status previous_customer_status = application.customer_status resp = self.client.get(url) self.assertEquals(resp.status_code, 200) # test that there's a cancel_url in the context of the response and an action_url that is set to the proper url self.assertTrue('cancel_url' in resp.context) self.assertEqual(resp.context['cancel_url'], reverse('wl_dashboard:home')) self.assertTrue('action_url' in resp.context) self.assertEquals(resp.context['action_url'], url) application.refresh_from_db() # status should be unchanged self.assertNotEqual(application.processing_status, 'discarded') self.assertNotEqual(application.customer_status, 'discarded') self.assertEqual(application.processing_status, previous_processing_status) self.assertEqual(application.customer_status, previous_customer_status) # actual discard resp = self.client.post(url, data=None, follow=True) self.assertEquals(resp.status_code, 200) application.refresh_from_db() self.assertEqual(application.processing_status, 'discarded') self.assertEqual(application.customer_status, 'discarded') # there should be a message self.assertTrue(has_response_messages(resp)) self.assertFalse(has_response_error_messages(resp))
def setUp(self): self.client = main_helpers.SocialClient() self.user = main_helpers.get_or_create_default_customer() self.officer = main_helpers.get_or_create_default_officer() self.assessor = main_helpers.get_or_create_default_assessor() self.lodged_application = app_helpers.create_and_lodge_application(self.user, **{ 'data': { 'title': 'Lodged Application' } }) self.issued_application = app_helpers.create_and_lodge_application(self.user, **{ 'data': { 'title': 'Issued Application' } }) self.licence = app_helpers.issue_licence(self.issued_application, self.officer) self.assertIsNotNone(self.licence) self.issue_urls_get = [ { 'url': reverse('wl_applications:issue_licence', args=[self.lodged_application.pk]), 'data': None }, { 'url': reverse('wl_applications:reissue_licence', args=[self.licence.pk]), 'data': None }, { 'url': reverse('wl_applications:preview_licence', args=[self.issued_application.pk]), 'data': app_helpers.get_minimum_data_for_issuing_licence() }, ] self.issue_urls_post = [ { 'url': reverse('wl_applications:issue_licence', args=[self.lodged_application.pk]), 'data': app_helpers.get_minimum_data_for_issuing_licence() }, ]
def _issue_licence(self, licence_data, **kwargs): application = app_helpers.create_and_lodge_application( self.customer, **{ 'applicant': kwargs.get('applicant', self.customer), 'licence_type': kwargs.get('licence_type', self.licence_type) }) self.assertIsNotNone(application) self.assertEqual(application.applicant, self.customer) self.assertIsNone(application.proxy_applicant) licence = app_helpers.issue_licence(application, kwargs.get('issuer', self.officer), licence_data=licence_data) self.assertEqual(licence.holder, self.customer) self.assertIsNotNone(licence) return licence
def _issue_licence(self, licence_data, **kwargs): application = app_helpers.create_and_lodge_application(self.customer, **{ 'applicant': kwargs.get('applicant', self.customer), 'licence_type': kwargs.get('licence_type', self.licence_type) }) self.assertIsNotNone(application) self.assertEqual(application.applicant, self.customer) self.assertIsNone(application.proxy_applicant) licence = app_helpers.issue_licence( application, kwargs.get('issuer', self.officer), licence_data=licence_data ) self.assertEqual(licence.holder, self.customer) self.assertIsNotNone(licence) return licence
def test_issued_status_after_entering_condition(self): """ Test that if an application has been issued, entering condition leave the status as issued @see https://kanboard.dpaw.wa.gov.au/?controller=TaskViewController&action=show&task_id=2736&project_id=24 """ application = create_and_lodge_application(self.user) # set some conditions url = reverse('wl_applications:enter_conditions', args=[application.pk]) condition = get_or_create_condition('0001', {"text": "For unit test"}) data = { 'conditionID': [condition.pk] } self.client.login(self.officer.email) self.assertTrue(is_client_authenticated(self.client)) resp = self.client.post(url, data=data, follow=True) self.assertEquals(200, resp.status_code) application.refresh_from_db() self.assertEquals(application.processing_status, 'ready_to_issue') # issue licence url = reverse('wl_applications:issue_licence', args=[application.pk]) today = datetime.date.today() tomorrow = today + datetime.timedelta(days=1) data = { 'regions': [G(Region).pk], 'return_frequency': -1, 'issue_date': str(today), 'start_date': str(today), 'end_date': str(tomorrow) } resp = self.client.post(url, data=data, follow=True) self.assertEquals(200, resp.status_code) application.refresh_from_db() self.assertEquals(application.processing_status, 'issued') # now repost conditions url = reverse('wl_applications:enter_conditions', args=[application.pk]) condition = get_or_create_condition('0001', {"text": "For unit test"}) data = { 'conditionID': [condition.pk] } resp = self.client.post(url, data=data, follow=True) self.assertEquals(200, resp.status_code) application.refresh_from_db() # status should not be 'ready_to_issue' but 'issued' expected_status = 'issued' self.assertEquals(application.processing_status, expected_status)
def setUp(self): self.client = SocialClient() self.user = get_or_create_default_customer() self.officer = get_or_create_default_officer() self.application = app_helpers.create_and_lodge_application( self.user, **{'data': { 'title': 'My Application' }}) self.assessment = app_helpers.get_or_create_assessment( self.application) self.condition = Condition.objects.first() self.assessment_condition = AssessmentCondition.objects.create( assessment=self.assessment, condition=self.condition, order=1) self.urls_get = [ reverse('wl_applications:enter_conditions', args=[self.application.pk]), reverse('wl_applications:search_conditions') ] self.urls_post = [ { 'url': reverse('wl_applications:create_condition', args=[self.application.pk]), 'data': { 'code': '123488374', 'text': 'condition text' } }, { 'url': reverse('wl_applications:set_assessment_condition_state'), 'data': { 'assessmentConditionID': self.assessment_condition.pk, 'acceptanceStatus': 'accepted', } }, { 'url': reverse('wl_applications:enter_conditions', args=[self.application.pk]), 'data': { 'conditionID': [self.condition.pk], } }, ]
def test_id_update(self): """ Test that when an ID update is required and the users update their ID the customer and id status are correctly updated """ application = create_and_lodge_application(self.user) self.client.login(self.officer.email) self.assertTrue(is_client_authenticated(self.client)) clear_mailbox() data = { 'officer': self.officer.pk, 'application': application.pk, 'reason': IDRequest.REASON_CHOICES[0][0], 'text': 'you to upload an ID.' } url = reverse('wl_applications:id_request') self.assertFalse(is_email()) response = self.client.post(url, data) self.assertEqual(200, response.status_code) resp_data = json.loads(response.content.decode('utf8')) self.assertIn('id_check_status', resp_data) self.assertIn('processing_status', resp_data) application.refresh_from_db() self.assertEqual('id_required', application.customer_status) self.assertEqual('awaiting_update', application.id_check_status) self.assertEqual('awaiting_applicant_response', application.processing_status) self.assertTrue(is_email()) email = get_email() self.assertIn(application.applicant_profile.email, email.to) self.assertEqual(ApplicationIDUpdateRequestedEmail.subject, email.subject) # now user upload ID self.client.logout() self.assertIsNone(self.user.identification) self.client.login(self.user.email) self.assertTrue(is_client_authenticated(self.client)) self.client.get(reverse('wl_main:identification')) upload_id(self.user) self.user.refresh_from_db() self.assertIsNotNone(self.user.identification) application.refresh_from_db() self.assertEqual('updated', application.id_check_status) self.assertEqual('under_review', application.customer_status) self.assertEqual('ready_for_action', application.processing_status)
def setUp(self): self.client = SocialClient() self.user = get_or_create_default_customer() self.officer = get_or_create_default_officer() self.application = app_helpers.create_and_lodge_application(self.user, **{ 'data': { 'title': 'My Application' } }) self.assessor_group = G(AssessorGroup, name='District7', email='*****@*****.**') self.assessor_1 = G(EmailUser, email='*****@*****.**', dob='1967-04-04') add_to_group(self.assessor_1, 'Assessors') add_to_group(self.assessor_1, self.assessor_group) self.assessor_2 = G(EmailUser, email='*****@*****.**', dob='1968-04-04') add_to_group(self.assessor_2, 'Assessors') add_to_group(self.assessor_2, self.assessor_group)
def setUp(self): self.client = SocialClient() self.user = get_or_create_default_customer() self.officer = get_or_create_default_officer() self.application = app_helpers.create_and_lodge_application(self.user, **{ 'data': { 'title': 'My Application' } }) self.assessment = app_helpers.get_or_create_assessment(self.application) self.condition = Condition.objects.first() self.assessment_condition = AssessmentCondition.objects.create(assessment=self.assessment, condition=self.condition, order=1) self.urls_get = [ reverse('wl_applications:enter_conditions', args=[self.application.pk]), reverse('wl_applications:search_conditions') ] self.urls_post = [ { 'url': reverse('wl_applications:create_condition', args=[self.application.pk]), 'data': { 'code': '123488374', 'text': 'condition text' } }, { 'url': reverse('wl_applications:set_assessment_condition_state'), 'data': { 'assessmentConditionID': self.assessment_condition.pk, 'acceptanceStatus': 'accepted', } }, { 'url': reverse('wl_applications:enter_conditions', args=[self.application.pk]), 'data': { 'conditionID': [self.condition.pk], } }, ]
def test_cannot_discard(self): """ Test that an application cannot be discarded if it hasn't been pushed back to the applicant. Formally its processing status must be in the list of Application.CUSTOMER_DISCARDABLE_STATE :return: """ # lodge application application = helpers.create_and_lodge_application(self.applicant) self.assertFalse(application.is_discardable) # try to discard with get or post previous_processing_status = application.processing_status previous_customer_status = application.customer_status url = reverse('wl_applications:discard_application', args=[application.pk]) self.client.login(self.applicant.email) self.assertTrue(is_client_authenticated(self.client)) resp = self.client.get(url, follow=True) application.refresh_from_db() # status should be unchanged self.assertNotEqual(application.processing_status, 'discarded') self.assertNotEqual(application.customer_status, 'discarded') self.assertEqual(application.processing_status, previous_processing_status) self.assertEqual(application.customer_status, previous_customer_status) # the response should have an error message self.assertTrue(has_response_error_messages(resp)) # same with post method resp = self.client.post(url, follow=True) application.refresh_from_db() # status should be unchanged self.assertNotEqual(application.processing_status, 'discarded') self.assertNotEqual(application.customer_status, 'discarded') self.assertEqual(application.processing_status, previous_processing_status) self.assertEqual(application.customer_status, previous_customer_status) # the response should have an error message self.assertTrue(has_response_error_messages(resp))
def test_amend_licence(self): """ Testing that a user can amend a licence and restart the application process based on the previous licence's application data """ application = helpers.create_and_lodge_application(user=self.customer) licence = helpers.issue_licence(application) self.client.login(self.customer.email) response = self.client.get(reverse('wl_applications:amend_licence', args=(licence.pk,)), follow=True) # check that client will be redirected to the enter details page self.assertRedirects(response, reverse('wl_applications:enter_details'), status_code=302, target_status_code=200) self.assertNotEquals(application.id, response.context['application'].id) self.assertEquals(response.context['application'].application_type, 'amendment') # check that the data contained in the context is the same as the application data self.assertEquals(application.data, response.context['application'].data)
def setUp(self): self.client = SocialClient() self.user = get_or_create_default_customer() self.officer = get_or_create_default_officer() self.application = app_helpers.create_and_lodge_application( self.user, **{'data': { 'title': 'My Application' }}) self.assessor_group = G(AssessorGroup, name='District7', email='*****@*****.**') self.assessor_1 = G(EmailUser, email='*****@*****.**', dob='1967-04-04') add_to_group(self.assessor_1, 'Assessors') add_to_group(self.assessor_1, self.assessor_group) self.assessor_2 = G(EmailUser, email='*****@*****.**', dob='1968-04-04') add_to_group(self.assessor_2, 'Assessors') add_to_group(self.assessor_2, self.assessor_group)
def test_application_amendment(self): """ Test that when an amendment is required, the user receives an email and can amend their application. When the user relodged, the officer can see the amendment and set the review status accordingly. """ application = create_and_lodge_application(self.user) self.assertFalse(application.can_user_edit) self.client.login(self.officer.email) post_data = { 'officer': self.officer.pk, 'application': application.pk, 'reason': AmendmentRequest.REASON_CHOICES[0][0], 'text': 'Application needs more data' } response = self.client.post( reverse('wl_applications:amendment_request'), post_data) self.assertEqual(200, response.status_code) resp_data = json.loads(response.content.decode('utf8')) application.refresh_from_db() self.assertIn('review_status', resp_data) self.assertEquals(resp_data['review_status'], utils.REVIEW_STATUSES[application.review_status]) self.assertIn('processing_status', resp_data) self.assertEquals( resp_data['processing_status'], utils.PROCESSING_STATUSES[application.processing_status]) self.assertEqual(application.customer_status, 'amendment_required') self.assertEqual(application.processing_status, 'awaiting_applicant_response') self.assertEqual(application.review_status, 'awaiting_amendments') amendment_request = AmendmentRequest.objects.filter( application=application).first() self.assertIsNotNone(amendment_request) self.assertEquals(amendment_request.status, 'requested') self.assertTrue(is_email()) email = get_email() self.assertIn(application.applicant_profile.email, email.to) self.assertEqual(ApplicationAmendmentRequestedEmail.subject, email.subject) # user logs in self.client.logout() self.client.login(self.user.email) self.assertTrue(application.can_user_edit) response = self.client.get(reverse('wl_applications:edit_application', args=(application.pk, )), follow=True) # check that client will be redirected to the enter details page self.assertRedirects(response, reverse('wl_applications:enter_details'), status_code=302, target_status_code=200) # edit and resubmit data post_params = {'project_title-0-0': 'New Title', 'lodge': True} response = self.client.post(reverse('wl_applications:enter_details'), post_params) # check that client is redirected to preview self.assertRedirects(response, reverse('wl_applications:preview'), status_code=302, target_status_code=200, fetch_redirect_response=False) response = self.client.post(reverse('wl_applications:preview')) # FIXME: simulate full checkout process instead of skipping self.client.get(reverse('wl_applications:complete')) application.refresh_from_db() self.assertFalse(application.can_user_edit) self.assertEqual( application.data[0]['project_details'][0]['project_title'], 'New Title') self.assertEqual(application.customer_status, 'under_review') self.assertEqual(application.processing_status, 'ready_for_action') self.assertEqual(application.review_status, 'amended') amendment_request.refresh_from_db() self.assertEquals(amendment_request.status, 'amended') # officer logs in self.client.logout() self.client.login(self.officer.email) post_data = {'applicationID': application.id, 'status': 'accepted'} response = self.client.post( reverse('wl_applications:set_review_status'), post_data) self.assertEquals(response.status_code, 200) application.refresh_from_db() self.assertEquals(application.review_status, 'accepted')
def setUp(self): self.client = SocialClient() self.user = get_or_create_default_customer() self.officer = get_or_create_default_officer() self.application = create_and_lodge_application( self.user, **{'data': { 'title': 'My Application' }}) self.process_urls_get = [ reverse('wl_applications:process', args=[self.application.pk]), ] self.process_urls_post = [ { 'url': reverse('wl_applications:process', args=[self.application.pk]), 'data': { 'applicationID': self.application.pk, } }, { 'url': reverse('wl_applications:assign_officer'), 'data': { 'applicationID': self.application.pk, 'userID': self.officer.pk, } }, { 'url': reverse('wl_applications:set_id_check_status'), 'data': { 'applicationID': self.application.pk, 'status': 'accepted', } }, { 'url': reverse('wl_applications:id_request'), 'data': { 'applicationID': self.application.pk, } }, { 'url': reverse('wl_applications:set_character_check_status'), 'data': { 'applicationID': self.application.pk, 'status': 'accepted', } }, { 'url': reverse('wl_applications:set_review_status'), 'data': { 'applicationID': self.application.pk, 'status': 'accepted', } }, { 'url': reverse('wl_applications:amendment_request'), 'data': { 'applicationID': self.application.pk, } }, { 'url': reverse('wl_applications:send_for_assessment'), 'data': { 'applicationID': self.application.pk, 'assGroupID': get_or_create_default_assessor_group().pk, 'status': 'awaiting_assessment' } }, { 'url': reverse('wl_applications:remind_assessment'), 'data': { 'applicationID': self.application.pk, 'assessmentID': get_or_create_assessment(self.application).pk } }, ]
def test_multiple_application_entry_denied(self): """ Testing the if a user is in the process of entering an application and attempts to start/edit/renew/amend another application, they are redirected back to home """ entry_denied_message = ('There is currently another application in the process of being entered. Please ' + 'conclude or save this application before creating a new one. If you are seeing this ' + 'message and there is not another application being entered, you may need to '+ '<a href="{}">logout</a> and log in again.').format(reverse('accounts:logout')) self.client.login(self.customer.email) response = self.client.get(reverse('wl_applications:new_application')) self.assertRedirects(response, reverse('wl_applications:select_licence_type'), status_code=302, target_status_code=200, fetch_redirect_response=False) # attempt to start another new licence application response = self.client.get(reverse('wl_applications:new_application'), follow=True) self.assertRedirects(response, reverse('wl_dashboard:tables_customer'), status_code=302, target_status_code=200, fetch_redirect_response=False) self.assertIn('messages', response.context) self.assertEquals(len(response.context['messages']), 1) self.assertEquals([str(m.message) for m in response.context['messages']][0], entry_denied_message) application = helpers.create_application(user=self.customer) # attempt to edit an application response = self.client.get(reverse('wl_applications:edit_application', args=(application.pk, )), follow=True) self.assertRedirects(response, reverse('wl_dashboard:tables_customer'), status_code=302, target_status_code=200, fetch_redirect_response=False) self.assertIn('messages', response.context) self.assertEquals(len(response.context['messages']), 1) self.assertEquals([str(m.message) for m in response.context['messages']][0], entry_denied_message) application = helpers.create_and_lodge_application(user=self.customer) licence = helpers.issue_licence(application, licence_data = { 'end_date': date.today() + relativedelta(days=30), 'is_renewable': True }) # attempt to renew a licence response = self.client.get(reverse('wl_applications:renew_licence', args=(licence.pk, )), follow=True) self.assertRedirects(response, reverse('wl_dashboard:tables_customer'), status_code=302, target_status_code=200, fetch_redirect_response=False) self.assertIn('messages', response.context) self.assertEquals(len(response.context['messages']), 1) self.assertEquals([str(m.message) for m in response.context['messages']][0], entry_denied_message) response = self.client.get(reverse('wl_applications:amend_licence', args=(licence.pk, )), follow=True ) # attempt to amend a licence self.assertRedirects(response, reverse('wl_dashboard:tables_customer'), status_code=302, target_status_code=200, fetch_redirect_response=False) self.assertIn('messages', response.context) self.assertEquals(len(response.context['messages']), 1) self.assertEquals([str(m.message) for m in response.context['messages']][0], entry_denied_message)
def test_application_amendment(self): """ Test that when an amendment is required, the user receives an email and can amend their application. When the user relodged, the officer can see the amendment and set the review status accordingly. """ application = create_and_lodge_application(self.user) self.assertFalse(application.can_user_edit) self.client.login(self.officer.email) post_data = { 'officer': self.officer.pk, 'application': application.pk, 'reason': AmendmentRequest.REASON_CHOICES[0][0], 'text': 'Application needs more data' } response = self.client.post(reverse('wl_applications:amendment_request'), post_data) self.assertEqual(200, response.status_code) resp_data = json.loads(response.content.decode('utf8')) application.refresh_from_db() self.assertIn('review_status', resp_data) self.assertEquals(resp_data['review_status'], utils.REVIEW_STATUSES[application.review_status]) self.assertIn('processing_status', resp_data) self.assertEquals(resp_data['processing_status'], utils.PROCESSING_STATUSES[application.processing_status]) self.assertEqual(application.customer_status, 'amendment_required') self.assertEqual(application.processing_status, 'awaiting_applicant_response') self.assertEqual(application.review_status, 'awaiting_amendments') amendment_request = AmendmentRequest.objects.filter(application=application).first() self.assertIsNotNone(amendment_request) self.assertEquals(amendment_request.status, 'requested') self.assertTrue(is_email()) email = get_email() self.assertIn(application.applicant_profile.email, email.to) self.assertEqual(ApplicationAmendmentRequestedEmail.subject, email.subject) # user logs in self.client.logout() self.client.login(self.user.email) self.assertTrue(application.can_user_edit) response = self.client.get(reverse('wl_applications:edit_application', args=(application.pk,)), follow=True) # check that client will be redirected to the enter details page self.assertRedirects(response, reverse('wl_applications:enter_details'), status_code=302, target_status_code=200) # edit and resubmit data post_params = { 'project_title-0-0': 'New Title', 'lodge': True } response = self.client.post(reverse('wl_applications:enter_details'), post_params) # check that client is redirected to preview self.assertRedirects(response, reverse('wl_applications:preview'), status_code=302, target_status_code=200, fetch_redirect_response=False) response = self.client.post(reverse('wl_applications:preview')) # FIXME: simulate full checkout process instead of skipping self.client.get(reverse('wl_applications:complete')) application.refresh_from_db() self.assertFalse(application.can_user_edit) self.assertEqual(application.data[0]['project_details'][0]['project_title'], 'New Title') self.assertEqual(application.customer_status, 'under_review') self.assertEqual(application.processing_status, 'ready_for_action') self.assertEqual(application.review_status, 'amended') amendment_request.refresh_from_db() self.assertEquals(amendment_request.status, 'amended') # officer logs in self.client.logout() self.client.login(self.officer.email) post_data = { 'applicationID': application.id, 'status': 'accepted' } response = self.client.post(reverse('wl_applications:set_review_status'), post_data) self.assertEquals(response.status_code, 200) application.refresh_from_db() self.assertEquals(application.review_status, 'accepted')
def setUp(self): self.client = SocialClient() self.user = get_or_create_default_customer() self.officer = get_or_create_default_officer() self.application = create_and_lodge_application(self.user, **{ 'data': { 'title': 'My Application' } }) self.process_urls_get = [ reverse('wl_applications:process', args=[self.application.pk]), ] self.process_urls_post = [ { 'url': reverse('wl_applications:process', args=[self.application.pk]), 'data': { 'applicationID': self.application.pk, } }, { 'url': reverse('wl_applications:assign_officer'), 'data': { 'applicationID': self.application.pk, 'userID': self.officer.pk, } }, { 'url': reverse('wl_applications:set_id_check_status'), 'data': { 'applicationID': self.application.pk, 'status': 'accepted', } }, { 'url': reverse('wl_applications:id_request'), 'data': { 'applicationID': self.application.pk, } }, { 'url': reverse('wl_applications:set_character_check_status'), 'data': { 'applicationID': self.application.pk, 'status': 'accepted', } }, { 'url': reverse('wl_applications:set_review_status'), 'data': { 'applicationID': self.application.pk, 'status': 'accepted', } }, { 'url': reverse('wl_applications:amendment_request'), 'data': { 'applicationID': self.application.pk, } }, { 'url': reverse('wl_applications:send_for_assessment'), 'data': { 'applicationID': self.application.pk, 'assGroupID': get_or_create_default_assessor_group().pk, 'status': 'awaiting_assessment' } }, { 'url': reverse('wl_applications:remind_assessment'), 'data': { 'applicationID': self.application.pk, 'assessmentID': get_or_create_assessment(self.application).pk } }, ]