First pytest stuff
This commit is contained in:
parent
a8321decde
commit
056ca430ef
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@ __pycache__/
|
||||||
*.sw*
|
*.sw*
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
membersystem/settings/local.py
|
membersystem/settings/local.py
|
||||||
|
.pytest_cache
|
||||||
|
|
|
@ -9,3 +9,11 @@ To start developing:
|
||||||
# Run this make target, which installs all the requirements and sets up a
|
# Run this make target, which installs all the requirements and sets up a
|
||||||
# development database.
|
# development database.
|
||||||
$ make dev-setup
|
$ make dev-setup
|
||||||
|
|
||||||
|
To run the Django development server:
|
||||||
|
|
||||||
|
$ python manage.py runserver
|
||||||
|
|
||||||
|
Before you push your stuff, run tests:
|
||||||
|
|
||||||
|
$ make test
|
||||||
|
|
|
@ -32,6 +32,7 @@ class Account(CreatedModifiedAbstract):
|
||||||
|
|
||||||
owner = models.ForeignKey(get_user_model(), on_delete=models.PROTECT)
|
owner = models.ForeignKey(get_user_model(), on_delete=models.PROTECT)
|
||||||
|
|
||||||
|
@property
|
||||||
def balance(self):
|
def balance(self):
|
||||||
return self.transactions.all().aggregate(Sum('amount')).get('amount', 0)
|
return self.transactions.all().aggregate(Sum('amount')).get('amount', 0)
|
||||||
|
|
||||||
|
|
16
accounting/tests.py
Normal file
16
accounting/tests.py
Normal 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
5
pytest.ini
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
[pytest]
|
||||||
|
testpaths = .
|
||||||
|
python_files = tests.py test_*.py *_tests.py
|
||||||
|
DJANGO_SETTINGS_MODULE = membersystem.settings
|
||||||
|
#norecursedirs = dist tmp* .svn .*
|
|
@ -1,2 +1,3 @@
|
||||||
pytest
|
pytest
|
||||||
|
pytest-django
|
||||||
pre-commit
|
pre-commit
|
||||||
|
|
Loading…
Reference in a new issue