当前位置: 首页>>代码示例>>Python>>正文


Python SocialClient.logout方法代码示例

本文整理汇总了Python中wildlifelicensing.apps.main.tests.helpers.SocialClient.logout方法的典型用法代码示例。如果您正苦于以下问题:Python SocialClient.logout方法的具体用法?Python SocialClient.logout怎么用?Python SocialClient.logout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wildlifelicensing.apps.main.tests.helpers.SocialClient的用法示例。


在下文中一共展示了SocialClient.logout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_action_log

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import logout [as 别名]
def get_action_log(application):
    client = SocialClient()
    officer = get_or_create_default_officer()
    client.login(officer.email)
    url = reverse('wl_applications:action_list', args=[application.pk])
    resp = client.get(url)
    client.logout()
    return resp.json()['data']
开发者ID:wilsonc86,项目名称:ledger,代码行数:10,代码来源:helpers.py

示例2: TestStatusLifeCycle

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import logout [as 别名]
class TestStatusLifeCycle(TestCase):
    fixtures = ['licences.json']

    def setUp(self):
        self.client = SocialClient()
        self.officer = get_or_create_default_officer()
        self.user = get_or_create_default_customer()
        self.assertNotEqual(self.officer, self.user)

    def tearDown(self):
        self.client.logout()
        clear_mailbox()
        clear_all_id_files()

    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)
开发者ID:brendanc-dpaw,项目名称:ledger,代码行数:60,代码来源:test_process.py

示例3: lodge_application

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import logout [as 别名]
def lodge_application(application):
    """
    :param application:
    """
    client = SocialClient()
    client.login(application.applicant.email)
    client.get(reverse('wl_applications:edit_application', args=[application.pk]))
    url = reverse_lazy('wl_applications:preview')
    client.post(url)
    application.refresh_from_db()
    client.logout()
    return application
开发者ID:wilsonc86,项目名称:ledger,代码行数:14,代码来源:helpers.py

示例4: lodge_application

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import logout [as 别名]
def lodge_application(application):
    """
    :param application:
    """
    client = SocialClient()
    client.login(application.applicant_profile.user.email)
    url = reverse_lazy("wl_applications:preview", args=[application.licence_type.code_slug, application.pk])
    session = client.session
    session["application"] = {"profile": application.applicant_profile.pk, "data": application.data}
    session.save()
    client.post(url)
    application.refresh_from_db()
    client.logout()
    return application
开发者ID:serge-gaia,项目名称:ledger,代码行数:16,代码来源:helpers.py

示例5: issue_licence

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import logout [as 别名]
def issue_licence(application=None, user=None, licence_data=None):
    if application is None:
        application = create_and_lodge_application(user)
    if user is None:
        user = get_or_create_default_officer()
    client = SocialClient()
    client.login(user.email)
    if licence_data is None:
        licence_data = {}
    data = get_minimum_data_for_issuing_licence()
    data.update(licence_data)
    url = reverse('wl_applications:issue_licence', args=[application.pk])
    client.post(url, data=data, follow=True)
    client.logout()
    application.refresh_from_db()
    assert application.licence
    return application.licence
开发者ID:wilsonc86,项目名称:ledger,代码行数:19,代码来源:helpers.py

示例6: lodge_application

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import logout [as 别名]
def lodge_application(application):
    """
    :param application:
    """
    client = SocialClient()
    client.login(application.applicant_profile.user.email)
    url = reverse_lazy('applications:preview', args=[application.licence_type.code, application.pk])
    session = client.session
    session['application'] = {
        'profile': application.applicant_profile.pk,
        'data': application.data
    }
    session.save()
    client.post(url)
    application.refresh_from_db()
    client.logout()
    return application
开发者ID:rockychen-dpaw,项目名称:ledger,代码行数:19,代码来源:helpers.py

示例7: ApplicationEntrySecurity

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import logout [as 别名]

