Exemplo n.º 1
0
    def test_send_with_sendgrid_success(self):
        mock_client = mock.MagicMock()
        mock_client.send.return_value = 200, 'success'
        from_addr, to_addr = fake.email(), fake.email()
        category1, category2 = fake.word(), fake.word()
        subject = fake.bs()
        message = fake.text()
        ret = _send_with_sendgrid(from_addr=from_addr,
                                  to_addr=to_addr,
                                  subject=subject,
                                  message=message,
                                  mimetype='txt',
                                  client=mock_client,
                                  categories=(category1, category2))
        assert_true(ret)

        assert_equal(mock_client.send.call_count, 1)
        # First call's argument should be a Mail object with
        # the correct configuration
        first_call_arg = mock_client.send.call_args[0][0]
        assert_is_instance(first_call_arg, sendgrid.Mail)
        assert_equal(first_call_arg.from_email, from_addr)
        assert_equal(first_call_arg.to[0], to_addr)
        assert_equal(first_call_arg.subject, subject)
        assert_equal(first_call_arg.text, message)
        # Categories are set
        assert_equal(first_call_arg.smtpapi.data['category'],
                     (category1, category2))
Exemplo n.º 2
0
    def test_send_with_sendgrid_success(self):
        mock_client = mock.MagicMock()
        mock_client.send.return_value = 200, 'success'
        from_addr, to_addr = fake.email(), fake.email()
        category1, category2 = fake.word(), fake.word()
        subject = fake.bs()
        message = fake.text()
        ret = _send_with_sendgrid(
            from_addr=from_addr,
            to_addr=to_addr,
            subject=subject,
            message=message,
            mimetype='txt',
            client=mock_client,
            categories=(category1, category2)
        )
        assert_true(ret)

        mock_client.send.assert_called_once()
        # First call's argument should be a Mail object with
        # the correct configuration
        first_call_arg = mock_client.send.call_args[0][0]
        assert_is_instance(first_call_arg, sendgrid.Mail)
        assert_equal(first_call_arg.from_email, from_addr)
        assert_equal(first_call_arg.to[0], to_addr)
        assert_equal(first_call_arg.subject, subject)
        assert_equal(first_call_arg.text, message)
        # Categories are set
        assert_equal(first_call_arg.smtpapi.data['category'], (category1, category2))
Exemplo n.º 3
0
    def test_correct_name_shows_in_contributor_list(self):
        name1, email = fake.name(), fake.email()
        UnregUserFactory(fullname=name1, email=email)
        name2, email = fake.name(), fake.email()
        # Added with different name
        self.project.add_unregistered_contributor(fullname=name2, email=email, auth=Auth(self.referrer))
        self.project.save()

        res = self.app.get(self.project.url, auth=self.referrer.auth)
        # Correct name is shown
        assert_in_html(name2, res)
        assert_not_in(name1, res)
Exemplo n.º 4
0
    def test_correct_name_shows_in_contributor_list(self):
        name1, email = fake.name(), fake.email()
        UnregUserFactory(fullname=name1, email=email)
        name2, email = fake.name(), fake.email()
        # Added with different name
        self.project.add_unregistered_contributor(fullname=name2,
            email=email, auth=Auth(self.referrer))
        self.project.save()

        res = self.app.get(self.project.url, auth=self.referrer.auth)
        # Correct name is shown
        assert_in(name2, res)
        assert_not_in(name1, res)
Exemplo n.º 5
0
 def test_send_with_sendgrid_failure_returns_false(self):
     mock_client = mock.MagicMock()
     mock_client.send.return_value = 400, 'failed'
     from_addr, to_addr = fake.email(), fake.email()
     subject = fake.bs()
     message = fake.text()
     ret = _send_with_sendgrid(from_addr=from_addr,
                               to_addr=to_addr,
                               subject=subject,
                               message=message,
                               mimetype='txt',
                               client=mock_client)
     assert_false(ret)
