Skip to content
Permalink
Browse files
first commit
  • Loading branch information
Iulian Ivighenie committed Apr 6, 2021
0 parents commit 1e7b314f384965ffbdf21f2b178ff975b270feef
Show file tree
Hide file tree
Showing 31 changed files with 1,469 additions and 0 deletions.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Empty file.
@@ -0,0 +1,44 @@
import unittest
from app import app


class BasicTestsSetup(unittest.TestCase):

def setUp(self):
app.config['TESTING'] = True
app.config['WTF_CSRF_ENABLED'] = False
app.config['DEBUG'] = False
self.app = app.test_client()
self.assertEqual(app.debug, False)

# executed after each test
def tearDown(self):
pass


class TestCaseExamples(unittest.TestCase):

def test_home_status(self):
tester = app.test_client(self)
response = tester.get('/', content_type='html/text')
self.assertEqual(response.status_code, 200) # (test if the page renders and response is correct )

def test_home_content(self):
tester = app.test_client(self)
response = tester.get('/', content_type='html/text')
self.assertTrue(b'<!DOCTYPE html>\n<html lang="en">\n<head>\n <meta charset="UTF-8">\n <title>Demo</title>\n' in response.data) # passed the test

def test_dashboard(self):
tester = app.test_client(self)
response = tester.get('/dashboard', content_type='html/text')
self.assertTrue(b'<!doctype html>\n<html lang="en">\n <head>\n <meta charset="utf-8">\n <meta name="viewport" content="width=device-width, initial-scale=1">\n' in response.data) # passed the test

def test_report_id(self):
tester = app.test_client(self)
response = tester.get('/issue/1', content_type='html/text')
self.assertTrue(b'<h2>Issue Details</h2>' in response.data) # passed the test



if __name__ == '__main__':
unittest.main()
@@ -0,0 +1,32 @@
import unittest
from issue import Issue


class TestIssue(unittest.TestCase):
def setUp(self):
self.__issue = Issue()

def test_issue_has_title(self):
self.__issue.set_title("problem with the bin")
title = self.__issue.get_title()
self.assertEqual(title, "problem with the bin")

def test_issue_has_type(self):
self.__issue.set_issue_type("bins")
type = self.__issue.get_issue_type()
self.assertEqual(type, "bins")

def test_issue_has_description(self):
self.__issue.set_description("there is a bin left outside 2 days before collection day")
description = self.__issue.get_description()
self.assertEqual(description, "there is a bin left outside 2 days before collection day")

def test_issue_has_postcode(self):
self.__issue.set_postcode("CV24EP")
postcode = self.__issue.get_postcode()
self.assertEqual(postcode, "CV24EP")

def test_issue_has_time(self):
self.__issue.set_time("03/04/2021 21:14")
the_time = self.__issue.get_time()
self.assertEqual(the_time, "03/04/2021 21:14")
@@ -0,0 +1,24 @@
# Currently there is no class manager. In Composite pattern
# the manager is part of "staff". Perhaps, this could grow into a
# separate class on its own


# import unittest
# from manager import Manager
#
#
# class TestManager(unittest.TestCase):
#
# def setUp(self):
# print("setup")
# self.__manager = Manager()
# self.__email = ""
#
#
# def tearDown(self):
# print("teardown")
# del self.__manager
#
#
# if __name__ == '__main__':
# unittest.main()
@@ -0,0 +1,14 @@
import unittest
from messageboard import MessageController
import datetime


class TestMessageController(unittest.TestCase):
def setUp(self):
self.__message_controller = MessageController()

# MessageController displays message correctly
def test_issue_has_title(self):
message = self.__message_controller.display_message("this is a test message")
now = datetime.datetime.now()
self.assertEqual(message, now.strftime("%Y-%m-%d %H:%M:%S") + " " + "this is a test message")
@@ -0,0 +1,39 @@
import unittest
from staff import Staff


class TestStaff(unittest.TestCase):

# standard built in method "setUp" for testing
def setUp(self):
self.__user = Staff()
self.__user.set_role("staff")
self.__user.set_email("staff@mail.com")
self.__user.add_manager("manager@mail.com")

# test if role is correct
def test_get_role(self):
test_result = self.__user.get_role()
self.assertEqual(test_result, "staff")

# test if email is correct
def test_get_email(self):
test_result = self.__user.get_email()
self.assertEqual(test_result, "staff@mail.com")

# test that it doesn't have "managers" composite pattern
def test_phone_is_null(self):
# use built in hasattr() to check if attribute
# get_phone exist
test_result = hasattr(self.__user, "get_phone")
self.assertIs(test_result, False)

# test that it doesn't have "managers" composite pattern
def test_manager_exists(self):
test_result = self.__user.get_managers_email()
self.assertEqual(test_result, ["manager@mail.com"])

def test_manager_add(self):
self.__user.add_manager("manager2@mail.com")
test_result = self.__user.get_managers_email()
self.assertEqual(test_result, ["manager@mail.com","manager2@mail.com"])
@@ -0,0 +1,35 @@
import unittest
from user import User


class TestUser(unittest.TestCase):

# standard built in method "setUp" for testing
def setUp(self):
self.__user = User()
self.__user.set_role("user")
self.__user.set_email("test@mail.com")
self.__user.set_phone("07427730650")

# test if role is correct
def test_get_role(self):
test_result = self.__user.get_role()
self.assertEqual(test_result, "user")

# test if email is correct
def test_get_email(self):
test_result = self.__user.get_email()
self.assertEqual(test_result, "test@mail.com")

# test if phone exists and is correct
def test_phone_exists(self):
test_result = self.__user.get_phone()
self.assertIsNotNone(test_result)
self.assertEqual(test_result, "07427730650")

# test that it doesn't have "managers" composite pattern
def test_has_not_manager(self):
# use built in hasattr() to check if attribute
# get_managers exist
test_result = hasattr(self.__user, "get_managers")
self.assertIs(test_result, False)
@@ -0,0 +1,36 @@
import unittest
from user_profile import Profile


class TestProfile(unittest.TestCase):

def setUp(self):
self.__user = Profile()

# we test if attributes exist
def test_has_get_email(self):
# use built in hasattr() to check if attribute
# get_managers exist
test_result = hasattr(self.__user, "get_email")
self.assertIs(test_result, True)

# we test if attributes exist
def test_has_set_email(self):
# use built in hasattr() to check if attribute
# get_managers exist
test_result = hasattr(self.__user, "set_email")
self.assertIs(test_result, True)

# we test if attributes exist
def test_has_get_role(self):
# use built in hasattr() to check if attribute
# get_managers exist
test_result = hasattr(self.__user, "get_role")
self.assertIs(test_result, True)

# we test if attributes exist
def test_has_get_role(self):
# use built in hasattr() to check if attribute
# get_managers exist
test_result = hasattr(self.__user, "set_role")
self.assertIs(test_result, True)
@@ -0,0 +1,17 @@
import unittest
from userfactory import UserFactory


class TestUserFactory(unittest.TestCase):
def setUp(self):
self.__factory = UserFactory()

def test_factory_creates_staff(self):
staff = self.__factory.factory("staff")
role = staff.get_role()
self.assertEqual(role, "staff")

def test_factory_creates_user(self):
staff = self.__factory.factory("user")
role = staff.get_role()
self.assertEqual(role, "user")

0 comments on commit 1e7b314

Please sign in to comment.