#.........这里部分代码省略.........
        self.assertNotEqual(customer1, customer2)
        application1 = helpers.create_application(user=customer1)
        application2 = helpers.create_application(user=customer2)
        self.assertNotEqual(application1, application2)

        # login as user1
        self.client.login(customer1.email)
        my_url = reverse('applications:enter_details_existing_application',
                         args=[application1.licence_type.code, application1.pk])
        response = self.client.get(my_url)
        self.assertEqual(200, response.status_code)

        forbidden_urls = [
            reverse('applications:edit_application', args=[application2.licence_type.code, application2.pk]),
            reverse('applications:enter_details_existing_application',
                    args=[application2.licence_type.code, application2.pk]),
            reverse('applications:preview', args=[application2.licence_type.code, application2.pk])
        ]

        for forbidden_url in forbidden_urls:
            response = self.client.get(forbidden_url, follow=True)
            self.assertEqual(403, response.status_code)

    def test_user_access_lodged(self):
        """
        Once the application if lodged the user should not be able to edit it
        """
        customer1 = create_random_customer()
        # login as user1
        self.client.login(customer1.email)

        application = helpers.create_application(user=customer1)
        self.assertEqual('draft', application.customer_status)
        my_urls = [
            reverse('applications:edit_application', args=[application.licence_type.code, application.pk]),
            reverse('applications:enter_details_existing_application',
                    args=[application.licence_type.code, application.pk]),
            reverse('applications:preview', args=[application.licence_type.code, application.pk])
        ]
        for url in my_urls:
            response = self.client.get(url, follow=True)
            self.assertEqual(200, response.status_code,
                             msg="Wrong status code {1} for {0}".format(url, response.status_code))

        # lodge the application
        url = reverse('applications:preview', args=[application.licence_type.code, application.pk])
        session = self.client.session
        session['application'] = {
            'profile': application.applicant_profile.pk,
            'data': {
                'project_title': 'Test'
            }
        }
        session.save()
        self.client.post(url)
        application.refresh_from_db()
        self.assertEqual('under_review', application.customer_status)
        for url in my_urls:
            response = self.client.get(url, follow=True)
            self.assertEqual(403, response.status_code)

    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()
        application = helpers.create_application(user=customer1)
        self.assertEqual('draft', application.customer_status)
        my_urls = [
            reverse('applications:edit_application', args=[application.licence_type.code, application.pk]),
            reverse('applications:enter_details_existing_application',
                    args=[application.licence_type.code, application.pk]),
            reverse('applications:preview', args=[application.licence_type.code, application.pk])
        ]
        for url in my_urls:
            response = self.client.get(url, follow=True)
            self.assertEqual(200, response.status_code,
                             msg="Wrong status code {1} for {0}".format(url, response.status_code))
            self.assertTrue(is_login_page(response))

        # lodge the application
        self.client.login(customer1.email)
        url = reverse('applications:preview', args=[application.licence_type.code, application.pk])
        session = self.client.session
        session['application'] = {
            'profile': application.applicant_profile.pk,
            'data': {
                'project_title': 'Test'
            }
        }
        session.save()
        self.client.post(url)
        application.refresh_from_db()
        self.assertEqual('under_review', application.customer_status)
        # logout
        self.client.logout()
        for url in my_urls:
            response = self.client.get(url, follow=True)
            self.assertEqual(200, response.status_code)
            self.assertTrue(is_login_page(response))
开发者ID:ropable,项目名称:ledger,代码行数:104,代码来源:test_entry.py

