Skip to content

Instantly share code, notes, and snippets.

View jangia's full-sized avatar

Jan Giacomelli jangia

View GitHub Profile
@jangia
jangia / models.py
Created April 10, 2024 05:41
Test behavior, not implementation details - part 3
from dataclasses import dataclass
from enum import Enum
class TaskStatus(str, Enum):
OPEN = "OPEN"
CLOSED = "CLOSED"
@dataclass
@jangia
jangia / tests.py
Created March 27, 2024 19:11
Testing behavior, not implementation details – part 2 (tests)
import sqlite3
import pytest
from models import Task, TaskStatus
from store import TaskStoreSQLite
@pytest.fixture
def connection(tmp_path) -> sqlite3.Connection:
@jangia
jangia / models.py
Created March 27, 2024 18:48
Testing behavior, not implementation details – part 2 (model & store)
from dataclasses import dataclass
from enum import Enum
class TaskStatus(str, Enum):
OPEN = "OPEN"
CLOSED = "CLOSED"
@dataclass
@jangia
jangia / tests.py
Created March 18, 2024 17:26
Testing behavior, not implementation details – In-Memory Store Tests
# behavior/tests.py
def test_add_task_():
store = TaskStoreInMemory()
task = Task(title="Do the dishes", status=TaskStatus.OPEN)
store.add_task(task)
assert store.tasks[0].title == "Do the dishes"
@jangia
jangia / store.py
Created March 18, 2024 17:25
Testing behavior, not implementation details – In-Memory Store
# behavior/store.py
class TaskStoreInMemory(TaskStore):
def __init__(self):
self._tasks = []
def add_task(self, task: Task) -> None:
self._tasks.append(task)
def list_tasks(self) -> list[Task]:
@jangia
jangia / models.py
Created March 18, 2024 17:24
Testing behavior, not implementation details – Testing Behavior
# behavior/models.py
from dataclasses import dataclass
from enum import Enum
class TaskStatus(str, Enum):
OPEN = "OPEN"
CLOSED = "CLOSED"
@jangia
jangia / models.py
Last active March 18, 2024 17:22
Testing behavior, not implementation details – Testing implementation Details
# implementation_details/models.py
from dataclasses import dataclass
from enum import Enum
class TaskStatus(str, Enum):
OPEN = "OPEN"
CLOSED = "CLOSED"
class Stick:
def __init__(self, color, length, weight):
self.color = color
self.length = length
self.weight = weight
stick = Stick('yellow', 1, 0.324)
def my_function():
print('Hi')
print(my_function)
# <function my_function at 0x7efea5c36050>
def send_email_ses(email_message):
print(f'Send email using AWS SES: {email_message}')
@jangia
jangia / user.py
Created December 28, 2020 21:52
SRP violated
import datetime
class User:
def __init__(self, username, banned_until):
self.username = username
self.banned_until = banned_until
def save(self):
print('I am saving to PostgreSQL')