Exemplo n.º 6
0
 def test_send_with_sendgrid_failure_returns_false(self):
     mock_client = mock.MagicMock()
     mock_client.send.return_value = 400, 'failed'
     from_addr, to_addr = fake.email(), fake.email()
     subject = fake.bs()
     message = fake.text()
     ret = _send_with_sendgrid(
         from_addr=from_addr,
         to_addr=to_addr,
         subject=subject,
         message=message,
         mimetype='txt',
         client=mock_client
     )
     assert_false(ret)
Exemplo n.º 7
0
    def setUp(self):
        super(PreregViewsTests, self).setUp()

        ensure_schemas()
        
        self.osf_user = factories.AuthUserFactory()
        password = fake.password(),
        self.user = User.objects.create(
            email=fake.email(),
            first_name=fake.first_name(),
            last_name=fake.last_name(),
            osf_id=self.osf_user._id
        )
        self.user.set_password(password)
        self.user.save()
        self.logged_in = self.client.login(username=self.user.email, password=password)
        PREREG_GROUP.user_set.add(self.user)
        PREREG_GROUP.save()

        self.prereg_schema = MetaSchema.find_one(
            Q('name', 'eq', 'Prereg Challenge') &
            Q('schema_version', 'eq', 2)
        )
        self.other_schema = MetaSchema.find(
            Q('name', 'ne', 'Prereg Challenge') &
            Q('schema_version', 'eq', 2)
        )[0]
Exemplo n.º 8
0
 def test_get_most_in_common_contributors(self):
     # project 1 (contrib 1, contrib 2, unreg_contrib 3)
     #  - component 1 (contrib 1)
     # project 2 - add should show contrib 1 first (2 links), contrib 2 second (1 link)
     contributor_1 = AuthUserFactory()
     contributor_2 = AuthUserFactory()
     self.project.add_contributor(contributor_1, auth=self.auth)
     self.project.add_contributor(contributor_2, auth=self.auth)
     # has one unregistered contributor
     self.project.add_unregistered_contributor(
         fullname=fake.name(),
         email=fake.email(),
         auth=self.auth,
     )
     self.project.save()
     component = NodeFactory(parent=self.project, creator=self.user)
     component.add_contributor(contributor_1, auth=self.auth)
     component.save()
     project_2 = ProjectFactory(creator=self.user)
     project_2.add_contributor(contributor_1, auth=self.auth)
     url = project_2.api_url_for('get_most_in_common_contributors')
     res = self.app.get(url, auth=self.user.auth)
     project_2.reload()
     res_contribs = res.json['contributors']
     assert_equal(len(res.json['contributors']), 2)
     assert_equal(contributor_1._id, res_contribs[0]['id'])
     assert_equal(res_contribs[0]['n_projects_in_common'], 2)
     assert_equal(contributor_2._id, res_contribs[1]['id'])
     assert_equal(res_contribs[1]['n_projects_in_common'], 1)
Exemplo n.º 9
0
    def test_user_signup_with_valid_data_succeeds(self, client, init_db,
                                                  new_company):
        """
            Parameters:
                client(FlaskClient): fixture to get flask test client
                init_db(SQLAlchemy): fixture to initialize the test database
                new_company (Company): Fixture to create a new company
        """
        payload = {
            'company_id': new_company.id,
            'email': fake.email(),
            'password': USER_ONE_VALID_PASSWORD
        }

        response = client.post(f'{BASE_URL}/users/signup',
                               data=json.dumps(payload),
                               content_type='application/json')

        response_json = json.loads(response.data.decode())
        assert response.status_code == 201
        assert response_json['status'] == 'success'
        assert response_json['message'] == SUCCESS_MESSAGES['USER_SIGNUP']

        data = response_json['data']

        assert AuthToken.decode_auth_token(data['token']) is not None

        assert data['user']['id'] is not None
        assert data['user']['email'] == payload['email']

        assert data['user']['company']['id'] == new_company.id
        assert data['user']['company']['name'] == new_company.name
