def test_authenticate_user_not_valid_for_this_app(self): self.db.query(User).delete() UserFactory(email='*****@*****.**') mock_response = Mock( code=200, body='{"issued_to": "222", "email": "*****@*****.**"}' ) def handle_request(url, handler, proxy_host, proxy_port): handler(mock_response) fetch_mock = Mock() fetch_mock.side_effect = handle_request config = Config() config.GOOGLE_CLIENT_ID = '000' access_token = '111' User.authenticate( access_token, fetch_mock, self.db, config, callback=self.stop ) response = self.wait() expect(response.get('status')).to_equal(401) expect(response.get('reason')).to_equal( "Token's client ID does not match app's." )
def test_authenticate_unauthorized_user(self): self.db.query(User).delete() mock_response = Mock( code=200, body='{"issued_to": "000", "email": "*****@*****.**"}' ) def handle_request(url, handler, proxy_host, proxy_port): handler(mock_response) fetch_mock = Mock() fetch_mock.side_effect = handle_request config = Config() config.GOOGLE_CLIENT_ID = '000' access_token = '111' User.authenticate( access_token, fetch_mock, self.db, config, callback=self.stop ) response = self.wait() expect(response.get('status')).to_equal(403) expect(response.get('reason')).to_equal('Unauthorized user')
def test_authenticate(self, datetime_mock): dt = datetime(2014, 2, 14, 15, 0, 30) datetime_mock.now.return_value = dt self.db.query(User).delete() UserFactory(email='*****@*****.**') mock_response = Mock( code=200, body='{"issued_to": "000", "email": "*****@*****.**"}' ) def handle_request(url, handler, proxy_host, proxy_port): handler(mock_response) fetch_mock = Mock() fetch_mock.side_effect = handle_request config = Config() config.GOOGLE_CLIENT_ID = '000' access_token = '111' User.authenticate( access_token, fetch_mock, self.db, config, callback=self.stop ) response = self.wait() expect(response).to_be_like({ 'status': 200, 'user': { 'is_superuser': True, 'fullname': u'Marcelo Jorge Vieira', 'last_login': dt, 'email': u'*****@*****.**' } }) loaded_user = User.by_email('*****@*****.**', self.db) expect(loaded_user.last_login).to_equal(dt)
def test_authenticate_invalid_token(self): self.db.query(User).delete() UserFactory(email='*****@*****.**') mock_response = Mock( code=400, body=dumps({ "error": "invalid_token", "error_description": "Invalid Value" }) ) def handle_request(url, handler, proxy_host, proxy_port): handler(mock_response) fetch_mock = Mock() fetch_mock.side_effect = handle_request config = Config() config.GOOGLE_CLIENT_ID = '000' access_token = '111' User.authenticate( access_token, fetch_mock, self.db, config, callback=self.stop ) response = self.wait() expect(response).to_be_like({ 'status': 400, 'reason': 'Error', 'details': '{"error_description":"Invalid Value", \ "error":"invalid_token"}' })