示例8: ApplicationEntryTestCase

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import logout [as 别名]
class ApplicationEntryTestCase(TestCase):
    def setUp(self):
        self.customer = create_default_customer()

        self.client = SocialClient()

        licence_type = WildlifeLicenceType.objects.get(code='regulation17')
        licence_type.identification_required = True
        licence_type.save()

    def tearDown(self):
        self.client.logout()
        # clean id file
        if self.customer.identification:
            os.remove(self.customer.identification.path)

    def test_select_licence_type(self):
        """Testing that a user can display the licence type selection list"""
        self.client.login(self.customer.email)

        # check that client can access the licence type selection list
        response = self.client.get(reverse('applications:select_licence_type'))
        self.assertEqual(200, response.status_code)

    def test_check_identification_required_no_current_id(self):
        """Testing that a user can display the identification required page in the case the user has no
        current identification, and upload an ID.
        """
        self.client.login(self.customer.email)

        # check that client can access the identification required page
        response = self.client.get(reverse('applications:check_identification', args=('regulation17',)))
        self.assertEqual(200, response.status_code)

        with open(TEST_ID_PATH) as fp:
            post_params = {
                'identification_file': fp
            }
            response = self.client.post(reverse('applications:check_identification', args=('regulation17',)),
                                        post_params)

            self.assertRedirects(response, reverse('applications:create_select_profile', args=('regulation17',)),
                                 status_code=302, target_status_code=200, fetch_redirect_response=False)

            # update customer
            self.customer = EmailUser.objects.get(email=self.customer.email)

            # assert customer's ID is the uploaded file
            self.assertEqual(self.customer.identification.filename, 'test_id.jpg')

    def test_check_identification_required_current_id(self):
        """Testing that a user can display the identification required page in the case the user has a
        current identification.
        """
        self.client.login(self.customer.email)

        with open(TEST_ID_PATH) as fp:
            self.customer.identification = Document.objects.create(name='test_id')
            self.customer.identification.file.save('test_id.jpg', File(fp), save=True)
            self.customer.save()

        # check that client is redirected to profile creation / selection page
        response = self.client.get(reverse('applications:check_identification', args=('regulation17',)))
        self.assertRedirects(response, reverse('applications:create_select_profile', args=('regulation17',)),
                             status_code=302, target_status_code=200, fetch_redirect_response=False)

    def test_create_select_profile_create(self):
        """Testing that a user can display the create / select profile page and create a profile
        in the case the user has no profile
        """
        self.client.login(self.customer.email)

        original_profile_count = self.customer.profile_set.count()

        # create the application dict in the session first
        # the session must be stored in a variable in order to be modifyable
        # https://docs.djangoproject.com/en/1.9/topics/testing/tools/#persistent-state
        session = self.client.session
        session['application'] = {}
        session.save()

        # check that client can access the profile create/select page
        response = self.client.get(reverse('applications:create_select_profile', args=('regulation17',)))
        self.assertEqual(200, response.status_code)

        # check there is not a profile selection form, meaning there is no profile
        self.assertFalse('profile_selection_form' in response.context)

        post_params = {
            'name': 'Test Profile',
            'email': '[email protected]',
            'institution': 'Test Institution',
            'line1': '1 Test Street',
            'locality': 'Test Suburb',
            'state': 'WA',
            'country': 'AU',
            'postcode': '0001',
            'create': True
        }

#.........这里部分代码省略.........
开发者ID:ropable,项目名称:ledger,代码行数:103,代码来源:test_entry.py

示例9: TestApplicationDiscardView

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import logout [as 别名]
class TestApplicationDiscardView(TestCase):
    """
    Rules of discard:
    If draft not submitted -> delete the app
    otherwise -> flag as discarded
    @see https://kanboard.dpaw.wa.gov.au/?controller=TaskViewController&action=show&task_id=2833&project_id=24

    External person must be able to discard application pushed back .
    @see https://kanboard.dpaw.wa.gov.au/?controller=TaskViewController&action=show&task_id=2743&project_id=24
    """
    fixtures = ['licences.json', 'catalogue.json', 'partner.json']

    def setUp(self):
        self.client = SocialClient()
        self.officer = helpers.get_or_create_default_officer()
        self.applicant = get_or_create_default_customer()
        self.assertNotEqual(self.officer, self.applicant)

    def tearDown(self):
        self.client.logout()
        clear_mailbox()

    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_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)
#.........这里部分代码省略.........
开发者ID:wilsonc86,项目名称:ledger,代码行数:103,代码来源:test_entry.py

