本文整理汇总了Python中wildlifelicensing.apps.main.tests.helpers.SocialClient类的典型用法代码示例。如果您正苦于以下问题:Python SocialClient类的具体用法?Python SocialClient怎么用?Python SocialClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SocialClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lodge_application
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
示例2: setUp
def setUp(self):
create_default_country()
self.customer = get_or_create_default_customer()
self.officer = get_or_create_default_officer()
self.client = SocialClient()
示例3: setUp
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()
示例4: setUp
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)
示例5: setUp
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()
示例6: get_action_log
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']
示例7: lodge_application
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
示例8: setUp
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)
示例9: issue_licence
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
示例10: lodge_application
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
示例11: AccountsTestCase
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)
#.........这里部分代码省略.........
示例12: TestPermissions
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]
#.........这里部分代码省略.........
示例13: TestLifeCycle
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()
#.........这里部分代码省略.........
示例14: ApplicationEntrySecurity
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)
#.........这里部分代码省略.........
示例15: setUp
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
}
},
]