本文整理汇总了Python中myjobs.tests.factories.UserFactory.set_password方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.set_password方法的具体用法?Python UserFactory.set_password怎么用?Python UserFactory.set_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类myjobs.tests.factories.UserFactory
的用法示例。
在下文中一共展示了UserFactory.set_password方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_non_staff_user
# 需要导入模块: from myjobs.tests.factories import UserFactory [as 别名]
# 或者: from myjobs.tests.factories.UserFactory import set_password [as 别名]
def test_non_staff_user(self):
self.client.logout()
user = UserFactory(email='[email protected]')
user.set_password('secret')
self.client.login(username=user.email, password='secret')
response = self.client.get(reverse('source_code_upload'))
self.assertTrue('Log in' in response.content)
示例2: NewUserTests
# 需要导入模块: from myjobs.tests.factories import UserFactory [as 别名]
# 或者: from myjobs.tests.factories.UserFactory import set_password [as 别名]
class NewUserTests(SeleniumTestCase):
"""Tests Account creation"""
def setUp(self):
self.user = UserFactory(first_name="John", last_name="Doe")
def test_home_page_works(self):
"""
As John, navigating to https://secure.my.jobs should send me to a page
titled "My.jobs".
"""
self.browser.get(self.live_server_url)
self.assertIn(self.browser.title, 'My.jobs')
def test_cant_log_in_without_account(self):
"""
As John, I shouldn't be able to log into My.jobs without registering
first.
"""
self.browser.get('/'.join([self.live_server_url, 'prm', 'view']))
# attempt to log in
username = self.find('id_username')
username.send_keys(self.user.email)
self.find('id_password').send_keys(self.user.password)
self.find('login').click()
self.assertEqual(username.get_attribute('placeholder'),
'Please enter a correct email.')
def test_user_registration(self):
"""
As John, I should be able to register on My.jobs and log in.
"""
user = UserFactory.build(email='[email protected]')
self.browser.get('/'.join([self.live_server_url, 'prm', 'view']))
# register
self.find('id_email').send_keys(user.email)
self.find('id_password1').send_keys(user.password)
self.find('id_password2').send_keys(user.password)
self.find('register').click()
self.assertEqual(self.find('profile').get_attribute(
'innerHTML'),
'Skip: Take me to my profile')
def test_user_login(self):
self.user.set_password("test")
self.user.save()
self.find('id_username').send_keys(self.user.email)
self.find('id_password').send_keys("test")
self.find('login').click()
示例3: MyReportsTestCase
# 需要导入模块: from myjobs.tests.factories import UserFactory [as 别名]
# 或者: from myjobs.tests.factories.UserFactory import set_password [as 别名]
class MyReportsTestCase(TestCase):
"""
Base class for all MyReports Tests. Identical to `django.test.TestCase`
except that it provides a MyJobs TestClient instance and a logged in user.
"""
def setUp(self):
self.client = TestClient()
self.user = UserFactory(email='[email protected]')
self.user.set_password('aa')
self.company = CompanyFactory(name='Test Company')
self.partner = PartnerFactory(name='Test Partner', owner=self.company)
# associate company to user
CompanyUserFactory(user=self.user, company=self.company)
self.client.login_user(self.user)
create_full_fixture()
示例4: NewUserTests
# 需要导入模块: from myjobs.tests.factories import UserFactory [as 别名]
# 或者: from myjobs.tests.factories.UserFactory import set_password [as 别名]
class NewUserTests(SeleniumTestCase):
"""Tests Account creation"""
def setUp(self):
super(NewUserTests, self).setUp()
company = CompanyFactory()
self.user = UserFactory(first_name="John", last_name="Doe")
admin_role = RoleFactory(company=company, name='Admin')
self.user.roles.add(self.admin_role)
def test_home_page_works(self):
"""
As John, navigating to https://secure.my.jobs should send me to a page
titled "My.jobs".
"""
self.browser.get(self.live_server_url)
self.assertIn(self.browser.title, 'My.jobs')
def test_cant_log_in_without_account(self):
"""
As John, I shouldn't be able to log into My.jobs without registering
first.
"""
self.browser.get('/'.join([self.live_server_url, 'prm', 'view']))
# We're trying to access a private page while unauthenticated, which
# should result in a next parameter being added.
self.assertTrue('next=' in self.browser.current_url)
# attempt to log in
username = self.find('id_username')
username.send_keys(self.user.email)
self.find('id_password').send_keys(self.user.password)
self.find('login').click()
# If we've logged in, the next parameter should have went away. We
# aren't expecting to be logged in right now as the password was bad.
self.assertTrue('next=' in self.browser.current_url)
def test_user_registration(self):
"""
As John, I should be able to register on My.jobs and log in.
"""
self.browser.get('/'.join([self.live_server_url, 'prm', 'view']))
# register
self.find('id_email').send_keys('[email protected]')
self.find('id_password1').send_keys('aaAA11..')
self.find('id_password2').send_keys('aaAA11..')
self.find('register').click()
try:
WebDriverWait(self.browser, 10).until(
expected_conditions.presence_of_element_located(
(By.ID, 'profile')))
finally:
self.assertEqual(self.find('profile').get_attribute(
'innerHTML'),
'Skip: Take me to my profile')
def test_user_login(self):
self.user.set_password("test")
self.user.save()
self.find('id_username').send_keys(self.user.email)
self.find('id_password').send_keys("test")
self.find('login').click()
示例5: EmailForwardTests
# 需要导入模块: from myjobs.tests.factories import UserFactory [as 别名]
# 或者: from myjobs.tests.factories.UserFactory import set_password [as 别名]
class EmailForwardTests(RedirectBase):
def setUp(self):
super(EmailForwardTests, self).setUp()
self.redirect_guid = JOB['guid']
self.redirect = RedirectFactory(buid=JOB['buid'],
guid='{%s}' %
uuid.UUID(self.redirect_guid))
self.password = 'secret'
self.user = UserFactory(email='[email protected]')
self.user.set_password(self.password)
self.user.save()
self.contact = CompanyEmail.objects.create(
buid=self.redirect.buid,
email=self.user.email)
self.email = self.user.email.replace('@', '%40')
self.auth = {
'bad': [
'',
'Basic %s' % base64.b64encode('bad%40email:wrong_pass')],
'good':
'Basic %s' % base64.b64encode('%s:%s' % (self.user.email.\
replace('@', '%40'),
self.password))}
self.post_dict = {'to': '[email protected]',
'from': '[email protected]',
'text': 'Questions about stuff',
'html': '<b>Questions about stuff</b>',
'subject': 'Bad Email',
'attachments': 0}
self.r = Replacer()
self.r.replace('pysolr.Solr.search', mock_search)
def tearDown(self):
super(EmailForwardTests, self).tearDown()
self.r.restore()
def submit_email(self, use_data=True):
"""
Helper method for submitting parsed emails. Ensures that the request
returns a status of 200.
Inputs:
:use_data: Should we include post data; Default: True
Outputs:
:response: HttpResponse from email redirect view
"""
auth = self.auth.get('good')
kwargs = {'HTTP_AUTHORIZATION': auth}
if use_data:
kwargs['data'] = self.post_dict
response = self.client.post(reverse('email_redirect'),
**kwargs)
self.assertEqual(response.status_code, 200)
return response
def assert_guid_email_responses_are_correct(self,
redirect,
job=None):
"""
Helper method for validating parsed [email protected] emails.
Inputs:
:redirect: Redirect instance to use if a job is old
:job: Solr result for a new job
"""
email = mail.outbox.pop(0)
self.assertEqual(email.from_email,
settings.DEFAULT_FROM_EMAIL)
self.assertEqual(email.to, [self.post_dict['from']])
self.assertEqual(email.subject, self.post_dict['subject'])
# Emails turn lots of characters into HTML entities. Results from
# Solr and the database do not. Unescape the email body so we can
# compare the two.
parser = HTMLParser.HTMLParser()
body = parser.unescape(email.body)
if job is not None:
self.assertTrue(markdown.markdown(job['description']) in body)
else:
self.assertTrue(redirect.job_title in body)
def test_jira_login(self):
jira = JIRA(options=settings.options,
basic_auth=settings.my_agent_auth)
self.assertIsNotNone(jira)
def test_bad_authorization(self):
for auth in self.auth.get('bad'):
kwargs = {}
if auth:
# auth_value has a value, so we can pass an HTTP_AUTHORIZATION
# header
kwargs['HTTP_AUTHORIZATION'] = auth
response = self.client.post(reverse('email_redirect'),
#.........这里部分代码省略.........