示例10: ApplicationEntryTestCase

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import logout [as 别名]
class ApplicationEntryTestCase(TestCase):
    fixtures = ['licences.json', 'catalogue.json', 'partner.json']

    def setUp(self):
        helpers.create_default_country()
        self.customer = get_or_create_default_customer()

        self.client = SocialClient()

        self.licence_type = WildlifeLicenceType.objects.get(product_title='regulation-17')
        self.licence_type.identification_required = True
        self.licence_type.save()

    def tearDown(self):
        self.client.logout()
        # clean id file
        if self.customer.identification:
            os.remove(self.customer.identification.path)

    def test_new_application(self):
        """
        Testing that a user can begin the process of creating an application
        """
        self.client.login(self.customer.email)

        original_application_count = Application.objects.count()

        # check that client can access the licence type selection list
        response = self.client.get(reverse('wl_applications:new_application'), follow=True)

        self.assertRedirects(response, reverse('wl_applications:select_licence_type'),
                             status_code=302, target_status_code=200, fetch_redirect_response=False)

        self.assertEquals(Application.objects.count(), original_application_count + 1)

        application = Application.objects.get(pk=response.context['application'].id)

        self.assertEquals(application.application_type, 'new_licence')

        self.assertEqual(self.client.session['application_id'], application.id)

    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)

    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
#.........这里部分代码省略.........
开发者ID:wilsonc86,项目名称:ledger,代码行数:103,代码来源:test_entry.py

示例11: TestAssignAssessor

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import logout [as 别名]
class TestAssignAssessor(TestCase):
    fixtures = ['licences.json', 'conditions.json']

    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='[email protected]')
        self.assessor_1 = G(EmailUser, email='[email protected]', 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='[email protected]', dob='1968-04-04')
        add_to_group(self.assessor_2, 'Assessors')
        add_to_group(self.assessor_2, self.assessor_group)

    def _issue_assessment(self, application, assessor_group):
        self.client.login(self.officer.email)

        url = reverse('wl_applications:send_for_assessment')
        payload = {
            'applicationID': application.pk,
            'assGroupID': assessor_group.pk
        }
        resp = self.client.post(url, data=payload)
        self.assertEqual(resp.status_code, 200)
        self.client.logout()
        clear_mailbox()
        data = resp.json()
        return Assessment.objects.filter(pk=data['assessment']['id']).first()

    def test_email_sent_to_assessor_group(self):
        """
        Test that when an officer issue an assessment an email is sent to the group email
        """
        # officer issue assessment
        self.client.login(self.officer.email)

        url = reverse('wl_applications:send_for_assessment')
        payload = {
            'applicationID': self.application.pk,
            'assGroupID': self.assessor_group.pk
        }
        resp = self.client.post(url, data=payload)
        self.assertEqual(resp.status_code, 200)
        # we should have one email sent to the assessor
        emails = get_emails()
        self.assertEqual(len(emails), 1)
        email = emails[0]
        recipients = email.to
        self.assertEqual(len(recipients), 1)
        expected_recipient = self.assessor_group.email
        self.assertEqual(recipients[0], expected_recipient)

        # the response is a json response. It should contain the assessment id
        expected_content_type = 'application/json'
        self.assertEqual(resp['content-type'], expected_content_type)
        data = resp.json()
        self.assertTrue('assessment' in data)
        self.assertTrue('id' in data['assessment'])
        assessment = Assessment.objects.filter(pk=data['assessment']['id']).first()
        self.assertIsNotNone(assessment)
        self.assertEqual(assessment.application, self.application)
        expected_status = 'awaiting_assessment'
        self.assertEqual(assessment.status, expected_status)
        # check more data
        self.assertEqual(assessment.assessor_group, self.assessor_group)
        self.assertEqual(assessment.officer, self.officer)

        self.assertEqual(assessment.date_last_reminded, date.today())
        self.assertEqual(assessment.conditions.count(), 0)
        self.assertEqual(assessment.comment, '')
        self.assertEqual(assessment.purpose, '')

    def test_assign_assessment_send_email(self):
        """
        Use case: assessor_1 assign the assessment to assessor_2.
         Test that assessor_2 should receive an email with a link.
         The email should be also log in the communication log
        """
        assessment = self._issue_assessment(self.application, self.assessor_group)
        previous_comm_log = app_helpers.get_communication_log(assessment.application)
        previous_action_list = app_helpers.get_action_log(assessment.application)

        url = reverse('wl_applications:assign_assessor')
        self.client.login(self.assessor_1.email)
        payload = {
            'assessmentID': assessment.id,
            'userID': self.assessor_2.id
        }
        resp = self.client.post(url, data=payload)
        self.assertEqual(resp.status_code, 200)
        # the response is a json response. It should contain the assessment id
        expected_content_type = 'application/json'
