Skip to content

Instantly share code, notes, and snippets.

View jangia's full-sized avatar

Jan Giacomelli jangia

View GitHub Profile
@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')
with open('example.txt') as file:
lines = file.readlines()
for line in lines:
if line.lower().startswith('t'):
print(line)
service: my-service
provider:
name: aws
region: ${opt:region, 'eu-west-1'}
stage: ${opt:stage, 'development'}
plugins:
- serverless-s3-sync
import datetime
from fastapi import FastAPI
from pydantic.main import BaseModel
app = FastAPI()
class CreateTodo(BaseModel):
name: str
@jangia
jangia / App.svelte
Last active November 10, 2020 18:41
<script>
import Auth from '@aws-amplify/auth';
import { onMount } from 'svelte';
import axios from 'axios';
Auth.configure(
{
Auth: {
region: 'region',
userPoolId: 'pool_id',
userPoolWebClientId: 'client_id'