예제 #1
0
class TestPages(unittest.TestCase):
    """This class tests all the methods in pages.py"""
    def setUp(self) -> None:
        # set up the Pages class
        self.exec = Pages(DB.connect())

    def test_select(self):
        #  Test the select method of Pages class in pages.py
        result = self.exec.select()
        self.assertIsNotNone(result)

    def test_select_id(self):
        self.assertIsNotNone(self.exec.select_id())

    def test_select_url(self):
        # Test the select_url method of Pages class in pages.py
        self.assertIsNotNone(self.exec.select_url(1))

    def test_find(self):
        # Test the find method of Pages class in pages.py
        DB.seed()
        result = self.exec.find(2)
        self.assertIsNotNone(result)

    def test_find_url(self):
        # Test the find_url method of Pages class in pages.py
        DB.seed()
        self.assertIsNotNone(self.exec.find_url(1))

    def test_update(self):
        # Test the update method of Pages class in pages.py
        DB.seed()
        self.assertIsNone(self.exec.update(False, 1))

    def test_delete(self):
        # Test the delete method of Pages class in pages.py
        self.assertIsNone(self.exec.delete(2))

    def tearDown(self) -> None:
        # Tear down the Pages class after all tests
        self.exec = None
예제 #2
0
class TestPages(TestCase):
    # Test each and every method in the Pages class
    def setUp(self):
        """Setup all the necessary class and functions"""
        self.pages = Pages()
        self.conn_server = DB.only_server()
        self.conn = self.pages.connect()
        self.cursor = self.conn.cursor()

    def test_connect(self):
        """ Test connecting to postgresql server is successful """
        connection_object = self.conn
        self.assertIsNotNone(connection_object)

    def test_select(self):
        """Test select return all data from the database"""
        data = self.pages.select()
        self.assertIsNotNone(data)

    def test_find(self):
        """Test find data returns the data with the id provided"""
        data = self.pages.find(1)
        self.assertIsNotNone(data)
        self.assertEqual(type(data), tuple)

    def test_update(self):
        """Test data is updated by id with params and returned the updated data """
        data = 'True'
        updated_data = self.pages.update(data, 1)
        self.assertIsNone(updated_data)

    def test_delete(self):
        """Test data is deleted by id and returns none """
        deleted = self.pages.delete(1)
        self.assertEqual(deleted, None)

    def tearDown(self):
        """TearDown connections and delete all data created for testing purposes"""
        self.pages.close()