-
Notifications
You must be signed in to change notification settings - Fork 6
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
2bccf93
commit db3af7a
Showing
5 changed files
with
88 additions
and
11 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,4 +1,5 @@ | ||
black | ||
fastapi | ||
uvicorn[standard] | ||
db-sqlite3 | ||
db-sqlite3 | ||
pytest |
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,26 @@ | ||
from db import DB, Paste | ||
from typing import Any | ||
|
||
|
||
class Service: | ||
""" | ||
Service | ||
'business layer' of the Pastebin API | ||
Will interact with a requester (API routes) and the Database | ||
unit test coverage should be around 100% | ||
""" | ||
|
||
def __init__(self, db: DB = None): | ||
self._db = db if db is not None else DB() | ||
|
||
def save(self, content: Any, badge: str = "") -> str: | ||
p = Paste(badge=badge, paste=content) | ||
return self._db.insert_paste(paste=p) | ||
|
||
def retrieve_by_id(self, id: str): | ||
... |
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,18 @@ | ||
import pytest | ||
from service import Service | ||
from db import Paste | ||
|
||
PASTE_CONTENT = "a sample paste" | ||
HASHED_CONTENT_FIRST_SIX_CHARS = "b054cd" | ||
|
||
|
||
class Mock_db: | ||
def insert_paste(self, paste: Paste) -> str: | ||
return HASHED_CONTENT_FIRST_SIX_CHARS | ||
|
||
|
||
def test_simple_insert(): | ||
svc = Service(db=Mock_db()) | ||
|
||
r = svc.save(content=PASTE_CONTENT) | ||
assert r == HASHED_CONTENT_FIRST_SIX_CHARS |