From 056ca430ef5a6deb494ecda5d3d199001c54e336 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Sun, 24 Jun 2018 01:05:02 +0200 Subject: [PATCH] First pytest stuff --- .gitignore | 1 + README.rst | 8 ++++++++ accounting/models.py | 1 + accounting/test.py | 0 accounting/tests.py | 16 ++++++++++++++++ pytest.ini | 5 +++++ requirements_dev.txt | 1 + 7 files changed, 32 insertions(+) delete mode 100644 accounting/test.py create mode 100644 accounting/tests.py create mode 100644 pytest.ini diff --git a/.gitignore b/.gitignore index 976eaca..f4b2f47 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ __pycache__/ *.sw* db.sqlite3 membersystem/settings/local.py +.pytest_cache diff --git a/README.rst b/README.rst index 0d23ef5..2ac2ce6 100644 --- a/README.rst +++ b/README.rst @@ -9,3 +9,11 @@ To start developing: # Run this make target, which installs all the requirements and sets up a # development database. $ make dev-setup + +To run the Django development server: + + $ python manage.py runserver + +Before you push your stuff, run tests: + + $ make test diff --git a/accounting/models.py b/accounting/models.py index 73ddb8d..0b55eb3 100644 --- a/accounting/models.py +++ b/accounting/models.py @@ -32,6 +32,7 @@ class Account(CreatedModifiedAbstract): owner = models.ForeignKey(get_user_model(), on_delete=models.PROTECT) + @property def balance(self): return self.transactions.all().aggregate(Sum('amount')).get('amount', 0) diff --git a/accounting/test.py b/accounting/test.py deleted file mode 100644 index e69de29..0000000 diff --git a/accounting/tests.py b/accounting/tests.py new file mode 100644 index 0000000..b2e28e3 --- /dev/null +++ b/accounting/tests.py @@ -0,0 +1,16 @@ +import pytest +from django.contrib.auth.models import User + +from . import models + +# @pytest.fixture +# def test(): +# do stuff + +@pytest.mark.django_db +def test_balance(): + user = User.objects.create_user("test", "lala@adas.com", "1234") + account = models.Account.objects.create( + owner=user + ) + assert account.balance == 0 diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..1e2ec6a --- /dev/null +++ b/pytest.ini @@ -0,0 +1,5 @@ +[pytest] +testpaths = . +python_files = tests.py test_*.py *_tests.py +DJANGO_SETTINGS_MODULE = membersystem.settings +#norecursedirs = dist tmp* .svn .* diff --git a/requirements_dev.txt b/requirements_dev.txt index 4d4a689..ad11934 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,2 +1,3 @@ pytest +pytest-django pre-commit