Exemplo n.º 10
0
 def test_get_most_in_common_contributors(self):
     # project 1 (contrib 1, contrib 2, unreg_contrib 3)
     #  - component 1 (contrib 1)
     # project 2 - add should show contrib 1 first (2 links), contrib 2 second (1 link)
     contributor_1 = AuthUserFactory()
     contributor_2 = AuthUserFactory()
     self.project.add_contributor(contributor_1, auth=self.auth)
     self.project.add_contributor(contributor_2, auth=self.auth)
     # has one unregistered contributor
     self.project.add_unregistered_contributor(
         fullname=fake.name(),
         email=fake.email(),
         auth=self.auth,
     )
     self.project.save()
     component = NodeFactory(parent=self.project, creator=self.user)
     component.add_contributor(contributor_1, auth=self.auth)
     component.save()
     project_2 = ProjectFactory(creator=self.user)
     project_2.add_contributor(contributor_1, auth=self.auth)
     url = project_2.api_url_for('get_most_in_common_contributors')
     res = self.app.get(url, auth=self.user.auth)
     project_2.reload()
     res_contribs = res.json['contributors']
     assert_equal(len(res.json['contributors']), 2)
     assert_equal(contributor_1._id, res_contribs[0]['id'])
     assert_equal(res_contribs[0]['n_projects_in_common'], 2)
     assert_equal(contributor_2._id, res_contribs[1]['id'])
     assert_equal(res_contribs[1]['n_projects_in_common'], 1)
Exemplo n.º 11
0
    def test_cannot_go_to_claim_url_after_setting_password(self):
        name, email = fake.name(), fake.email()
        new_user = self.project.add_unregistered_contributor(
            email=email,
            fullname=name,
            auth=Auth(self.referrer)
        )
        self.project.save()
        # Goes to claim url and successfully claims account
        claim_url = new_user.get_claim_url(self.project._primary_key)
        res = self.app.get(claim_url)
        self.project.reload()
        assert_in('Set Password', res)
        form = res.forms['setPasswordForm']
        #form['username'] = new_user.username #Removed as long as the E-mail can't be changed
        form['password'] = '******'
        form['password2'] = 'killerqueen'
        res = form.submit().maybe_follow()

        # logs out
        res = self.app.get('/logout/').maybe_follow()
        # tries to go to claim url again
        res = self.app.get(claim_url, expect_errors=True)
        assert_equal(res.status_code, 400)
        assert_in('already been claimed', res)
Exemplo n.º 12
0
    def test_user_signup_with_not_strong_password_fails(
            self, client, init_db, new_company):
        """
            Parameters:
                client(FlaskClient): fixture to get flask test client
                init_db(SQLAlchemy): fixture to initialize the test database
                new_company (Company): Fixture to create a new company
        """

        #payload with not strong password
        payload = {
            'company_id': new_company.id,
            'email': fake.email(),
            'password': '******',
        }

        response = client.post(f'{BASE_URL}/users/signup',
                               data=json.dumps(payload),
                               content_type='application/json')

        data = json.loads(response.data.decode())
        assert response.status_code == 400
        assert data['status'] == 'error'
        assert data['message'] == ERROR_MESSAGES['DEFAULT']
        assert data['errors'] == dict(
            password=[ERROR_MESSAGES['NOT_STRONG_PASSWORD']])
Exemplo n.º 13
0
 def setUp(self):
     super(TestClaimingAsARegisteredUser, self).setUp()
     self.referrer = AuthUserFactory()
     self.project = ProjectFactory(creator=self.referrer, is_public=True)
     name, email = fake.name(), fake.email()
     self.user = self.project.add_unregistered_contributor(fullname=name, email=email, auth=Auth(user=self.referrer))
     self.project.save()
Exemplo n.º 14
0
 def setUp(self):
     super(TestClaimingAsARegisteredUser, self).setUp()
     self.referrer = AuthUserFactory()
     self.project = ProjectFactory(creator=self.referrer, is_public=True)
     name, email = fake.name(), fake.email()
     self.user = self.project.add_unregistered_contributor(
         fullname=name, email=email, auth=Auth(user=self.referrer))
     self.project.save()
Exemplo n.º 15
0
def new_user(app, new_company):
    params = {
        'company_id': new_company.id,
        'email': fake.email(),
        'password': fake.password()
    }
    user = User(**params)
    return user.save()