#.........这里部分代码省略.........
开发者ID:wilsonc86,项目名称:ledger,代码行数:103,代码来源:test_conditions.py

示例12: TestLifeCycle

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import logout [as 别名]
class TestLifeCycle(TestCase):
    fixtures = ['licences.json', 'countries.json', 'catalogue.json', 'partner.json', 'returns.json']

    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.licence_type = get_or_create_licence_type('regulation-17')
        self.return_type = get_or_create_return_type(self.licence_type)

    def tearDown(self):
        self.client.logout()

    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 _lodge_reg17_return(self, ret, data=None):
        post_params = {
            'lodge': True,
        }
        data = data or TEST_VALUES
        for key, value in data.items():
            post_params['regulation-17::{}'.format(key)] = value

        holder = ret.licence.holder
        self.client.login(holder.email)
        response = self.client.post(reverse('wl_returns:enter_return', args=(ret.pk,)), post_params)
        self.assertRedirects(response, reverse('home'),
                             status_code=302, target_status_code=200, fetch_redirect_response=False)
        ret.refresh_from_db()
        self.client.logout()
        return data

    def _create_and_lodge_return(self):
        start_date = date.today()
        end_date = start_date + relativedelta(months=2)  # 2 months licence
        licence_data = {
            'return_frequency': -1,  # one off
            'start_date': str(start_date),
            'end_date': str(end_date)
        }
        licence = self._issue_licence(licence_data)
        self.assertIsNotNone(licence)

        ret = Return.objects.first()
        expected_status = 'current'
        self.assertEqual(ret.status, expected_status)
        data = self._lodge_reg17_return(ret)
        expected_status = 'submitted'
        self.assertEqual(ret.status, expected_status)
        return ret, data

    def _create_lodge_and_amend_return(self):
        ret, data = self._create_and_lodge_return()
        expected_status = 'submitted'
        self.assertEqual(ret.status, expected_status)

        url = reverse('wl_returns:amendment_request')
        curator = self.officer
        self.client.login(curator.email)
        payload = {
            'ret': ret.pk,
            'officer': curator.pk,
            'reason': 'Chubby bat is not a valid species'
        }
        resp = self.client.post(url, data=payload)
        self.assertEqual(resp.status_code, 200)
        ret.refresh_from_db()
        expected_status = 'amendment_required'
        self.assertEqual(ret.status, expected_status)
        self.assertEqual(ret.pending_amendments_qs.count(), 1)
        self.client.logout()
        return ret

    def test_initial_states_with_future(self):
        """
        Test that after the licence has been created some returns has been created according to the return frequency
        and the licence end date
        """
        # issue licence
        # use a one year licence with a monthly return
        start_date = today = date.today()
#.........这里部分代码省略.........
开发者ID:wilsonc86,项目名称:ledger,代码行数:103,代码来源:test_returns.py

示例13: ApplicationEntrySecurity

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import logout [as 别名]
class ApplicationEntrySecurity(TransactionTestCase):
    fixtures = ['licences.json']
    serialized_rollback = True

    def setUp(self):
        self.client = SocialClient()

    def tearDown(self):
        self.client.logout()

    def test_user_access_other_user(self):
        """
        Test that a user cannot edit/view another user application
        """
        customer1 = create_random_customer()
        customer2 = create_random_customer()
        self.assertNotEqual(customer1, customer2)

        application1 = helpers.create_application(user=customer1)
        application2 = helpers.create_application(user=customer2)
        self.assertNotEqual(application1, application2)

        # login as user1
        self.client.login(customer1.email)
        my_url = reverse('wl_applications:edit_application', args=[application1.pk])
        response = self.client.get(my_url)
        self.assertEqual(302, response.status_code)

        forbidden_urls = [
            reverse('wl_applications:edit_application', args=[application2.pk]),
        ]

        for forbidden_url in forbidden_urls:
            response = self.client.get(forbidden_url, follow=True)
            self.assertEqual(403, response.status_code)

    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)

        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)

    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)
#.........这里部分代码省略.........
开发者ID:gaiaresources,项目名称:ledger,代码行数:103,代码来源:test_entry.py

