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


Python SocialClient.get方法代码示例

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


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

示例1: TestStatusLifeCycle

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import get [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

示例2: lodge_application

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import get [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

示例3: get_action_log

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import get [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

示例4: ApplicationEntrySecurity

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import get [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

示例5: ApplicationEntryTestCase

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import get [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 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'))

        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)

        self.assertEqual(self.client.session['application_id'], Application.objects.first().id)

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

        self.client.get(reverse('wl_applications:new_application'))

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

        # check that client can select a licence type the licence type selection list
        response = self.client.get(reverse('wl_applications:select_licence_type', args=(self.licence_type.pk,)))

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

    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)

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

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

        with open(TEST_ID_PATH, 'rb') as fp:
            post_params = {
                'identification_file': fp
            }
            response = self.client.post(reverse('wl_applications:check_identification'),
                                        post_params, follow=True)

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

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

    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)

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

        with open(TEST_ID_PATH, 'rb') 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('wl_applications:check_identification'), follow=True)
        self.assertRedirects(response, reverse('wl_applications:create_select_profile'),
                             status_code=302, target_status_code=200, fetch_redirect_response=True)

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

示例6: ApplicationEntrySecurity

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

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

示例7: ApplicationEntryTestCase

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import get [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

示例8: TestApplicationDiscardView

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import get [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

示例9: ApplicationEntryTestCase

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import get [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

示例10: AccountsTestCase

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import get [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

示例11: AccountsTestCase

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import get [as 别名]
class AccountsTestCase(TestCase):
    def setUp(self):
        create_default_country()
        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(403, 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)

        # check no profile
        self.assertEquals(0, Profile.objects.filter(user=self.customer).count())
        # 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)

        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 one profile has been created
        self.assertEquals(1, Profile.objects.filter(user=self.customer).count())

        profile = Profile.objects.filter(user=self.customer).first()
        # 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)

        # updated profile
        post_params['name'] = 'Updated Profile'
        post_params['line1'] = 'New Line 1'
        response = self.client.post(reverse('wl_main:edit_profile', args=(profile.pk,)), post_params)
        self.assertEqual(302, response.status_code)

        # get updated profile
        self.assertEquals(1, Profile.objects.filter(user=self.customer).count())
#.........这里部分代码省略.........
开发者ID:wilsonc86,项目名称:ledger,代码行数:103,代码来源:tests.py

示例12: TestViewAccess

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import get [as 别名]
class TestViewAccess(TestCase):
    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 tearDown(self):
        self.client.logout()

    def test_customer_access(self):
        """
         A Customer cannot access any URL
        """
        # not logged-in
        for url in self.process_urls_get:
            response = self.client.get(url, follow=True)
            self.assertTrue(is_login_page(response))

        for url in self.process_urls_post:
            response = self.client.post(url['url'], url['data'], follow=True)
            self.assertTrue(is_login_page(response))

        # logged-in. Should get a 403
        self.client.login(self.user.email)
        for url in self.process_urls_get:
            response = self.client.get(url, follow=True)
            self.assertEqual(response.status_code, 403)
        for url in self.process_urls_post:
#.........这里部分代码省略.........
开发者ID:wilsonc86,项目名称:ledger,代码行数:103,代码来源:test_process.py

示例13: TestStatusLifeCycle

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import get [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

示例14: TestPermissions

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import get [as 别名]
class TestPermissions(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 = create_licence(self.customer, self.officer, product_title='regulation-17')
        self.ret = create_return(self.licence)

    def test_returns_lodgement_page(self):
        """
        Only officer or application owner can view returns
        """
        url = reverse('wl_returns:enter_return', args=(self.ret.pk,))
        allowed = [self.officer, self.customer]
        forbidden = [self.not_allowed_customer, self.assessor]

        for user in allowed:
            self.client.login(user.email)
            response = self.client.get(url)
            self.assertEqual(200, response.status_code)
            self.client.logout()

        for user in forbidden:
            self.client.login(user.email)
            response = self.client.get(url)
            self.assertEqual(403, response.status_code)
            self.client.logout()

    def test_readonly_view(self):
        """
        Only officer or application owner can enter returns
        """
        url = reverse('wl_returns:view_return', args=(self.ret.pk,))
        allowed = [self.officer, self.customer]
        forbidden = [self.not_allowed_customer, self.assessor]

        for user in allowed:
            self.client.login(user.email)
            response = self.client.get(url)
            self.assertEqual(200, response.status_code)
            self.client.logout()

        for user in forbidden:
            self.client.login(user.email)
            response = self.client.get(url)
            self.assertEqual(403, response.status_code)
            self.client.logout()

    def test_curate_view(self):
        """
        Only officer can curate returns
        """
        url = reverse('wl_returns:curate_return', args=(self.ret.pk,))
        allowed = [self.officer]
        forbidden = [self.not_allowed_customer, self.assessor, self.customer]

        for user in allowed:
            self.client.login(user.email)
            response = self.client.get(url)
            self.assertEqual(200, response.status_code)
            self.client.logout()

        for user in forbidden:
            self.client.login(user.email)
            response = self.client.get(url)
            self.assertEqual(403, response.status_code)
            self.client.logout()

    def test_view_log(self):
        """
        Only officer can view log
        """
        url = reverse('wl_returns:log_list', args=(self.ret.pk,))
        allowed = [self.officer]
        forbidden = [self.not_allowed_customer, self.assessor, self.customer]

        for user in allowed:
            self.client.login(user.email)
            response = self.client.get(url)
            self.assertEqual(200, response.status_code)
            self.client.logout()

        for user in forbidden:
            self.client.login(user.email)
            response = self.client.get(url)
            self.assertEqual(403, response.status_code)
            self.client.logout()

    def test_add_log(self):
        """
        Only officer can view log
        """
        url = reverse('wl_returns:add_log_entry', args=(self.ret.pk,))
        allowed = [self.officer]
#.........这里部分代码省略.........
开发者ID:wilsonc86,项目名称:ledger,代码行数:103,代码来源:test_returns.py

示例15: ReturnsTestCase

# 需要导入模块: from wildlifelicensing.apps.main.tests.helpers import SocialClient [as 别名]
# 或者: from wildlifelicensing.apps.main.tests.helpers.SocialClient import get [as 别名]
class ReturnsTestCase(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.client = SocialClient()

        self.licence = create_licence(self.customer, self.officer, product_title='regulation-17')
        self.ret = create_return(self.licence)

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

    def test_returns_lodgement_page(self):
        """Testing that a user can access the returns lodgement page"""

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

        # check that client can access the licence type selection list
        response = self.client.get(reverse('wl_returns:enter_return', args=(self.ret.pk,)))
        self.assertEqual(200, response.status_code)

    def test_lodge_nil_return(self):
        """Testing that a user can log a nil return"""

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

        post_params = {
            'nil': True,
            'comments': 'No survey taken'
        }
        response = self.client.post(reverse('wl_returns:enter_return', args=(self.ret.pk,)),
                                    post_params)

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

    def test_upload_return_spreadsheet(self):
        """Testing that a user can upload a return spreadsheet"""

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

        with open(TEST_SPREADSHEET_PATH, 'rb') as fp:
            post_params = {
                'upload': True,
                'spreadsheet_file': fp
            }
            response = self.client.post(reverse('wl_returns:enter_return', args=(self.ret.pk,)),
                                        post_params)

        self.assertEqual(200, response.status_code)

        # assert values in the response context match those in the spreadsheet
        for key, value in response.context['tables'][0]['data'][0].items():
            self.assertEqual(value['value'], TEST_VALUES[key])

    def test_lodge_return(self):
        """Testing that a user can lodge a return"""
        self.client.login(self.customer.email)

        # check return status is intially 'current'
        self.assertEqual(self.ret.status, 'current')

        post_params = {
            'lodge': True,
        }

        for key, value in TEST_VALUES.items():
            post_params['regulation-17::{}'.format(key)] = value

        response = self.client.post(reverse('wl_returns:enter_return', args=(self.ret.pk,)), post_params)

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

        self.ret.refresh_from_db()

        # check return status is 'submitted'
        self.assertEqual(self.ret.status, 'submitted')

        # assert values in the return is what is expected
        for key, value in self.ret.returntable_set.first().returnrow_set.first().data.items():
            self.assertEqual(value, str(TEST_VALUES[key]))
开发者ID:gaiaresources,项目名称:ledger,代码行数:87,代码来源:test_returns.py


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