Skip to content

Commit

Permalink
83%
Browse files Browse the repository at this point in the history
  • Loading branch information
fishlesswater committed Dec 19, 2023
1 parent d5e1ad7 commit 5980a34
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ def setUp(self):
db.nutrition.delete_many({})
# Create a user for signin tests
hashed_password = generate_password_hash(self.password)
db.users.insert_one({
result = db.users.insert_one({
'username': self.username,
'password': hashed_password,
'gender': 'female',
'dob': '1990-01-01',
'height': '170',
'current_weight': '60'
})
# Set user_id from the inserted user
self.user_id = result.inserted_id
# Log in the user
self.client.post('/signin', data={
'username': self.username,
Expand Down Expand Up @@ -119,7 +121,7 @@ def test_nutrition_tracker_post(self):
'calories': 105,
'date': '2022-01-01'
}, follow_redirects=True)
self.assertNotEqual(response.status_code, 200)
self.assertEqual(response.status_code, 200)

# Verify entry was added
entry = db.nutrition.find_one({'food_item': food_item})
Expand Down Expand Up @@ -151,8 +153,29 @@ def tearDown(self):
with app.app_context():
db.users.delete_many({})
db.nutrition.delete_many({})
def test_progress(self):
# Log in the test user
with self.client:
self.client.post('/signin', data={
'username': self.username,
'password': self.password
})
# Simulate user session
with self.client.session_transaction() as sess:
sess['user_id'] = str(self.user_id)

# Test adding a new weight entry
weight = '70'
date = '2022-01-01'
response = self.client.post('/progress', data={
'weight': weight,
'date': date
}, follow_redirects=True)
self.assertEqual(response.status_code, 200)


# Fetch the user's document and check the weight logs
user = db.users.find_one({"_id": self.user_id})
self.assertIsNotNone(user, "User not found in the database.")



Expand Down

0 comments on commit 5980a34

Please sign in to comment.