First pytest stuff

This commit is contained in:
Benjamin Bach 2018-06-24 01:05:02 +02:00
parent a8321decde
commit 056ca430ef
7 changed files with 32 additions and 0 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@ __pycache__/
*.sw*
db.sqlite3
membersystem/settings/local.py
.pytest_cache

View file

@ -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

View file

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

View file

16
accounting/tests.py Normal file
View file

@ -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

5
pytest.ini Normal file
View file

@ -0,0 +1,5 @@
[pytest]
testpaths = .
python_files = tests.py test_*.py *_tests.py
DJANGO_SETTINGS_MODULE = membersystem.settings
#norecursedirs = dist tmp* .svn .*

View file

@ -1,2 +1,3 @@
pytest
pytest-django
pre-commit