Skip to content

Commit

Permalink
Added git forms & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
agent87 committed Jan 25, 2022
1 parent 6befa33 commit 80fcc0f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@ dmypy.json
# Playground File
playground

migrations/
migrations/
test-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<a href={% url 'login' %}>I forgot my password</a>
</p>
<p class="mb-0">
<a href={% url 'RegisterView' %} class="text-center">Register a new membership</a>
<a href={% url 'RegisterView' %} class="text-center">Register as Parking Owner</a>
</p>
</div>
</div>
Expand Down
14 changes: 14 additions & 0 deletions SystemApp/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.forms import ModelForm
from .models import *


class CustomersForm(ModelForm):
class Meta:
model = Customers
fields = ['company_name', 'address']


class UsersForm(ModelForm):
class Meta:
model = Users
fields = ['customer_id', 'first_name', 'last_name', 'email', 'phonenum', 'password', 'role']
Empty file added SystemApp/test/__init__.py
Empty file.
Empty file added SystemApp/test/test_managers.py
Empty file.
45 changes: 45 additions & 0 deletions SystemApp/test/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from django.test import TestCase
from django.db import transaction
from DashboardApp.views import users
from SystemApp.models import *
import os

class CustomerTestCase(TestCase):
def setUp(self):
pass

def test_enroll_customers(self):
Customers.enroll_customer('Leapr Labs', 'Rugando, Kigali, Rwanda')
Customers.enroll_customer('Makuza Peace Plaza', 'Downtown, Kigali, Rwanda')

customers_obj = Customers.objects.all()

self.assertEqual(len(customers_obj), 2)


class UserTestCase(TestCase):
def setUp(self):
Customers.enroll_customer('Leapr Labs', 'Rugando, Kigali, Rwanda')
Customers.enroll_customer('Makuza Peace Plaza', 'Downtown, Kigali, Rwanda')

def test_add_user(self):
add_1 = Users.add_user(customer_id=Customers.objects.all()[0].customer_id, first_name='fname_1', last_name='lname_1', email='test_1@gmailcom', phonenum='+250783089337', password='admin123', role='Admin')
add_2 = Users.add_user(customer_id=Customers.objects.all()[1].customer_id, first_name='fname_2', last_name='lname_2', email='admin_2@gmailcom', phonenum='+250783089337', password='admin456', role=None)
with transaction.atomic():
add_3 = Users.add_user(customer_id=Customers.objects.all()[0].customer_id, first_name='fname_1', last_name='lname_1', email='test_1@gmailcom', phonenum='+250783089337', password='admin123', role='Admin')

users_obj = Users.objects.all()

#test size of the users object
self.assertEqual(len(users_obj), 2)

#test addition 1
self.assertEqual(add_1, (True, users_obj[0], None))

#test addition 2 to see if user is super user
self.assertEqual(add_2[1].is_superuser, False)

#test addition 3 to check duplicate email
self.assertEqual(add_3, (False, None, 'Email already exists'))


0 comments on commit 80fcc0f

Please sign in to comment.