本文整理汇总了Python中tests.factories.AuthUserFactory.save方法的典型用法代码示例。如果您正苦于以下问题:Python AuthUserFactory.save方法的具体用法?Python AuthUserFactory.save怎么用?Python AuthUserFactory.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.AuthUserFactory
的用法示例。
在下文中一共展示了AuthUserFactory.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import save [as 别名]
def setUp(self):
self.yesterday = datetime.today() - timedelta(1)
self.a_while_ago = datetime.today() - timedelta(2)
super(TestUserCount, self).setUp()
for i in range(0, 3):
u = AuthUserFactory()
u.is_registered = True
u.password = 'wow' + str(i)
u.date_confirmed = self.yesterday
u.save()
u = AuthUserFactory()
u.is_registered = True
u.password = 'wow'
u.date_confirmed = self.a_while_ago
u.save()
for i in range(0, 2):
u = AuthUserFactory()
u.date_confirmed = None
u.save()
u = AuthUserFactory()
u.date_disabled = self.yesterday
u.save()
u = AuthUserFactory()
u.date_disabled = self.a_while_ago
u.save()
modify_user_dates_in_mongo(self.yesterday)
示例2: TestUserSettingsModel
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import save [as 别名]
class TestUserSettingsModel(OsfTestCase):
def setUp(self):
super(TestUserSettingsModel, self).setUp()
self.user = AuthUserFactory()
self.user.add_addon('badges', override=True)
self.usersettings = self.user.get_addon('badges')
self.usersettings.save()
def test_can_award(self):
assert_false(self.usersettings.can_award)
create_mock_badge(self.usersettings)
assert_true(self.usersettings.can_award)
def test_to_openbadge(self):
self.user.fullname = 'HoneyBadger'
self.user.username = '[email protected]'
self.user.save()
test = {
'name': 'HoneyBadger',
'email': '[email protected]'
}
assert_equal(self.usersettings.to_openbadge(), test)
def test_badges(self):
create_mock_badge(self.usersettings)
create_mock_badge(self.usersettings)
assert_equal(len(self.usersettings.badges), 2)
create_mock_badge(self.usersettings)
assert_equal(len(self.usersettings.badges), 3)
示例3: test_revoke_didnt_award
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import save [as 别名]
def test_revoke_didnt_award(self):
badgeid = self.user_settings.badges[0]._id
initnum = len(self.project.badgeassertion__awarded)
assert_true(self.user_settings.can_award)
url = api_url_for('award_badge', pid=self.project._id)
ret = self.app.post_json(url, {'badgeid': badgeid}, auth=self.user.auth)
self.project.reload()
assert_equals(ret.status_int, 200)
assert_equals(initnum + 1, len(self.project.badgeassertion__awarded))
assertion = self.project.badgeassertion__awarded[0]
revoke = api_url_for('revoke_badge', pid=self.project._id)
user2 = AuthUserFactory()
user2.add_addon('badges', override=True)
user2.save()
user2.reload()
ret = self.app.post_json(revoke,
{
'id': assertion._id,
'reason': ''
}, auth=user2.auth, expect_errors=True)
self.project.reload()
self.user_settings.reload()
assertion.reload()
assert_equals(ret.status_int, 400)
assert_false(assertion.revoked)
assert_true(self.project.badgeassertion__awarded[0]._id, assertion._id)
assert_false(assertion._id in self.user_settings.revocation_list)
示例4: TestMenbibAuthViews
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import save [as 别名]
class TestMenbibAuthViews(OsfTestCase):
def setUp(self):
self.app = TestApp(app)
self.user = AuthUserFactory()
self.app.authenticate(*self.user.auth)
def test_menbib_oauth_start(self):
url = api_url_for('menbib_oauth_start_user')
res = self.app.get(url)
assert_is_redirect(res)
@mock.patch('website.addons.menbib.views.auth.finish_auth')
def test_menbib_oauth_finish(self, mock_finish):
mock_finish.return_value = AuthResult('mytokenabc', 'myrefreshabc', 'cool', '3600')
url = api_url_for('menbib_oauth_finish')
res = self.app.get(url)
assert_is_redirect(res)
def test_menbib_oauth_delete_user(self):
self.user.add_addon('menbib')
user_settings = self.user.get_addon('menbib')
user_settings.access_token = '12345abc'
assert_true(user_settings.has_auth)
self.user.save()
url = api_url_for('menbib_oauth_delete_user')
res = self.app.delete(url)
user_settings.reload()
assert_false(user_settings.has_auth)
示例5: test_oauth_delete_user_two_osf_user
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import save [as 别名]
def test_oauth_delete_user_two_osf_user(self, mock_revoke_token, mock_github_user):
mock_revoke_token.return_value = True
user = mock.Mock()
user.id = "testing user id"
user.login = "testing user"
mock_github_user.return_value = user
views.auth.create_and_attach_oauth(self.user_settings, "testing acess token", "testing token type")
user2 = AuthUserFactory()
user2.add_addon('github')
user2.save()
user_settings2 = user2.get_addon('github')
views.auth.create_and_attach_oauth(user_settings2, "testing access token", "testing token type")
url = api_url_for("github_oauth_delete_user")
self.app.delete(url, auth=self.user.auth)
self.user_settings.reload()
user_settings2.reload()
assert_false(self.user_settings.oauth_token_type)
assert_false(self.user_settings.oauth_access_token)
assert_false(self.user_settings.github_user_name)
assert_false(self.user_settings.oauth_settings)
assert_true(user_settings2.oauth_settings)
assert_equal(user_settings2.oauth_token_type, "testing token type")
assert_equal(user_settings2.oauth_access_token, "testing access token")
assert_equal(user_settings2.github_user_name, "testing user")
示例6: TestUsers
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import save [as 别名]
class TestUsers(ApiTestCase):
def setUp(self):
super(TestUsers, self).setUp()
self.user_one = AuthUserFactory()
self.user_two = AuthUserFactory()
def tearDown(self):
super(TestUsers, self).tearDown()
def test_returns_200(self):
res = self.app.get('/{}users/'.format(API_BASE))
assert_equal(res.status_code, 200)
assert_equal(res.content_type, 'application/vnd.api+json')
def test_find_user_in_users(self):
url = "/{}users/".format(API_BASE)
res = self.app.get(url)
user_son = res.json['data']
ids = [each['id'] for each in user_son]
assert_in(self.user_two._id, ids)
def test_all_users_in_users(self):
url = "/{}users/".format(API_BASE)
res = self.app.get(url)
user_son = res.json['data']
ids = [each['id'] for each in user_son]
assert_in(self.user_one._id, ids)
assert_in(self.user_two._id, ids)
def test_find_multiple_in_users(self):
url = "/{}users/?filter[fullname]=fred".format(API_BASE)
res = self.app.get(url)
user_json = res.json['data']
ids = [each['id'] for each in user_json]
assert_in(self.user_one._id, ids)
assert_in(self.user_two._id, ids)
def test_find_single_user_in_users(self):
url = "/{}users/?filter[fullname]=my".format(API_BASE)
self.user_one.fullname = 'My Mom'
self.user_one.save()
res = self.app.get(url)
user_json = res.json['data']
ids = [each['id'] for each in user_json]
assert_in(self.user_one._id, ids)
assert_not_in(self.user_two._id, ids)
def test_find_no_user_in_users(self):
url = "/{}users/?filter[fullname]=NotMyMom".format(API_BASE)
res = self.app.get(url)
user_json = res.json['data']
ids = [each['id'] for each in user_json]
assert_not_in(self.user_one._id, ids)
assert_not_in(self.user_two._id, ids)
示例7: test_claim_user_registered_with_correct_password
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import save [as 别名]
def test_claim_user_registered_with_correct_password(self):
reg_user = AuthUserFactory()
reg_user.set_password('killerqueen')
reg_user.save()
url = self.user.get_claim_url(self.project._primary_key)
# Follow to password re-enter page
res = self.app.get(url, auth=reg_user.auth).follow(auth=reg_user.auth)
# verify that the "Claim Account" form is returned
assert_in('Claim Contributor', res.body)
form = res.forms['claimContributorForm']
form['password'] = 'killerqueen'
res = form.submit(auth=reg_user.auth).follow(auth=reg_user.auth)
self.project.reload()
self.user.reload()
# user is now a contributor to the project
assert_in(reg_user._primary_key, self.project.contributors)
# the unregistered user (self.user) is removed as a contributor, and their
assert_not_in(self.user._primary_key, self.project.contributors)
# unclaimed record for the project has been deleted
assert_not_in(self.project._primary_key, self.user.unclaimed_records)
示例8: setUp
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import save [as 别名]
def setUp(self):
self.yesterday = datetime.today() - timedelta(1)
self.a_while_ago = datetime.today() - timedelta(2)
super(TestUserCount, self).setUp()
for i in range(0, 3):
u = AuthUserFactory()
u.is_registered = True
u.password = 'wow' + str(i)
u.date_confirmed = self.yesterday
u.save()
# Make one of those 3 a depth user
for i in range(LOG_THRESHOLD + 1):
NodeLogFactory(action='file_added', user=u)
u = AuthUserFactory()
u.is_registered = True
u.password = 'wow'
u.date_confirmed = self.a_while_ago
u.save()
for i in range(LOG_THRESHOLD + 1):
NodeLogFactory(action='file_added', user=u)
for i in range(0, 2):
u = AuthUserFactory()
u.date_confirmed = None
u.save()
u = AuthUserFactory()
u.date_disabled = self.yesterday
u.save()
u = AuthUserFactory()
u.date_disabled = self.a_while_ago
u.save()
modify_user_dates_in_mongo(self.yesterday)
示例9: test_revoke_remote_access_not_called
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import save [as 别名]
def test_revoke_remote_access_not_called(self, mock_decorator, mock_revoke):
mock_decorator.return_value = self.user
user2 = AuthUserFactory()
user2.external_accounts.append(self.external_account)
user2.save()
self.user_settings.delete()
assert_equal(mock_revoke.call_count, 0)
示例10: TestUserGet
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import save [as 别名]
class TestUserGet(AdminTestCase):
def setUp(self):
super(TestUserGet, self).setUp()
User.remove()
self.user_1 = AuthUserFactory()
self.auth = Auth(user=self.user_1)
self.project = ProjectFactory(creator=self.user_1)
self.project.add_unregistered_contributor(
email='[email protected]',
fullname='Weezy F. Baby',
auth=self.auth
)
self.user_3 = AuthUserFactory()
self.user_3.date_confirmed = None
self.user_3.save()
self.user_4 = AuthUserFactory()
def test_get_all_user_count(self):
time_now = datetime.utcnow()
count = get_all_user_count(time_now)
nt.assert_equal(count, 4)
def test_get_unregistered_users(self):
count = get_unregistered_users()
nt.assert_equal(count, 1)
示例11: TestBoxIntegration
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import save [as 别名]
class TestBoxIntegration(OsfTestCase):
def setUp(self):
super(TestBoxIntegration, self).setUp()
self.user = AuthUserFactory()
# User is logged in
self.app.authenticate(*self.user.auth)
def test_cant_start_oauth_if_already_authorized(self):
# User already has box authorized
self.user.add_addon('box')
self.user.save()
settings = self.user.get_addon('box')
oauth = BoxOAuthSettings(user_id='fa;l', access_token='a;lkjadl;kas')
oauth.save()
settings.oauth_settings = oauth
settings.save()
assert_true(self.user.get_addon('box').has_auth)
# Tries to start oauth again
url = api_url_for('box_oauth_start_user')
res = self.app.get(url).follow()
# Is redirected back to settings page
assert_equal(
res.request.path,
web_url_for('user_addons')
)
示例12: test_reviewer_cannot_update_nested_value_fields_draft_registration
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import save [as 别名]
def test_reviewer_cannot_update_nested_value_fields_draft_registration(self):
user = AuthUserFactory()
user.system_tags.append(PREREG_ADMIN_TAG)
user.save()
payload = {
"data": {
"id": self.prereg_draft_registration._id,
"type": "draft_registrations",
"attributes": {
"registration_metadata": {
'q7': {
'value': {
'question': {
'value': 'This is the answer'
}
}
}
}
}
}
}
url = '/{}nodes/{}/draft_registrations/{}/'.format(API_BASE, self.public_project._id, self.prereg_draft_registration._id)
res = self.app.put_json_api(url, payload, auth=user.auth, expect_errors=True)
assert_equal(res.status_code, 400)
assert_equal(res.json['errors'][0]['detail'], "Additional properties are not allowed (u'value' was unexpected)")
示例13: test_reviewer_can_update_nested_comment_fields_draft_registration
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import save [as 别名]
def test_reviewer_can_update_nested_comment_fields_draft_registration(self):
user = AuthUserFactory()
user.system_tags.append(PREREG_ADMIN_TAG)
user.save()
payload = {
"data": {
"id": self.prereg_draft_registration._id,
"type": "draft_registrations",
"attributes": {
"registration_metadata": {
'q7': {
'value': {
'question': {
'comments': [{'value': 'Add some clarity here.'}]
}
}
}
}
}
}
}
url = '/{}nodes/{}/draft_registrations/{}/'.format(API_BASE, self.public_project._id, self.prereg_draft_registration._id)
res = self.app.put_json_api(url, payload, auth=user.auth, expect_errors=True)
assert_equal(res.status_code, 200)
assert_equal(res.json['data']['attributes']['registration_metadata']['q7']['value']['question']['comments'][0]['value'], 'Add some clarity here.')
示例14: TestDataverseRestrictions
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import save [as 别名]
class TestDataverseRestrictions(DataverseAddonTestCase, OsfTestCase):
def setUp(self):
super(DataverseAddonTestCase, self).setUp()
# Nasty contributor who will try to access content that he shouldn't
# have access to
self.contrib = AuthUserFactory()
self.project.add_contributor(self.contrib, auth=Auth(self.user))
self.project.save()
@mock.patch('addons.dataverse.views.client.connect_from_settings')
def test_restricted_set_dataset_not_owner(self, mock_connection):
mock_connection.return_value = create_mock_connection()
# Contributor has dataverse auth, but is not the node authorizer
self.contrib.add_addon('dataverse')
self.contrib.save()
url = api_url_for('dataverse_set_config', pid=self.project._primary_key)
params = {
'dataverse': {'alias': 'ALIAS1'},
'dataset': {'doi': 'doi:12.3456/DVN/00002'},
}
res = self.app.post_json(url, params, auth=self.contrib.auth,
expect_errors=True)
assert_equal(res.status_code, http.FORBIDDEN)
示例15: test_many_users_each_with_the_same_github
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import save [as 别名]
def test_many_users_each_with_the_same_github(self):
user = AuthUserFactory()
user.add_addon('github')
user.external_accounts.append(self.oauth_settings)
user.save()
results = AddonSnapshot().get_events()
github_res = [res for res in results if res['provider']['name'] == 'github'][0]
assert_equal(github_res['users']['total'], 2)