示例14: AccountsTestCase

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import logout [as 别名]
class AccountsTestCase(TestCase):
    def setUp(self):
        self.customer = get_or_create_default_customer()

        self.officer = get_or_create_default_officer()

        self.client = SocialClient()

    def tearDown(self):
        self.client.logout()
        # clean id file
        if self.customer.identification:
            os.remove(self.customer.identification.path)

    def test_profile_list(self):
        """Testing that a user can display the profile list if they are a customer"""
        self.client.login(self.customer.email)

        # check that client can access the profile list
        response = self.client.get(reverse('wl_main:list_profiles'))
        self.assertEqual(200, response.status_code)

    def test_profile_list_non_customer(self):
        """Testing that a user cannot display the profile list if they are not a customer"""
        self.client.login(self.officer.email)

        # check that client gets redirected if they try to access the profile list
        response = self.client.get(reverse('wl_main:list_profiles'))
        self.assertEqual(302, response.status_code)

    def test_create_profile(self):
        """Testing that a user can create a profile"""
        self.client.login(self.customer.email)

        original_profile_count = Profile.objects.filter(user=self.customer).count()

        # check that client can access the create profile page
        response = self.client.get(reverse('wl_main:create_profile'))
        self.assertEqual(200, response.status_code)

        post_params = {
            'user': self.customer.pk,
            'name': 'Test Profile',
            'email': '[email protected]',
            'institution': 'Test Institution',
            'line1': '1 Test Street',
            'locality': 'Test Suburb',
            'state': 'WA',
            'country': 'AU',
            'postcode': '0001'
        }

        response = self.client.post(reverse('wl_main:create_profile'), post_params)
        self.assertEqual(302, response.status_code)

        # check that a new profile has been created
        self.assertEquals(Profile.objects.filter(user=self.customer).count(), original_profile_count + 1)

    def test_edit_profile(self):
        """Testing that a user can edit an existing profile"""
        self.client.login(self.customer.email)

        # create original profile
        address = Address.objects.create(line1='1 Test Street', locality='Test Suburb', state='WA', postcode='0001')
        profile = Profile.objects.create(user=self.customer, name='Test Profile', email='[email protected]',
                                         institution='Test Institution', postal_address=address)

        # check that client can access the edit profile page
        response = self.client.get(reverse('wl_main:edit_profile', args=(profile.pk,)))
        self.assertEqual(200, response.status_code)

        post_params = {
            'user': self.customer.pk,
            'name': 'Test Profile 2',
            'email': profile.email,
            'institution': profile.institution,
            'line1': '2 Test Street',
            'locality': address.locality,
            'state': address.state,
            'country': 'AU',
            'postcode': address.postcode
        }

        response = self.client.post(reverse('wl_main:edit_profile', args=(profile.pk,)), post_params)
        self.assertEqual(302, response.status_code)

        # get updated profile
        profile = Profile.objects.get(pk=profile.pk)

        # check that the profile has been edited
        self.assertEquals(profile.name, 'Test Profile 2')
        self.assertEquals(profile.postal_address.line1, '2 Test Street')

    def test_manage_id(self):
        """Testing that a user can access the manage identification page"""
        self.client.login(self.customer.email)

        # check that client can access the manage identification page
        response = self.client.get(reverse('wl_main:identification'))
        self.assertEqual(200, response.status_code)
#.........这里部分代码省略.........
开发者ID:serge-gaia,项目名称:ledger,代码行数:103,代码来源:tests.py

示例15: TestStatusLifeCycle

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import logout [as 别名]
class TestStatusLifeCycle(TestCase):
    fixtures = ['licences.json']

    def setUp(self):
        self.client = SocialClient()
        self.officer = get_or_create_default_officer()
        self.user = get_or_create_default_customer()
        self.assertNotEqual(self.officer, self.user)

    def tearDown(self):
        self.client.logout()
        clear_mailbox()
        clear_all_id_files()

    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 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())
#.........这里部分代码省略.........
开发者ID:wilsonc86,项目名称:ledger,代码行数:103,代码来源:test_process.py


注:本文中的wildlifelicensing.apps.main.tests.helpers.SocialClient.logout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。