-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ec0bcb
commit 045c310
Showing
4 changed files
with
103 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from pydantic import BaseModel | ||
|
||
from pymailtm.api.credentials import Credentials | ||
from pymailtm.api.connection_manager import ConnectionManager | ||
|
||
|
||
class Account(BaseModel): | ||
id: str | ||
address: str | ||
quota: int | ||
used: int | ||
isDisabled: bool | ||
isDeleted: bool | ||
createdAt: str | ||
updatedAt: str | ||
|
||
|
||
class AccountController: | ||
|
||
def __init__(self, connection_manager: ConnectionManager): | ||
self.connection_manager = connection_manager | ||
self.endpoint = "accounts" | ||
|
||
def create_account(self, credentials: Credentials) -> Account: | ||
response = self.connection_manager.post( | ||
self.endpoint, | ||
{ | ||
"address": credentials.address, | ||
"password": credentials.password, | ||
}, | ||
) | ||
return Account(**response.json()) |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pytest | ||
|
||
from conftest import BASE_URL | ||
|
||
from pymailtm.api.account import AccountController | ||
from pymailtm.api.credentials import Credentials | ||
from pymailtm.api.connection_manager import ConnectionManager | ||
|
||
|
||
class TestAnAccountController: | ||
"""Test: An Account Controller...""" | ||
|
||
ac: AccountController | ||
|
||
@pytest.fixture(scope="class", autouse=True) | ||
def setup(self, request): | ||
"""TestAnAccountController setup""" | ||
request.cls.ac = AccountController(ConnectionManager(BASE_URL)) | ||
|
||
def test_should_be_able_to_create_a_new_account(self, mock_api, mocks): | ||
"""An account controller should be able to create a new account.""" | ||
# set up the api mock | ||
mock_api.post(f"{BASE_URL}/accounts", json=mocks.json_account) | ||
credentials = Credentials(address="user@domain.test", password="password") | ||
|
||
# create a new account | ||
account = self.ac.create_account(credentials) | ||
assert account == mocks.account | ||
assert credentials.address | ||
assert credentials.password |
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