From d504475fc971388a01ee67e0c1971201344c6005 Mon Sep 17 00:00:00 2001 From: Ojas Kulkarni Date: Thu, 19 Oct 2023 20:08:43 -0400 Subject: [PATCH 1/2] Updated test cases for CRUD operations --- .github/workflows/unit_test.yml | 1 + tests/test_module.py | 68 ++++++++++++++++----------------- tests/test_profile.py | 32 ++++++++-------- tests/test_register.py | 41 ++++++++++---------- 4 files changed, 72 insertions(+), 70 deletions(-) diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml index f8805245..0bf8c1f8 100644 --- a/.github/workflows/unit_test.yml +++ b/.github/workflows/unit_test.yml @@ -23,4 +23,5 @@ jobs: echo requirements installed - name: Run tests run: | + python application.py && pytest tests/test_*.py --doctest-modules --junitxml=junit/test-results.xml --cov=tests --cov-report=xml --cov-report=html diff --git a/tests/test_module.py b/tests/test_module.py index fa222125..f099558e 100644 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -1,5 +1,5 @@ import unittest -# from application import app +from application import app class BasicTestCase(unittest.TestCase): @@ -7,39 +7,39 @@ class BasicTestCase(unittest.TestCase): def test_logout(self): pass - # self.app = app.test_client() - # ans =self.app.get('/logout') - # self.assertEqual(ans.status_code, 200) - - # def test_home(self): - # self.app = app.test_client() - # ans =self.app.get('/home') - # self.assertEqual(ans.status_code, 302) - - # def test_login(self): - # self.app = app.test_client() - # ans =self.app.get('/login') - # self.assertEqual(ans.status_code, 200) - - # def test_register(self): - # self.app = app.test_client() - # ans =self.app.get('/register') - # self.assertEqual(ans.status_code, 200) - - # def test_dashboard(self): - # self.app = app.test_client() - # ans =self.app.get('/dashboard') - # self.assertEqual(ans.status_code, 200) - - # def test_friends(self): - # self.app= app.test_client() - # ans=self.app.get('/friends') - # self.assertEqual(ans.status_code, 200) - - # def test_calories(self): - # self.app= app.test_client() - # ans=self.app.get('/calories') - # self.assertEqual(ans.status_code, 302) + self.app = app.test_client() + ans =self.app.get('/logout') + self.assertEqual(ans.status_code, 200) + + def test_home(self): + self.app = app.test_client() + ans =self.app.get('/home') + self.assertEqual(ans.status_code, 302) + + def test_login(self): + self.app = app.test_client() + ans =self.app.get('/login') + self.assertEqual(ans.status_code, 200) + + def test_register(self): + self.app = app.test_client() + ans =self.app.get('/register') + self.assertEqual(ans.status_code, 200) + + def test_dashboard(self): + self.app = app.test_client() + ans =self.app.get('/dashboard') + self.assertEqual(ans.status_code, 200) + + def test_friends(self): + self.app= app.test_client() + ans=self.app.get('/friends') + self.assertEqual(ans.status_code, 200) + + def test_calories(self): + self.app= app.test_client() + ans=self.app.get('/calories') + self.assertEqual(ans.status_code, 302) pass diff --git a/tests/test_profile.py b/tests/test_profile.py index 3816cc02..8e01f2d4 100644 --- a/tests/test_profile.py +++ b/tests/test_profile.py @@ -1,19 +1,19 @@ -# import pytest -# from unittest.mock import patch -# from application import app -# import mongomock +import pytest +from unittest.mock import patch +from application import app +import mongomock -# @pytest.fixture -# def client(): -# with mongomock.patch(): -# with app.test_client() as client: -# yield client +@pytest.fixture +def client(): + with mongomock.patch(): + with app.test_client() as client: + yield client -# def test_get_user_profile(client): -# db = mongomock.MongoClient().db +def test_get_user_profile(client): + db = mongomock.MongoClient().db -# db.items.insert_one( -# {"email":"ojaskulkarni100@gmail.com" ,"weight":90, "height":180, "target_weight":80,"goal":"75"}, -# ) -# response = client.get("/user_profile") -# assert response.status_code == 302 + db.items.insert_one( + {"email":"ojaskulkarni100@gmail.com" ,"weight":90, "height":180, "target_weight":80,"goal":"75"}, + ) + response = client.get("/user_profile") + assert response.status_code == 302 diff --git a/tests/test_register.py b/tests/test_register.py index 4251af47..74aa36fd 100644 --- a/tests/test_register.py +++ b/tests/test_register.py @@ -1,24 +1,25 @@ import pytest -# from application import app +import mongomock +from application import app -# @pytest.fixture -# def client(): -# with mongomock.patch(): -# with app.test_client() as client: -# yield client +@pytest.fixture +def client(): + with mongomock.patch(): + with app.test_client() as client: + yield client -# def test_get_user(client): -# db = mongomock.MongoClient().db -# db.items.insert_one( -# {"name": "OjasTest", "pwd":"hshaksjn", "weight":90, "height":180, "target_weight":80, "start_date":"2023-10-15", "target_date": -# "2023-11-15"}, -# ) -# response = client.get("/register") -# assert response.status_code == 200 +def test_get_user(client): + db = mongomock.MongoClient().db + db.items.insert_one( + {"name": "OjasTest", "pwd":"hshaksjn", "weight":90, "height":180, "target_weight":80, "start_date":"2023-10-15", "target_date": +"2023-11-15"}, + ) + response = client.get("/register") + assert response.status_code == 200 -# def test_insert_user(client): -# # Make a POST request to the /items endpoint with a JSON payload -# response = client.post("/register", json={"name": "OjasTest", "pwd":"hshaksjn", "weight":"90", "height":"180", "target_weight":"80", "start_date":"2023-10-15", "target_date": -# "2023-11-15"}) -# # Assert the response status code is 201 Created -# assert response.status_code == 200 +def test_insert_user(client): + # Make a POST request to the /items endpoint with a JSON payload + response = client.post("/register", json={"name": "OjasTest", "pwd":"hshaksjn", "weight":"90", "height":"180", "target_weight":"80", "start_date":"2023-10-15", "target_date": +"2023-11-15"}) + # Assert the response status code is 201 Created + assert response.status_code == 200 From 0e470fcf60fd083d4a765091b57b5b005507ddbf Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 20 Oct 2023 00:09:05 +0000 Subject: [PATCH 2/2] Automated autoyapf fixes --- tests/test_module.py | 19 ++++++++++--------- tests/test_profile.py | 11 +++++++++-- tests/test_register.py | 27 ++++++++++++++++++++++----- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/tests/test_module.py b/tests/test_module.py index f099558e..b87cd000 100644 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -8,38 +8,39 @@ def test_logout(self): pass self.app = app.test_client() - ans =self.app.get('/logout') + ans = self.app.get('/logout') self.assertEqual(ans.status_code, 200) def test_home(self): self.app = app.test_client() - ans =self.app.get('/home') + ans = self.app.get('/home') self.assertEqual(ans.status_code, 302) def test_login(self): self.app = app.test_client() - ans =self.app.get('/login') + ans = self.app.get('/login') self.assertEqual(ans.status_code, 200) def test_register(self): self.app = app.test_client() - ans =self.app.get('/register') + ans = self.app.get('/register') self.assertEqual(ans.status_code, 200) def test_dashboard(self): self.app = app.test_client() - ans =self.app.get('/dashboard') + ans = self.app.get('/dashboard') self.assertEqual(ans.status_code, 200) def test_friends(self): - self.app= app.test_client() - ans=self.app.get('/friends') + self.app = app.test_client() + ans = self.app.get('/friends') self.assertEqual(ans.status_code, 200) def test_calories(self): - self.app= app.test_client() - ans=self.app.get('/calories') + self.app = app.test_client() + ans = self.app.get('/calories') self.assertEqual(ans.status_code, 302) + pass diff --git a/tests/test_profile.py b/tests/test_profile.py index 8e01f2d4..6a4e44d6 100644 --- a/tests/test_profile.py +++ b/tests/test_profile.py @@ -3,17 +3,24 @@ from application import app import mongomock + @pytest.fixture def client(): with mongomock.patch(): with app.test_client() as client: yield client + def test_get_user_profile(client): db = mongomock.MongoClient().db db.items.insert_one( - {"email":"ojaskulkarni100@gmail.com" ,"weight":90, "height":180, "target_weight":80,"goal":"75"}, - ) + { + "email": "ojaskulkarni100@gmail.com", + "weight": 90, + "height": 180, + "target_weight": 80, + "goal": "75" + }, ) response = client.get("/user_profile") assert response.status_code == 302 diff --git a/tests/test_register.py b/tests/test_register.py index 74aa36fd..e44b7428 100644 --- a/tests/test_register.py +++ b/tests/test_register.py @@ -2,24 +2,41 @@ import mongomock from application import app + @pytest.fixture def client(): with mongomock.patch(): with app.test_client() as client: yield client + def test_get_user(client): db = mongomock.MongoClient().db db.items.insert_one( - {"name": "OjasTest", "pwd":"hshaksjn", "weight":90, "height":180, "target_weight":80, "start_date":"2023-10-15", "target_date": -"2023-11-15"}, - ) + { + "name": "OjasTest", + "pwd": "hshaksjn", + "weight": 90, + "height": 180, + "target_weight": 80, + "start_date": "2023-10-15", + "target_date": "2023-11-15" + }, ) response = client.get("/register") assert response.status_code == 200 + def test_insert_user(client): # Make a POST request to the /items endpoint with a JSON payload - response = client.post("/register", json={"name": "OjasTest", "pwd":"hshaksjn", "weight":"90", "height":"180", "target_weight":"80", "start_date":"2023-10-15", "target_date": -"2023-11-15"}) + response = client.post("/register", + json={ + "name": "OjasTest", + "pwd": "hshaksjn", + "weight": "90", + "height": "180", + "target_weight": "80", + "start_date": "2023-10-15", + "target_date": "2023-11-15" + }) # Assert the response status code is 201 Created assert response.status_code == 200