Skip to content

Commit

Permalink
Fix formatting per linter
Browse files Browse the repository at this point in the history
  • Loading branch information
akuny committed Oct 6, 2023
1 parent 68bf48d commit 0efdfb3
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nad_ch/application_context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from .gateways.storage_mock import StorageGatewayMock


class ApplicationContext:
def __init__(self):
self._storage = StorageGatewayMock()
Expand All @@ -9,10 +10,12 @@ def __init__(self):
def storage(self):
return self._storage


class TestApplicationContext(ApplicationContext):
def __init__(self):
self._storage = StorageGatewayMock()


def create_app_context():
if os.environ.get('APP_ENV') == 'test':
return TestApplicationContext()
Expand Down
4 changes: 4 additions & 0 deletions nad_ch/controllers/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
from ..entities import File
from ..use_cases import upload_file, list_files, get_file_metadata


@click.group()
@click.pass_context
def cli(ctx):
pass


@cli.command()
@click.pass_context
@click.argument('filename')
Expand All @@ -17,6 +19,7 @@ def upload(ctx, filename, content):
upload_file(context, file)
click.echo(f"Uploaded {filename}")


@cli.command()
@click.pass_context
def listall(ctx):
Expand All @@ -25,6 +28,7 @@ def listall(ctx):
for file in files:
click.echo(file.name)


@cli.command()
@click.pass_context
@click.argument('filename')
Expand Down
2 changes: 2 additions & 0 deletions nad_ch/entities.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from dataclasses import dataclass


@dataclass
class File:
name: str
content: str


@dataclass
class FileMetadata:
name: str
Expand Down
1 change: 1 addition & 0 deletions nad_ch/gateways/storage_mock.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ..entities import File, FileMetadata
from ..interfaces.storage import StorageGateway


class StorageGatewayMock(StorageGateway):
def __init__(self):
self.files = []
Expand Down
1 change: 1 addition & 0 deletions nad_ch/interfaces/storage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Protocol
from ..entities import File, FileMetadata


class StorageGateway(Protocol):
def save(self, file: File) -> None:
...
Expand Down
3 changes: 3 additions & 0 deletions nad_ch/use_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
from .entities import File, FileMetadata
from .interfaces.storage import StorageGateway


def upload_file(ctx: ApplicationContext, file: File) -> None:
storage: StorageGateway = ctx.storage
storage.save(file)


def list_files(ctx: ApplicationContext) -> list[File]:
storage: StorageGateway = ctx.storage
return storage.list_all()


def get_file_metadata(ctx: ApplicationContext, file_name: str) -> FileMetadata:
storage: StorageGateway = ctx.storage
return storage.get_metadata(file_name)
4 changes: 4 additions & 0 deletions tests/test_use_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
from nad_ch.entities import File, FileMetadata
from nad_ch.use_cases import upload_file, list_files, get_file_metadata


@pytest.fixture(scope="function")
def app_context():
context = create_app_context()
yield context


def test_upload_file(app_context):
file = File(name="test.txt", content="Sample content")

Expand All @@ -17,6 +19,7 @@ def test_upload_file(app_context):
assert stored_file.name == "test.txt"
assert stored_file.content == "Sample content"


def test_list_files(app_context):
file1 = File(name="test1.txt", content="Content 1")
file2 = File(name="test2.txt", content="Content 2")
Expand All @@ -29,6 +32,7 @@ def test_list_files(app_context):
assert any(f.name == "test1.txt" for f in files)
assert any(f.name == "test2.txt" for f in files)


def test_get_file_metadata(app_context):
file = File(name="test.txt", content="Sample content for metadata")
upload_file(app_context, file)
Expand Down

0 comments on commit 0efdfb3

Please sign in to comment.