Exemplo n.º 16
0
    def test_add_unconfirmed_email_when_email_verifications_is_None(self):

        self.user.email_verifications = None
        self.user.save()
        email = fake.email()
        self.user.add_unconfirmed_email(email)
        self.user.save()
        assert_in(email, self.user.unconfirmed_emails)
Exemplo n.º 17
0
    def test_add_unconfirmed_email_when_email_verifications_is_None(self):

        self.user.email_verifications = None
        self.user.save()
        email = fake.email()
        self.user.add_unconfirmed_email(email)
        self.user.save()
        assert_in(email, self.user.unconfirmed_emails)
Exemplo n.º 18
0
def user_one(app, new_company):
    params = {
        'company_id': new_company.id,
        'email': fake.email(),
        'password': '******'
    }
    user = User(**params)
    return user.save()
Exemplo n.º 19
0
 def test_sees_is_redirected_if_user_already_logged_in(self):
     name, email = fake.name(), fake.email()
     new_user = self.project.add_unregistered_contributor(email=email, fullname=name, auth=Auth(self.referrer))
     self.project.save()
     existing = AuthUserFactory()
     claim_url = new_user.get_claim_url(self.project._primary_key)
     # a user is already logged in
     res = self.app.get(claim_url, auth=existing.auth, expect_errors=True)
     assert_equal(res.status_code, 302)
Exemplo n.º 20
0
 def test_sees_is_redirected_if_user_already_logged_in(self):
     name, email = fake.name(), fake.email()
     new_user = self.project.add_unregistered_contributor(
         email=email, fullname=name, auth=Auth(self.referrer))
     self.project.save()
     existing = AuthUserFactory()
     claim_url = new_user.get_claim_url(self.project._primary_key)
     # a user is already logged in
     res = self.app.get(claim_url, auth=existing.auth, expect_errors=True)
     assert_equal(res.status_code, 302)
Exemplo n.º 21
0
 def test_get_recently_added_contributors(self):
     project = ProjectFactory(creator=self.user)
     project.add_contributor(AuthUserFactory(), auth=self.auth)
     project.add_contributor(AuthUserFactory(), auth=self.auth)
     # has one unregistered contributor
     project.add_unregistered_contributor(fullname=fake.name(), email=fake.email(), auth=self.auth)
     project.save()
     url = self.project.api_url_for("get_recently_added_contributors")
     res = self.app.get(url, auth=self.user.auth)
     project.reload()
     recent = [c for c in self.user.recently_added if c.is_active]
     assert_equal(len(res.json["contributors"]), len(recent))
Exemplo n.º 22
0
 def test_save(self, init_db, new_company):
     """Test for creating a new user
     
         Args:
             init_db(SQLAlchemy): fixture to initialize the test database
             new_company (Company): Fixture to create a new company
     """
     params = {
         'company_id' : new_company.id,
         'email': fake.email(),
         'password' : fake.password()
     }
     user = User(**params)
     assert user == user.save()
Exemplo n.º 23
0
def create_fake_user():
    email = fake.email()
    name = fake.name()
    parsed = impute_names(name)
    user = UserFactory(username=email,
                       fullname=name,
                       is_registered=True,
                       is_claimed=True,
                       date_registered=fake.date_time(),
                       emails=[email],
                       **parsed)
    user.set_password('faker123')
    user.save()
    return user
Exemplo n.º 24
0
 def test_update_published_does_not_send_contributor_added_for_inactive_users(
         self):
     unpublished = PreprintFactory(creator=self.user, is_published=False)
     unpublished.node.add_unregistered_contributor(fullname=fake.name(),
                                                   email=fake.email(),
                                                   auth=Auth(self.user),
                                                   save=True)
     url = '/{}preprints/{}/'.format(API_BASE, unpublished._id)
     payload = build_preprint_update_payload(
         unpublished._id, attributes={'is_published': True})
     with capture_signals() as captured:
         res = self.app.patch_json_api(url, payload, auth=self.user.auth)
         # Signal not sent, because contributor is not registered
         assert_false(captured[contributor_added])
