Пример #1
0
    def test_edit_application(self):
        """
        Testing that a user can edit an application that was either draft or requiring amendments
        """
        application = helpers.create_application(user=self.customer)
        application.customer_status = 'draft'
        application.save()
        application.refresh_from_db()

        self.client.login(self.customer.email)

        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)

        # 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 an application that's not in an editable state can't be edited
        application.customer_status = 'under_review'
        application.save()

        response = self.client.get(reverse('wl_applications:edit_application', args=(application.pk,)))

        self.assertEqual(response.status_code, 403)
Пример #2
0
    def test_user_access_lodged(self):
        """
        Once the application if lodged the user should not be able to edit it
        """
        customer1 = create_random_customer()
        self.client.login(customer1)

        self.client.get(reverse('wl_applications:new_application'))
        self.client.get(reverse('wl_applications:select_licence_type', args=(1,)))

        application = Application.objects.first()
        self.assertIsNotNone(application)
        self.assertIsNotNone(application.applicant)

        # check that the state of the application is temp
        self.assertEqual(application.processing_status, 'temp')

        response = self.client.post(reverse('wl_applications:preview'))

        # check that client is redirected to checkout
        self.assertRedirects(response, reverse('wl_payments:checkout_application', args=(application.pk,)),
                             status_code=302, target_status_code=200, fetch_redirect_response=False)

        # FIXME: simulate full checkout process instead of skipping
        self.client.get(reverse('wl_applications:complete'))

        application.refresh_from_db()

        # check that the state of the application is new/underreview
        self.assertEqual(application.processing_status, 'new')
        self.assertEqual('under_review', application.customer_status)

        response = self.client.get(reverse('wl_applications:edit_application', args=[application.pk]), follow=True)
        self.assertEqual(403, response.status_code)
Пример #3
0
    def test_preview_lodge(self):
        """
        Testing that a user can preview the details of an application form then lodge the application
        """
        self.client.login(self.customer.email)

        self.client.get(reverse('wl_applications:new_application'))
        self.client.get(reverse('wl_applications:select_licence_type', args=(self.licence_type.pk,)))

        application = Application.objects.first()
        self.assertIsNotNone(application.applicant)

        # check that the state of the application is temp
        self.assertEqual(application.processing_status, 'temp')

        response = self.client.post(reverse('wl_applications:preview'))

        # check that client is redirected to checkout
        self.assertRedirects(response, reverse('wl_payments:checkout_application', args=(application.pk,)),
                             status_code=302, target_status_code=200, fetch_redirect_response=False)

        # FIXME: simulate full checkout process instead of skipping
        self.client.get(reverse('wl_applications:complete'))

        application.refresh_from_db()

        # check that the state of the application is new
        self.assertEqual(application.processing_status, 'new')
Пример #4
0
    def test_user_not_logged_is_redirected_to_login(self):
        """
        A user not logged in should be redirected to the login page and not see a 403
        """
        customer1 = create_random_customer()
        self.client.login(customer1)

        self.client.get(reverse('wl_applications:new_application'))
        self.client.get(reverse('wl_applications:select_licence_type', args=(1,)))

        application = Application.objects.first()
        self.assertIsNotNone(application)

        # check that the state of the application is temp
        self.assertEqual(application.processing_status, 'temp')

        response = self.client.post(reverse('wl_applications:preview'))

        # check that client is redirected to checkout
        self.assertRedirects(response, reverse('wl_payments:checkout_application', args=(application.pk,)),
                             status_code=302, target_status_code=200, fetch_redirect_response=False)

        application.refresh_from_db()

        # check that the state of the application is new/underreview
        self.assertEqual(application.processing_status, 'new')
        self.assertEqual('under_review', application.customer_status)

        # logout
        self.client.logout()

        response = self.client.get(reverse('wl_applications:edit_application', args=[application.pk]), follow=True)
        self.assertEqual(200, response.status_code)
        self.assertTrue(is_login_page(response))
Пример #5
0
    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))
Пример #6
0
    def test_not_submitted_draft_are_deleted(self):
        """
        This is the happy path and the only use case where the application can be deleted.
        User create application, save as draft and delete it
        """
        self.client.login(self.applicant.email)
        application = helpers.create_application(self.applicant)
        self.assertEquals(application.customer_status, 'temp')
        self.assertFalse(application.is_discardable)

        # save application as a draft
        helpers.set_application_session(self.client, application)
        pk = self.client.session['application_id']
        self.assertEqual(application.pk, pk)
        url = reverse('wl_applications:enter_details')
        data = {
            'draft': 'draft'
        }
        resp = self.client.post(url, data=data, follow=True)
        self.assertEqual(resp.status_code, 200)
        application.refresh_from_db()
        self.assertEquals(application.customer_status, 'draft')

        # application should now be discardable
        self.assertTrue(application.is_discardable)
        # and deletable
        self.assertTrue(application.is_deletable)

        # discard
        url = reverse('wl_applications:discard_application', args=[application.pk])
        # the get should not delete but return a confirm page
        previous_processing_status = application.processing_status
        previous_customer_status = application.customer_status
        resp = self.client.get(url, follow=True)
        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 should not be deleted
        application = Application.objects.filter(pk=application.pk).first()
        self.assertIsNotNone(application)
        # status should be unchanged
        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 should now be deleted
        application = Application.objects.filter(pk=application.pk).first()
        self.assertIsNone(application)
Пример #7
0
    def test_enter_details_draft_continue(self):
        """
        Testing that a user can enter the details of an application form and save as a draft
        and continue editing
        """
        self.client.login(self.customer.email)

        self.client.get(reverse('wl_applications:new_application'))
        self.client.get(reverse('wl_applications:select_licence_type', args=(self.licence_type.pk,)))

        application = Application.objects.first()

        # check that the state of the application is temp
        self.assertEqual(application.processing_status, 'temp')

        # check that client can access the enter details page
        response = self.client.get(reverse('wl_applications:enter_details'))
        self.assertEqual(200, response.status_code)

        post_params = {
            'project_title-0-0': 'Test Title',
            'draft_continue': True
        }

        response = self.client.post(reverse('wl_applications:enter_details'), post_params)

        # check that client is redirected back to enter details page
        self.assertRedirects(response, reverse('wl_applications:enter_details'),
                             status_code=302, target_status_code=200, fetch_redirect_response=False)

        application.refresh_from_db()

        # check that the state of the application is draft
        self.assertEqual(application.processing_status, 'draft')

        # check that the state of the application is draft
        self.assertEqual(application.data[0]['project_details'][0]['project_title'], 'Test Title')
Пример #8
0
    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))
Пример #9
0
    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))