def logged_in_username(self): if not hasattr(self, "_username"): username = self.get_secure_cookie("username") if username != None: try: users.lookup_user_id(self.db_session(), username) except NotFound: username = None self._username = username return self._username
def get_and_check_user_id(self, username): if username != self.logged_in_username and \ self.request.headers.get("NGV-API-Key", None) != settings.API_KEY: raise HTTPError(403, "Username doesn't match logged in username.") try: return users.lookup_user_id(self.db_session(), username) except NotFound: raise HTTPError(404, "User not found.")
def get_and_check_user_id(self, username): # pragma: no cover if username != self.logged_in_username and \ self.request.headers.get("NGV-API-Key", None) != settings.API_KEY: raise HTTPError(403, "Username doesn't match logged in username.") try: return users.lookup_user_id(self.db_session(), username) except NotFound: raise HTTPError(404, "User not found.")
def test_lookup_user_id(self): self.mock_cursor.fetchone.return_value = ("1234567890abcdefg", ) id = users.lookup_user_id(self.mock_session, "*****@*****.**") self.mock_session.execute.assert_called_once_with( ANY, {"email": "*****@*****.**"}) self.assertEquals(id, "1234567890abcdefg")
def test_lookup_user_id(self): self.mock_cursor.fetchone.return_value = ("1234567890abcdefg",) id = users.lookup_user_id(self.mock_session, "*****@*****.**") self.mock_session.execute.assert_called_once_with(ANY, {"email": "*****@*****.**"}) self.assertEquals(id, "1234567890abcdefg")