Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Unittests for introduction/models #117

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ env
pygoat/db.sqlite3
*.sqlite3
*db.sqlite3
pygoat/staticfiles/*
pygoat.egg-info/*
29 changes: 0 additions & 29 deletions pygoat/introduction/lab_code/test.py

This file was deleted.

3 changes: 0 additions & 3 deletions pygoat/introduction/tests.py

This file was deleted.

Empty file.
50 changes: 50 additions & 0 deletions pygoat/introduction/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from django.test import TestCase
from introduction.models import *
from django.conf import settings
from django.contrib.auth.models import User

class ModelTests(TestCase):

# Create a FAANG Model
def test_faang_creation(self):
f = FAANG.objects.create(company="Google")
self.assertTrue(isinstance(f, FAANG))
self.assertEqual(f.__str__(), f.company)

# Create `info` Model
def test_info_creation(self):
f = FAANG.objects.create(company="Google")
i = info.objects.create(ceo="SPichai", about="Google CEO", faang=f)
self.assertTrue(isinstance(i, info))

# Create a `login` Model
def test_login_creation(self):
l = login.objects.create(user="admin", password="password")
self.assertTrue(isinstance(l, login))

# Create a `comments` Model
def test_comments_creation(self):
c = comments.objects.create(name="John Doe", comment="Test Comment")
self.assertTrue(isinstance(c, comments))

# Create a `authLogin` model
def test_authLogin_creation(self):
a = authLogin.objects.create(username="testuser", name="John Doe", password="password")
self.assertTrue(isinstance(a, authLogin))

# Create a `otp` Model
def test_otp_creation(self):
o = otp.objects.create(email="[email protected]", otp=69)
self.assertTrue(isinstance(o, otp))

# Create a `tickits` Model
def test_tickits_creation(self):
user = User.objects.create_user(username="john doe", password="password")
t = tickits.objects.create(user=user, tickit="abcd")
self.assertTrue(isinstance(t, tickits))
self.assertEqual(t.__str__(), f"{t.tickit} {t.user.username}" )

# Create a `sql_lab_table` Model
def test_sql_lab_table_creation(self):
s = sql_lab_table.objects.create(password="password")
self.assertTrue(isinstance(s, sql_lab_table))
6 changes: 6 additions & 0 deletions pygoat/introduction/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.test import RequestFactory, TestCase, Client
from django.contrib.auth.models import User
from django.http import HttpRequest
from introduction.views import *

# Create your tests here.
1 change: 1 addition & 0 deletions pygoat/introduction/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def register(request):
if request.method=="POST":
form = UserCreationForm(request.POST)
if form.is_valid():
print("hi")
form.save()
return redirect("login")

Expand Down