Exemplo n.º 25
0
def create_fake_user():
    email = fake.email()
    name = fake.name()
    parsed = impute_names(name)
    user = UserFactory(username=email,
                       fullname=name,
                       is_registered=True,
                       is_claimed=True,
                       verification_key=security.random_string(15),
                       date_registered=fake.date_time(),
                       emails=[email],
                       **parsed)
    user.set_password('faker123')
    user.save()
    return user
Exemplo n.º 26
0
 def test_user_can_set_password_on_claim_page(self):
     name, email = fake.name(), fake.email()
     new_user = self.project.add_unregistered_contributor(email=email, fullname=name, auth=Auth(self.referrer))
     self.project.save()
     claim_url = new_user.get_claim_url(self.project._primary_key)
     res = self.app.get(claim_url)
     self.project.reload()
     assert_in("Set Password", res)
     form = res.forms["setPasswordForm"]
     # form['username'] = new_user.username #Removed as long as E-mail can't be updated.
     form["password"] = "******"
     form["password2"] = "killerqueen"
     res = form.submit().follow()
     new_user.reload()
     assert_true(new_user.check_password("killerqueen"))
Exemplo n.º 27
0
    def test_unregistered_users_names_are_project_specific(self):
        name1, name2, email = fake.name(), fake.name(), fake.email()
        project2 = ProjectFactory(creator=self.referrer)
        # different projects use different names for the same unreg contributor
        self.project.add_unregistered_contributor(email=email, fullname=name1, auth=Auth(self.referrer))
        self.project.save()
        project2.add_unregistered_contributor(email=email, fullname=name2, auth=Auth(self.referrer))
        project2.save()
        self.app.authenticate(*self.referrer.auth)
        # Each project displays a different name in the contributor list
        res = self.app.get(self.project.url)
        assert_in_html(name1, res)

        res2 = self.app.get(project2.url)
        assert_in_html(name2, res2)
Exemplo n.º 28
0
 def test_user_can_set_password_on_claim_page(self):
     name, email = fake.name(), fake.email()
     new_user = self.project.add_unregistered_contributor(
         email=email, fullname=name, auth=Auth(self.referrer))
     self.project.save()
     claim_url = new_user.get_claim_url(self.project._primary_key)
     res = self.app.get(claim_url)
     self.project.reload()
     assert_in('Set Password', res)
     form = res.forms['setPasswordForm']
     #form['username'] = new_user.username #Removed as long as E-mail can't be updated.
     form['password'] = '******'
     form['password2'] = 'killerqueen'
     res = form.submit().follow()
     new_user.reload()
     assert_true(new_user.check_password('killerqueen'))
Exemplo n.º 29
0
 def test_get_recently_added_contributors(self):
     project = ProjectFactory(creator=self.user)
     project.add_contributor(AuthUserFactory(), auth=self.auth)
     project.add_contributor(AuthUserFactory(), auth=self.auth)
     # has one unregistered contributor
     project.add_unregistered_contributor(
         fullname=fake.name(),
         email=fake.email(),
         auth=self.auth,
     )
     project.save()
     url = self.project.api_url_for('get_recently_added_contributors')
     res = self.app.get(url, auth=self.user.auth)
     project.reload()
     recent = [c for c in self.user.recently_added if c.is_active()]
     assert_equal(len(res.json['contributors']), len(recent))
Exemplo n.º 30
0
def create_fake_user():
    email = fake.email()
    name = fake.name()
    parsed = impute_names(name)
    user = UserFactory(
        username=email,
        fullname=name,
        is_registered=True,
        is_claimed=True,
        date_registered=fake.date_time(),
        emails=[email],
        **parsed
    )
    user.set_password('faker123')
    user.save()
    return user
Exemplo n.º 31
0
 def test_was_invited(self):
     referrer = UserFactory()
     node = NodeFactory(creator=referrer)
     name = fake.name()
     email = fake.email()
     user = node.add_unregistered_contributor(
         fullname=name,
         email=email,
         auth=Auth(user=referrer),
     )
     user.register(email, 'secret')
     assert_true(is_invited(user))
     user.is_invited = None
     user.save()
     main(dry_run=False)
     user.reload()
     assert_true(user.is_invited)
