Skip to content

jangia/srp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Single responsibility principle

This repository was made to find the best solution which does not violate SRP.

It started with these 2 tweets: @testdrivenio and jangiacomelli

Specifications

Let's say we have a forum for Python professionals. We have users which are monthly charged for the subscription and banned for 7 days if they misbehave.

SRP-violating pseudo-solution

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')

    def ban(self):
        self.banned_until = datetime.datetime.today() + datetime.timedelta(days=7)

    def charge(self):
        print('Charge credit card of user using Stripe')

Goal

We're trying to find the best solution that complies with SRP.

Setup

To install requirements:

(venv)$ pip install -r requirements.txt

To run tests:

(venv)$ pytest tests

To run tests - if you're getting "pytest" not found:

(venv)$ python -m pytest

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages