def test_user_can_log_in_with_a_different_account(self, mock_session): # Assume that the unregistered user data is already stored in the session mock_session.data = { 'unreg_user': { 'uid': self.user._primary_key, 'pid': self.project._primary_key, 'token': self.user.get_unclaimed_record( self.project._primary_key)['token'] } } right_user = AuthUserFactory.build(fullname="Right User") right_user.set_password('science') right_user.save() # User goes to the claim page, but a different user (lab_user) is logged in lab_user = AuthUserFactory(fullname="Lab Comp") url = self.user.get_claim_url(self.project._primary_key) res = self.app.get(url, auth=lab_user.auth).follow(auth=lab_user.auth) # verify that the "Claim Account" form is returned assert_in('Claim Contributor', res.body) # Clicks "I am not Lab Comp" # Taken to login/register page res2 = res.click(linkid='signOutLink', auth=lab_user.auth) # Fills in log in form form = res2.forms['signinForm'] form['username'] = right_user.username form['password'] = '******' # submits res3 = form.submit().follow() # Back at claim contributor page assert_in('Claim Contributor', res3) # Verifies their password form = res3.forms['claimContributorForm'] form['password'] = '******' form.submit() self.project.reload() right_user.reload() self.user.reload() # user is now a contributor to self.project assert_in(right_user._primary_key, self.project.contributors) # lab user is not a contributor assert_not_in(lab_user._primary_key, self.project.contributors)
def test_user_config_get(self): url = api_url_for('dataverse_user_config_get') new_user = AuthUserFactory.build() res = self.app.get(url, auth=new_user.auth) result = res.json.get('result') assert_false(result['userHasAuth']) assert_in('hosts', result) assert_in('create', result['urls']) # userHasAuth is true with external accounts new_user.external_accounts.add(create_external_account()) new_user.save() res = self.app.get(url, auth=self.user.auth) result = res.json.get('result') assert_true(result['userHasAuth'])
def setUp(self): super(TestUserUpdate, self).setUp() self.user_one = AuthUserFactory.build( fullname='Martin Luther King Jr.', given_name='Martin', family_name='King', suffix='Jr.', social=dict( github='userOneGithub', scholar='userOneScholar', personal='http://www.useronepersonalwebsite.com', twitter='userOneTwitter', linkedIn='userOneLinkedIn', impactStory='userOneImpactStory', orcid='userOneOrcid', researcherId='userOneResearcherId' ) ) self.user_one.save() self.user_one_url = "/v2/users/{}/".format(self.user_one._id) self.user_two = AuthUserFactory() self.user_two.save() self.new_user_one_data = { 'id': self.user_one._id, 'fullname': 'el-Hajj Malik el-Shabazz', 'given_name': 'Malcolm', 'middle_names': 'Malik el-Shabazz', 'family_name': 'X', 'suffix': 'Sr.', 'gitHub': 'newGitHub', 'scholar': 'newScholar', 'personal_website': 'http://www.newpersonalwebsite.com', 'twitter': 'http://www.newpersonalwebsite.com', 'linkedIn': 'newLinkedIn', 'impactStory': 'newImpactStory', 'orcid': 'newOrcid', 'researcherId': 'newResearcherId', }
def setUp(self): super(TestExceptionFormatting, self).setUp() self.user = AuthUserFactory.build( fullname='Martin Luther King Jr.', given_name='Martin', family_name='King', suffix='Jr.', social=dict(github='userOneGithub', scholar='userOneScholar', personal='http://www.useronepersonalwebsite.com', twitter='userOneTwitter', linkedIn='userOneLinkedIn', impactStory='userOneImpactStory', orcid='userOneOrcid', researcherId='userOneResearcherId')) self.url = '/{}users/{}/'.format(API_BASE, self.user._id) self.user_two = AuthUserFactory()
def setUp(self): super(TestExceptionFormatting, self).setUp() self.user = AuthUserFactory.build( fullname="Martin Luther King Jr.", given_name="Martin", family_name="King", suffix="Jr.", social=dict( github="userOneGithub", scholar="userOneScholar", personal="http://www.useronepersonalwebsite.com", twitter="userOneTwitter", linkedIn="userOneLinkedIn", impactStory="userOneImpactStory", orcid="userOneOrcid", researcherId="userOneResearcherId", ), ) self.url = "/{}users/{}/".format(API_BASE, self.user._id) self.user_two = AuthUserFactory()
def setUp(self): super(TestExceptionFormatting, self).setUp() self.user = AuthUserFactory.build( fullname='Martin Luther King Jr.', given_name='Martin', family_name='King', suffix='Jr.', social=dict( github='userOneGithub', scholar='userOneScholar', personal='http://www.useronepersonalwebsite.com', twitter='userOneTwitter', linkedIn='userOneLinkedIn', impactStory='userOneImpactStory', orcid='userOneOrcid', researcherId='userOneResearcherId' ) ) self.url = '/{}users/{}/'.format(API_BASE, self.user._id) self.user_two = AuthUserFactory()
def setUp(self): super(TestUserUpdate, self).setUp() self.user_one = AuthUserFactory.build( fullname="Martin Luther King Jr.", given_name="Martin", family_name="King", suffix="Jr.", social=dict( github="userOneGithub", scholar="userOneScholar", personal="http://www.useronepersonalwebsite.com", twitter="userOneTwitter", linkedIn="userOneLinkedIn", impactStory="userOneImpactStory", orcid="userOneOrcid", researcherId="userOneResearcherId", ), ) self.user_one.save() self.user_one_url = "/v2/users/{}/".format(self.user_one._id) self.user_two = AuthUserFactory() self.user_two.save() self.new_user_one_data = { "data": { "type": "users", "id": self.user_one._id, "attributes": { "full_name": "el-Hajj Malik el-Shabazz", "given_name": "Malcolm", "middle_names": "Malik el-Shabazz", "family_name": "X", "suffix": "Sr.", "gitHub": "newGitHub", "scholar": "newScholar", "personal_website": "http://www.newpersonalwebsite.com", "twitter": "http://www.newpersonalwebsite.com", "linkedIn": "newLinkedIn", "impactStory": "newImpactStory", "orcid": "newOrcid", "researcherId": "newResearcherId", }, } } self.missing_id = { "data": {"type": "users", "attributes": {"full_name": "el-Hajj Malik el-Shabazz", "family_name": "Z"}} } self.missing_type = { "data": { "id": self.user_one._id, "attributes": {"fullname": "el-Hajj Malik el-Shabazz", "family_name": "Z"}, } } self.incorrect_id = { "data": { "id": "12345", "type": "users", "attributes": {"full_name": "el-Hajj Malik el-Shabazz", "family_name": "Z"}, } } self.incorrect_type = { "data": { "id": self.user_one._id, "type": "Wrong type.", "attributes": {"full_name": "el-Hajj Malik el-Shabazz", "family_name": "Z"}, } }
def create_user(self): return AuthUserFactory.build()