Example #1
0
    def test_reset_password(self):
        uid, name, email, code = 'UID', 'NAME', 'EM@IL', 'THE_CODE'
        params = {'name': 'USERNAME', 'link-template': 'LINK_TEMPLATE'}
        user = doubles.make(self.mox,
                            doubles.User,
                            name=name,
                            id=uid,
                            email=email,
                            fullname='')
        token = Token(user_id=uid, email=email, code=code)

        ConfigDAO.get('password-reset', 'enabled').AndReturn(True)
        me._find_user(params).AndReturn(user)
        me.ResetTokensDAO.create(uid, email).AndReturn(token)
        me.send_reset_password(email,
                               code,
                               name,
                               link_template='LINK_TEMPLATE',
                               greeting='')

        self.mox.ReplayAll()
        rv = self.client.post('/v1/me/reset-password',
                              data=json.dumps(params),
                              content_type='application/json')
        self.check_and_parse_response(rv, status_code=204)
Example #2
0
    def test_user_to_view_invite(self):
        user = doubles.make(self.mox,
                            doubles.User,
                            id=u'42',
                            name=u'iv',
                            email=u'*****@*****.**',
                            fullname=u'Example User',
                            enabled=False)
        date = datetime(2012, 9, 15, 15, 03, 00)
        invite = Token(user_id=user.id, created_at=date, complete=False)

        user.list_roles().AndReturn([])
        users.InvitesDAO.get_for_user(user.id).AndReturn(invite)

        expected = {
            u'id': u'42',
            u'name': u'iv',
            u'href': u'/v1/users/42',
            u'email': u'*****@*****.**',
            u'fullname': 'Example User',
            u'admin': False,
            u'projects': [],
            u'completed-registration': False,
            u'invited-at': date,
            u'links': {
                u'send-invite': '/v1/users/42/send-invite',
                u'ssh-keys': '/v1/users/42/ssh-keys/',
            }
        }

        self.mox.ReplayAll()
        with self.app.test_request_context():
            self.install_fake_auth()
            data = users.user_to_view(user)
        self.assertEquals(data, expected)
Example #3
0
    def test_apply_password_reset_complete(self):
        uid, code = 'UID', 'THE_CODE'
        token = Token(user_id=uid, code=code, complete=True)
        params = {'password': '******'}

        ConfigDAO.get('password-reset', 'enabled').AndReturn(True)
        me.ResetTokensDAO.get('THE_CODE').AndReturn(token)
        self.mox.ReplayAll()
        rv = self.client.post('/v1/me/reset-password/%s' % code,
                              data=json.dumps(params),
                              content_type='application/json')
        self.check_and_parse_response(rv, status_code=404)
Example #4
0
    def setUp(self):
        super(InvitesTestCase, self).setUp()
        self.mox.StubOutWithMock(invites, 'InvitesDAO')
        self.mox.StubOutWithMock(invites, 'user_to_view')
        self.mox.StubOutWithMock(invites.auth, 'admin_client_set')

        self.code = '42'
        self.token = Token(code=self.code, complete=False, user_id='UID')
        self.user = doubles.make(self.mox,
                                 doubles.User,
                                 id='UID',
                                 name='self.user',
                                 enabled=False)

        self.fake_client_set = self._fake_client_set_factory()
Example #5
0
    def setUp(self):
        super(SendInviteTestCase, self).setUp()
        self.mox.StubOutWithMock(users, 'user_to_view')
        self.mox.StubOutWithMock(users, 'send_invitation')
        self.mox.StubOutWithMock(users, 'InvitesDAO')
        self.mox.StubOutWithMock(users, 'update_user_data')
        self.mox.StubOutWithMock(users.auth, 'assert_admin')
        self.mox.StubOutWithMock(ConfigDAO, 'get')

        self.uid = 'UID'
        self.user = doubles.make(self.mox,
                                 doubles.User,
                                 id=self.uid,
                                 email='*****@*****.**',
                                 fullname='Test User')
        self.invite = Token(user_id=self.uid, code='THE_CODE', complete=False)
Example #6
0
    def test_user_to_view_send_invite_code(self):
        """What we got when resending invite without disabling user"""
        user = doubles.make(self.mox,
                            doubles.User,
                            id=u'42',
                            name=u'iv',
                            email=u'*****@*****.**',
                            fullname=u'Example User',
                            enabled=True)
        date = datetime(2012, 9, 15, 15, 03, 00)
        invite = Token(user_id=user.id,
                       created_at=date,
                       complete=False,
                       code='THE_CODE')

        user.list_roles().AndReturn([])
        expected = {
            u'id': u'42',
            u'name': u'iv',
            u'href': u'/v1/users/42',
            u'email': u'*****@*****.**',
            u'fullname': 'Example User',
            u'admin': False,
            u'projects': [],
            u'completed-registration': True,  # because user can work
            u'invited-at': date,
            u'invitation-code': 'THE_CODE',
            u'links': {
                u'send-invite': '/v1/users/42/send-invite',
                u'ssh-keys': '/v1/users/42/ssh-keys/',
            }
        }

        self.mox.ReplayAll()
        with self.app.test_request_context():
            self.install_fake_auth()
            data = users.user_to_view(user, invite, send_code=True)
        self.assertEquals(data, expected)