Exemplo n.º 32
0
 def test_was_invited(self):
     referrer = UserFactory()
     node = NodeFactory(creator=referrer)
     name = fake.name()
     email = fake.email()
     user = node.add_unregistered_contributor(
         fullname=name,
         email=email,
         auth=Auth(user=referrer),
     )
     user.register(email, 'secret')
     assert_true(is_invited(user))
     user.is_invited = None
     user.save()
     main(dry_run=False)
     user.reload()
     assert_true(user.is_invited)
Exemplo n.º 33
0
 def test_cannot_set_email_to_a_user_that_already_exists(self):
     reg_user = UserFactory()
     name, email = fake.name(), fake.email()
     new_user = self.project.add_unregistered_contributor(email=email, fullname=name, auth=Auth(self.referrer))
     self.project.save()
     # Goes to claim url and successfully claims account
     claim_url = new_user.get_claim_url(self.project._primary_key)
     res = self.app.get(claim_url)
     self.project.reload()
     assert_in("Set Password", res)
     form = res.forms["setPasswordForm"]
     # Fills out an email that is the username of another user
     form["username"] = reg_user.username
     form["password"] = "******"
     form["password2"] = "killerqueen"
     res = form.submit().maybe_follow(expect_errors=True)
     assert_in(language.ALREADY_REGISTERED.format(email=reg_user.username), res)
Exemplo n.º 34
0
def create_fake_user():
    email = fake.email()
    name = fake.name()
    parsed = impute_names(name)
    user = UserFactory(
        username=email,
        fullname=name,
        is_registered=True,
        is_claimed=True,
        verification_key=security.random_string(15),
        date_registered=fake.date_time(),
        emails=[email],
        **parsed
    )
    user.set_password('faker123')
    user.save()
    return user
Exemplo n.º 35
0
 def test_user_can_set_password_on_claim_page(self):
     name, email = fake.name(), fake.email()
     new_user = self.project.add_unregistered_contributor(
         email=email, fullname=name, auth=Auth(self.referrer))
     self.project.save()
     claim_url = new_user.get_claim_url(self.project._primary_key)
     res = self.app.get(claim_url)
     self.project.reload()
     assert_in('Set Password', res)
     form = res.forms['setPasswordForm']
     form['username'] = new_user.username
     form['password'] = '******'
     form['password2'] = 'killerqueen'
     res = form.submit().maybe_follow()
     new_user.reload()
     # at settings page
     assert_equal(res.request.path, '/settings/')
     assert_in('Welcome to the OSF', res)
Exemplo n.º 36
0
 def test_unregistered_user_can_create_an_account(self):
     # User is added as an unregistered contributor to a project
     email, name = fake.email(), fake.name()
     self.project.add_unregistered_contributor(email=email,
                                               fullname=name,
                                               auth=Auth(self.referrer))
     self.project.save()
     # Goes to registration page (instead of claiming their email)
     res = self.app.get('/account/').maybe_follow()
     form = res.forms['registerForm']
     form['register-fullname'] = name
     form['register-username'] = email
     form['register-username2'] = email
     form['register-password'] = '******'
     form['register-password2'] = 'example'
     res = form.submit()
     # registered successfully
     assert_in(language.REGISTRATION_SUCCESS.format(email=email), res)
Exemplo n.º 37
0
    def test_unregistered_users_names_are_project_specific(self):
        name1, name2, email = fake.name(), fake.name(), fake.email()
        project2 = ProjectFactory(creator=self.referrer)
        # different projects use different names for the same unreg contributor
        self.project.add_unregistered_contributor(email=email,
                                                  fullname=name1,
                                                  auth=Auth(self.referrer))
        self.project.save()
        project2.add_unregistered_contributor(email=email,
                                              fullname=name2,
                                              auth=Auth(self.referrer))
        project2.save()
        self.app.authenticate(*self.referrer.auth)
        # Each project displays a different name in the contributor list
        res = self.app.get(self.project.url)
        assert_in(name1, res)

        res2 = self.app.get(project2.url)
        assert_in(name2, res2)
