Пример #1
0
    def test_login(self, db_client):
        user, token = yield User.login(USERS[0]['email'], 'password0')

        assert user.id == USERS[0]['_id']
        assert token

        saved_token = db_client().save_doc.call_args[0][0]

        assert saved_token['_id'] == token
        assert saved_token['user_id'] == user.id
Пример #2
0
    def test_login(self, db_client):
        user, token = yield User.login(USERS[0]['email'], 'password0')

        assert user.id == USERS[0]['_id']
        assert token

        saved_token = db_client().save_doc.call_args[0][0]

        assert saved_token['_id'] == token
        assert saved_token['user_id'] == user.id
Пример #3
0
    def post(self):
        """Create token"""
        # TODO: what if unverified user?
        data = self.get_json_body(required=['email', 'password'])
        try:
            user, token = yield User.login(data['email'], data['password'])
        except Unauthorized:
            raise HTTPError(401, 'Invalid email and/or password')

        self.finish({
            'status': 200,
            'data': {
                'token': token,
                'user': user.clean()
            }
        })
Пример #4
0
    def post(self):
        """Create token"""
        # TODO: what if unverified user?
        data = self.get_json_body(required=['email', 'password'])
        try:
            user, token = yield User.login(data['email'], data['password'])
        except Unauthorized:
            raise HTTPError(401, 'Invalid email and/or password')

        self.finish({
            'status': 200,
            'data': {
                'token': token,
                'user': user.clean()
            }
        })
Пример #5
0
 def test_login_unverified_user(self, db_client):
     """Check logging in an unverified user doesn't raise an exception"""
     # TODO: should we allow unverified users to login?
     yield User.login(UNVERIFIED_USER['email'], 'password1')
Пример #6
0
 def test_login_incorrect_email(self, db_client):
     with pytest.raises(exceptions.Unauthorized):
         yield User.login('does not exist', 'password')
Пример #7
0
 def test_login_incorrect_password(self, db_client):
     with pytest.raises(exceptions.Unauthorized):
         yield User.login(USERS[0]['email'], 'password1')
Пример #8
0
 def test_login_unverified_user(self, db_client):
     """Check logging in an unverified user doesn't raise an exception"""
     # TODO: should we allow unverified users to login?
     yield User.login(UNVERIFIED_USER['email'], 'password1')
Пример #9
0
 def test_login_incorrect_email(self, db_client):
     with pytest.raises(exceptions.Unauthorized):
         yield User.login('does not exist', 'password')
Пример #10
0
 def test_login_incorrect_password(self, db_client):
     with pytest.raises(exceptions.Unauthorized):
         yield User.login(USERS[0]['email'], 'password1')