-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrote docstrings to all functions and modules
- Loading branch information
Showing
23 changed files
with
105 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,9 @@ | |
} | ||
}, | ||
"balance": { | ||
"[email protected]": 810, | ||
"[email protected]": 410, | ||
"[email protected]": 100 | ||
"[email protected]": 653, | ||
"[email protected]": 253, | ||
"[email protected]": 200 | ||
}, | ||
"movement": { | ||
"[email protected]": [ | ||
|
@@ -62,6 +62,16 @@ | |
"date": "2024-07-01T09:47:47.852407", | ||
"actor": "solermvictor", | ||
"value": 5 | ||
}, | ||
{ | ||
"date": "2024-07-01T10:28:44.587618", | ||
"actor": "solermvictor", | ||
"value": -257 | ||
}, | ||
{ | ||
"date": "2024-07-01T10:29:00.532653", | ||
"actor": "solermvictor", | ||
"value": 100 | ||
} | ||
], | ||
"[email protected]": [ | ||
|
@@ -104,13 +114,28 @@ | |
"date": "2024-07-01T09:47:47.852421", | ||
"actor": "solermvictor", | ||
"value": 5 | ||
}, | ||
{ | ||
"date": "2024-07-01T10:28:44.587632", | ||
"actor": "solermvictor", | ||
"value": -257 | ||
}, | ||
{ | ||
"date": "2024-07-01T10:29:00.532668", | ||
"actor": "solermvictor", | ||
"value": 100 | ||
} | ||
], | ||
"[email protected]": [ | ||
{ | ||
"date": "2024-06-30T13:17:00.086294", | ||
"actor": "system", | ||
"value": 100 | ||
}, | ||
{ | ||
"date": "2024-07-01T10:28:22.353956", | ||
"actor": "solermvictor", | ||
"value": 100 | ||
} | ||
] | ||
}, | ||
|
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Entry point of Dundie module.""" |
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,3 +1,5 @@ | ||
"""Main of Dundie module.""" | ||
|
||
from dundie.cli import main | ||
|
||
if __name__ == "__main__": | ||
|
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,4 @@ | ||
"""Core module of dundie""" | ||
"""Core module of dundie.""" | ||
|
||
import os | ||
from csv import reader | ||
|
@@ -10,7 +10,7 @@ | |
|
||
|
||
def load(filepath): | ||
"""Loads data from filepath to the database. | ||
"""Load data from filepath to the database. | ||
>>> len(load('assets/people.csv')) | ||
2 | ||
|
@@ -39,7 +39,7 @@ def load(filepath): | |
|
||
|
||
def read(**query): | ||
"""Read data from db and filters using query | ||
"""Read data from db and filters using query. | ||
read(email="[email protected]") | ||
""" | ||
|
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,3 +1,5 @@ | ||
"""Main functions to access, commit and make alterations into the database.""" | ||
|
||
import json | ||
from datetime import datetime | ||
|
||
|
@@ -9,7 +11,7 @@ | |
|
||
|
||
def connect() -> dict: | ||
"""Connects to the database, returns dict data.""" | ||
"""Connect to the database, returns dict data.""" | ||
try: | ||
with open(DATABASE_PATH, "r") as database_file: | ||
return json.loads(database_file.read()) | ||
|
@@ -27,7 +29,7 @@ def commit(db): | |
|
||
|
||
def add_person(db, pk, data): | ||
"""Saves person data to database. | ||
"""Save person data to database. | ||
- E-mail is unique (resolved by dictonary hash table) | ||
- If exists, update, else create | ||
|
@@ -51,7 +53,7 @@ def add_person(db, pk, data): | |
|
||
|
||
def set_initial_password(db, pk): | ||
"""Generates and saves password.""" | ||
"""Generate and save password.""" | ||
db["users"].setdefault(pk, {}) | ||
db["users"][pk]["password"] = generate_simple_password(8) | ||
return db["users"][pk]["password"] | ||
|
@@ -64,6 +66,12 @@ def set_initial_balance(db, pk, person): | |
|
||
|
||
def add_movement(db, pk, value, actor="system"): | ||
"""Add movement to user account. | ||
Example:: | ||
add_movement(db, "[email protected]", 100, "me") | ||
""" | ||
movements = db["movement"].setdefault(pk, []) | ||
movements.append( | ||
{"date": datetime.now().isoformat(), "actor": actor, "value": value} | ||
|
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,3 +1,5 @@ | ||
"""Settings for e-mail, SMTP and paths to functions in the module Dundie.""" | ||
|
||
import os | ||
|
||
SMTP_HOST = "Localhost" | ||
|
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 @@ | ||
"""Initialization of utils module of dundie module.""" |
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
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 @@ | ||
"""Entry point of integration tests module.""" |
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,3 +1,5 @@ | ||
"""Constants paths used on the dundie's integration tests.""" | ||
|
||
import os | ||
|
||
TEST_PATH = os.path.dirname(__file__) | ||
|
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Entry point of unit tests module.""" |
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,3 +1,5 @@ | ||
"""Constants paths used on dundie's unit tests.""" | ||
|
||
import os | ||
|
||
TEST_PATH = os.path.dirname(__file__) | ||
|
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,3 +1,5 @@ | ||
"""Tests the function add.""" | ||
|
||
import pytest | ||
|
||
from dundie.core import add | ||
|
@@ -6,6 +8,7 @@ | |
|
||
@pytest.mark.unit | ||
def test_add_movement(): | ||
"""Add two person into the db, and tests movements into the balance.""" | ||
db = connect() | ||
|
||
pk = "[email protected]" | ||
|
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,16 +1,20 @@ | ||
"""Tests the database.""" | ||
|
||
import pytest | ||
|
||
from dundie.database import EMPTY_DB, add_movement, add_person, commit, connect | ||
|
||
|
||
@pytest.mark.unit | ||
def test_database_schema(): | ||
"""Test the schema of database.""" | ||
db = connect() | ||
assert db.keys() == EMPTY_DB.keys() | ||
|
||
|
||
@pytest.mark.unit | ||
def test_commit_to_database(): | ||
"""Test the function commit to the database.""" | ||
db = connect() | ||
data = {"name": "Joe Doe", "role": "Salesman", "dept": "Sales"} | ||
db["people"]["[email protected]"] = data | ||
|
@@ -22,6 +26,7 @@ def test_commit_to_database(): | |
|
||
@pytest.mark.unit | ||
def test_add_person_for_the_first_time(): | ||
"""Test the add person to the db for the first time.""" | ||
pk = "[email protected]" | ||
data = {"role": "Salesman", "dept": "Sales", "name": "Joe Doe"} | ||
db = connect() | ||
|
@@ -38,12 +43,14 @@ def test_add_person_for_the_first_time(): | |
|
||
@pytest.mark.unit | ||
def test_negative_add_person_invalid_email(): | ||
"""Test if invalid email is going to raise a Value Error.""" | ||
with pytest.raises(ValueError): | ||
add_person({}, ".@bla", {}) | ||
|
||
|
||
@pytest.mark.unit | ||
def test_add_or_remove_points_for_person(): | ||
"""Test add two persons and add and remove points of them.""" | ||
pk = "[email protected]" | ||
data = {"role": "Salesman", "dept": "Sales", "name": "Joe Doe"} | ||
db = connect() | ||
|
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,3 +1,5 @@ | ||
"""Test the function load of dundie.""" | ||
|
||
import pytest | ||
|
||
from dundie.core import load | ||
|
Oops, something went wrong.