Exemplo n.º 38
0
 def test_cannot_set_email_to_a_user_that_already_exists(self):
     reg_user = UserFactory()
     name, email = fake.name(), fake.email()
     new_user = self.project.add_unregistered_contributor(
         email=email, fullname=name, auth=Auth(self.referrer))
     self.project.save()
     # Goes to claim url and successfully claims account
     claim_url = new_user.get_claim_url(self.project._primary_key)
     res = self.app.get(claim_url)
     self.project.reload()
     assert_in('Set Password', res)
     form = res.forms['setPasswordForm']
     # Fills out an email that is the username of another user
     form['username'] = reg_user.username
     form['password'] = '******'
     form['password2'] = 'killerqueen'
     res = form.submit().maybe_follow(expect_errors=True)
     assert_in(language.ALREADY_REGISTERED.format(email=reg_user.username),
               res)
Exemplo n.º 39
0
 def test_unregistered_user_can_create_an_account(self):
     # User is added as an unregistered contributor to a project
     email, name = fake.email(), fake.name()
     self.project.add_unregistered_contributor(
         email=email,
         fullname=name,
         auth=Auth(self.referrer)
     )
     self.project.save()
     # Goes to registration page (instead of claiming their email)
     res = self.app.get('/account/').maybe_follow()
     form = res.forms['registerForm']
     form['register-fullname'] = name
     form['register-username'] = email
     form['register-username2'] = email
     form['register-password'] = '******'
     form['register-password2'] = 'example'
     res = form.submit()
     # registered successfully
     assert_in(language.REGISTRATION_SUCCESS.format(email=email), res)
Exemplo n.º 40
0
 def test_user_can_set_password_on_claim_page(self):
     name, email = fake.name(), fake.email()
     new_user = self.project.add_unregistered_contributor(
         email=email,
         fullname=name,
         auth=Auth(self.referrer)
     )
     self.project.save()
     claim_url = new_user.get_claim_url(self.project._primary_key)
     res = self.app.get(claim_url)
     self.project.reload()
     assert_in('Set Password', res)
     form = res.forms['setPasswordForm']
     #form['username'] = new_user.username #Removed as long as E-mail can't be updated.
     form['password'] = '******'
     form['password2'] = 'killerqueen'
     res = form.submit().maybe_follow()
     new_user.reload()
     # at settings page
     assert_equal(res.request.path, '/settings/')
     assert_in('Welcome to the OSF', res)
Exemplo n.º 41
0
    def test_cannot_go_to_claim_url_after_setting_password(self):
        name, email = fake.name(), fake.email()
        new_user = self.project.add_unregistered_contributor(
            email=email, fullname=name, auth=Auth(self.referrer))
        self.project.save()
        # Goes to claim url and successfully claims account
        claim_url = new_user.get_claim_url(self.project._primary_key)
        res = self.app.get(claim_url)
        self.project.reload()
        assert_in('Set Password', res)
        form = res.forms['setPasswordForm']
        form['username'] = new_user.username
        form['password'] = '******'
        form['password2'] = 'killerqueen'
        res = form.submit().maybe_follow()

        # logs out
        res = self.app.get('/logout/').maybe_follow()
        # tries to go to claim url again
        res = self.app.get(claim_url, expect_errors=True)
        assert_equal(res.status_code, 400)
        assert_in('already been claimed', res)
Exemplo n.º 42
0
    def setUp(self):
        super(PreregViewsTests, self).setUp()

        ensure_schemas()

        self.osf_user = factories.AuthUserFactory()
        password = fake.password(),
        self.user = User.objects.create(email=fake.email(),
                                        first_name=fake.first_name(),
                                        last_name=fake.last_name(),
                                        osf_id=self.osf_user._id)
        self.user.set_password(password)
        self.user.save()
        self.logged_in = self.client.login(username=self.user.email,
                                           password=password)
        PREREG_GROUP.user_set.add(self.user)
        PREREG_GROUP.save()

        self.prereg_schema = MetaSchema.find_one(
            Q('name', 'eq', 'Prereg Challenge') & Q('schema_version', 'eq', 2))
        self.other_schema = MetaSchema.find(
            Q('name', 'ne', 'Prereg Challenge')
            & Q('schema_version', 'eq', 2))[0]