-
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.
begin implementing tests for the models
- Loading branch information
1 parent
aeadc4a
commit dc1fa89
Showing
7 changed files
with
124 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# State Of Work | ||
|
||
* Project has been fully configured from cookiecutter-django using MySQL. | ||
* Deployed to production at [negligentoctopus.pythonanywhere.com](negligentoctopus.pythonanywhere.com). | ||
|
||
Core models are being defined and added to the django-admin. | ||
Account and Transactions are implemented with balance as prefix-sum. | ||
|
||
## Update | ||
|
||
Testing for these model is being defined. | ||
|
||
# Today | ||
|
||
Testing required configuration of a db table 'test\_negligent\_octopus. | ||
This was achieved the same way as creating a normal table: | ||
- Go into sudo mysql | ||
- create table | ||
- grant all privileges to user | ||
After this pytest can create and drop the table as needed. | ||
|
||
Also, make sure that your app name is not relative, i.e., 'core' should be 'negligent\_octopus.core'. | ||
|
||
__To Continue__ | ||
|
||
Factories are defined. | ||
Testing is currently defined as methods of a class. | ||
The function can receive arguments with the name of models, which will be created and passed automatically by pytest using the factories (if defined) or using fixtures (use @pytest.fixture). | ||
|
||
## Work Log | ||
__InProgress__ | ||
* Add testing -- Functions are defined in class. Follow the one implemented as example. | ||
* Test business logic | ||
* Test balance is correct | ||
* Test balance on account is safe for one, for many transaction, with or withput inital balance | ||
* Test balance is same on change initial balance and change of a transaction | ||
* Test that changing acc or timestamp fails | ||
|
||
__ToDo__ | ||
|
||
__Done__ | ||
* Configure testing environment | ||
* Factories for testing | ||
* Testing functions | ||
|
||
__Discarded__ | ||
|
||
# To Do |
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 was deleted.
Oops, something went wrong.
Empty 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import factory | ||
from factory.django import DjangoModelFactory | ||
|
||
from negligent_octopus.core.models import Account | ||
from negligent_octopus.core.models import Transaction | ||
|
||
|
||
class AccountFactory(DjangoModelFactory): | ||
class Meta: | ||
model = Account | ||
|
||
owner = factory.SubFactory("negligent_octopus.users.tests.factories.UserFactory") | ||
name = factory.Faker("word") | ||
initial_balance = factory.Faker("random_number", digits=2) | ||
|
||
|
||
class TransactionFactory(DjangoModelFactory): | ||
class Meta: | ||
model = Transaction | ||
|
||
account = factory.SubFactory(AccountFactory) | ||
amount = factory.Faker("random_number", digits=2) | ||
title = factory.Faker("word") |
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,14 @@ | ||
import pytest | ||
|
||
from negligent_octopus.core.tests.factories import AccountFactory | ||
from negligent_octopus.core.tests.factories import TransactionFactory | ||
|
||
|
||
@pytest.fixture() | ||
def account(): | ||
return AccountFactory() | ||
|
||
|
||
@pytest.fixture() | ||
def transaction(): | ||
return TransactionFactory() |
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,37 @@ | ||
import pytest | ||
from django.utils import timezone | ||
from faker import Faker | ||
|
||
from negligent_octopus.core.models import Account | ||
from negligent_octopus.core.tests.factories import TransactionFactory | ||
|
||
faker = Faker() | ||
|
||
|
||
@pytest.mark.django_db() | ||
class TestAccountTransactionBalance: | ||
def test_account_balance(self, account: Account): | ||
balance = account.initial_balance | ||
for i in range(10): | ||
balance += i | ||
TransactionFactory( | ||
account=account, | ||
amount=i, | ||
timestamp=timezone.now(), # Make sure they are in order | ||
) | ||
assert account.balance == balance | ||
|
||
def test_account_initial_balance_change(self, account: Account): | ||
raise NotImplementedError | ||
|
||
def test_transaction_added_last(self, account: Account): | ||
raise NotImplementedError | ||
|
||
def test_transaction_added_first(self, account: Account): | ||
raise NotImplementedError | ||
|
||
def test_transaction_added_middle(self, account: Account): | ||
raise NotImplementedError | ||
|
||
def test_transaction_change_amount(self, account: Account): | ||
raise NotImplementedError |