Skip to content

Commit

Permalink
Testing
Browse files Browse the repository at this point in the history
Wrote unit tests for testing some of the CRUD operations
ojas1901 committed Oct 19, 2023
1 parent 46f067d commit f7454f4
Showing 5 changed files with 94 additions and 48 deletions.
2 changes: 1 addition & 1 deletion model/model.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
import string

df = pd.read_csv(
'C:\\Users\\Shivam\\Desktop\\calorieApp_server\\model\\cleaned_data.csv')
'model/cleaned_data.csv')
index_list = df.index.tolist()

client = pymongo.MongoClient('mongodb://localhost:27017')
4 changes: 2 additions & 2 deletions tests/test_history.py
Original file line number Diff line number Diff line change
@@ -8,12 +8,12 @@ class TestHistoryService(unittest.TestCase):
def test_total_calories_to_burn_a(self):
tw = 90
cw = 100
self.assertEquals(history.total_calories_to_burn(tw, cw), -77000)
self.assertEqual(history.total_calories_to_burn(tw, cw), -77000)

def test_total_calories_to_burn_b(self):
tw = 100
cw = 90
self.assertEquals(history.total_calories_to_burn(tw, cw), 77000)
self.assertEqual(history.total_calories_to_burn(tw, cw), 77000)

def test_calories_to_burn_a(self):
target_calories = -77000
80 changes: 35 additions & 45 deletions tests/test_module.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,45 @@
import unittest
from application import app


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, 200)
#
# def test_user_profile(self):
# self.app= app.test_client()
# ans=self.app.get('/user_profile')
# self.assertEqual(ans.status_code, 200)
#
# def test_history(self):
# self.app= app.test_client()
# ans=self.app.get('/history')
# self.assertEqual(ans.status_code, 200)

if __name__ == '__main__':
unittest.main()
22 changes: 22 additions & 0 deletions tests/test_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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


def test_get_user_profile(client):
db = mongomock.MongoClient().db

db.items.insert_one(
{"email":"[email protected]" ,"weight":90, "height":180, "target_weight":80,"goal":"75"},
)
response = client.get("/user_profile")
assert response.status_code == 302

34 changes: 34 additions & 0 deletions tests/test_register.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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


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






0 comments on commit f7454f4

Please sign in to comment.