-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add House creation logic after login as a user
Add Create House View fixing House tests and model to new house model fixing expenses tests and model to new house model Fixing create mock data Adding test for script Adding test for factories Change the House model to be with a one-to-one relationship with the Django user model
- Loading branch information
Showing
24 changed files
with
285 additions
and
204 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
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,32 @@ | ||
import pytest | ||
|
||
from factories.expense import ExpenseFactory | ||
from factories.house import HouseFactory | ||
from factories.user import UserFactory | ||
|
||
|
||
@pytest.fixture | ||
def user_factory(): | ||
return UserFactory() | ||
|
||
|
||
@pytest.fixture | ||
def house_factory(user_factory): | ||
return HouseFactory(user=user_factory) | ||
|
||
|
||
@pytest.fixture | ||
def expense_factory(house_factory): | ||
return ExpenseFactory(house=house_factory, month=1) | ||
|
||
|
||
@pytest.mark.django_db() | ||
class TestFactories: | ||
def test_user_factory(self): | ||
UserFactory() | ||
|
||
def test_house_factory(self, user_factory): | ||
HouseFactory(user=user_factory) | ||
|
||
def test_expense_factory(self, house_factory): | ||
ExpenseFactory(house=house_factory, month=1) |
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,11 @@ | ||
import factory | ||
from django.contrib.auth import get_user_model | ||
from django.contrib.auth.hashers import make_password | ||
|
||
|
||
class UserFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = get_user_model() | ||
|
||
username = factory.Sequence(lambda n: "username%d" % n) | ||
password = make_password("password") |
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
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 |
---|---|---|
@@ -1,11 +1,21 @@ | ||
import random | ||
from factories.expense import ExpenseFactory | ||
from factories.house import HouseFactory | ||
from factories.user import UserFactory | ||
|
||
|
||
def run(): | ||
for _ in range(500): | ||
house = HouseFactory() | ||
def run(*args): | ||
if args: | ||
number_to_create = int(args[0]) | ||
else: | ||
print("Please provide a number of records to create.\n" | ||
"Example: manage.py runscript create_mock_data --script-args 10.") | ||
return | ||
print(f"Creating {number_to_create} users with mock data") | ||
for _ in range(number_to_create): | ||
user = UserFactory() | ||
user.save() | ||
house = HouseFactory(user=user) | ||
house.save() | ||
for _ in range(5): | ||
ExpenseFactory(house=house, month=random.randint(1, 12)).save() | ||
house.save() |
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,16 @@ | ||
import pytest | ||
from django.contrib.auth.models import User | ||
|
||
from expenses.models import Expenses | ||
from house.models import House | ||
from scripts.create_mock_data import run | ||
|
||
|
||
@pytest.mark.django_db() | ||
class TestScripts: | ||
def test_create_mock_data(self): | ||
mock_num_for_test = 10 | ||
run(mock_num_for_test) | ||
assert len(User.objects.all()) == mock_num_for_test | ||
assert len(House.objects.all()) == mock_num_for_test | ||
assert len(Expenses.objects.all()) == mock_num_for_test * 5 |
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,9 @@ | ||
#house_create{ | ||
align-content: center; | ||
margin-top: 5%; | ||
margin-bottom: auto; | ||
} | ||
|
||
#submit-button{ | ||
width: 100%; | ||
} |
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
{% extends "base.html" %} | ||
{% load static %} | ||
{% load material_form %} | ||
{% block content %} | ||
<link rel="stylesheet" type="text/css" href="{% static 'css/house_create.css' %}"/> | ||
<div id="house_create"> | ||
<div class="d-flex justify-content-center h-100"> | ||
<div class="card"> | ||
<div class="card-header"> | ||
<h3>Add your House information</h3> | ||
</div> | ||
<div class="card-body" style="color: rgb(0, 0, 0); background: rgba(252, 252, 252, 0.3); width: 500px;"> | ||
<form method="POST"> | ||
{% csrf_token %} | ||
{% form form=form %}{% endform %} | ||
<button class="btn btn-primary" id="submit-button" type="submit">Submit</button> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock content %} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.