-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-4: Require authorized credentials for API
- Loading branch information
1 parent
5d23916
commit e8c3705
Showing
5 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,28 @@ | ||
from base64 import b64encode | ||
|
||
import requests | ||
|
||
|
||
class AppClient: | ||
DEFAULT_TIMEOUT = 10 | ||
|
||
def __init__(self, url: str): | ||
def __init__(self, url: str, username: str, password: str): | ||
self._url = url | ||
credentials = f"{username}:{password}" | ||
self._authorization = f"Basic {b64encode(credentials.encode()).decode()}" | ||
|
||
def add_user(self, email: str) -> None: | ||
users = [{"email": email}] | ||
response = requests.post(f"{self._url}/users", json=users, timeout=self.DEFAULT_TIMEOUT) | ||
response = requests.post( | ||
f"{self._url}/users", | ||
headers={"Authorization": self._authorization}, | ||
json=users, | ||
timeout=self.DEFAULT_TIMEOUT, | ||
) | ||
assert response.status_code == 201 | ||
|
||
def clear_users(self) -> None: | ||
response = requests.delete(f"{self._url}/users", timeout=self.DEFAULT_TIMEOUT) | ||
response = requests.delete( | ||
f"{self._url}/users", headers={"Authorization": self._authorization}, timeout=self.DEFAULT_TIMEOUT | ||
) | ||
assert response.status_code == 204 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters