Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Fix tests

Roland Geiderfc952f0d48bb
diff --git a/wger/manager/tests/test_api_ownership_checks.py b/wger/manager/tests/test_api_ownership_checks.py
index f14d4b1a2..bf6d32f04 100644
--- a/wger/manager/tests/test_api_ownership_checks.py
+++ b/wger/manager/tests/test_api_ownership_checks.py
@@ -102,14 +102,14 @@ class WorkoutLogNextLogOwnershipTestCase(WgerTestCase):
nulls the field, but the API should respond with 403 for consistency
with the other foreign keys on this resource.
- WorkoutLog pk=1 belongs to user 'admin' (pk=1).
+ The seed log belongs to user 'admin' (pk=1).
Routine pk=3 belongs to user 'test' (pk=2).
"""
def test_create_with_foreign_next_log_is_forbidden(self):
self.user_login('test')
- victim_log = WorkoutLog.objects.get(pk=1)
+ victim_log = WorkoutLog.objects.get(pk='aaaaaaaa-aaaa-aaaa-aaaa-000000000001')
self.assertEqual(victim_log.user_id, 1)
response = self.client.post(
diff --git a/wger/nutrition/tests/test_ingredient.py b/wger/nutrition/tests/test_ingredient.py
index 20bea97b4..5ad419559 100644
--- a/wger/nutrition/tests/test_ingredient.py
+++ b/wger/nutrition/tests/test_ingredient.py
@@ -266,23 +266,19 @@ class IngredientSearchTestCase(WgerTestCase):
Helper function - Searches in English
"""
- # The query has to be long enough to clear the trigram similarity
- # threshold (default 0.3) — short terms like "test" get diluted by
- # the trigrams of longer ingredient names and find nothing.
response = self.client.get(
reverse('api-ingredientinfo-list'),
- {'name__search': 'Ingredient', 'language__code': 'en'},
+ {'name__search': 'test', 'language__code': 'en'},
)
self.assertEqual(response.status_code, 200)
result = json.loads(response.content.decode('utf8'))
- self.assertEqual(result['count'], 4)
+ self.assertEqual(result['count'], 2)
- # Trigram ranks shorter names higher (the query is a larger fraction
- # of their trigrams). "Pending ingredient" beats "Test ingredient 1".
ingredient_1 = result['results'][0]
- self.assertEqual(ingredient_1['id'], 7)
- self.assertEqual(ingredient_1['name'], 'Pending ingredient')
+ self.assertEqual(ingredient_1['id'], 2)
+ self.assertEqual(ingredient_1['name'], 'Ingredient, test, 2, organic, raw')
+ self.assertEqual(ingredient_1['uuid'], '44dc5966-73a2-4df7-8b15-f6d37a8990d9')
self.assertEqual(ingredient_1['language']['id'], 2)
self.assertEqual(ingredient_1['image'], None)
self.assertEqual(ingredient_1['thumbnails'], None)
@@ -300,10 +296,9 @@ class IngredientSearchTestCase(WgerTestCase):
Helper function - Searches in German
"""
- # See search_ingredient_en for why "test" doesn't work as a query.
response = self.client.get(
reverse('api-ingredientinfo-list'),
- {'name__search': 'Testzutat', 'language__code': 'de'},
+ {'name__search': 'test', 'language__code': 'de'},
)
self.assertEqual(response.status_code, 200)
result = json.loads(response.content.decode('utf8'))
diff --git a/wger/nutrition/tests/test_search_api.py b/wger/nutrition/tests/test_search_api.py
index aeb81e6b6..105354c45 100644
--- a/wger/nutrition/tests/test_search_api.py
+++ b/wger/nutrition/tests/test_search_api.py
@@ -28,32 +28,26 @@ class SearchIngredientApiTestCase(BaseTestCase, ApiBaseTestCase):
"""
Logged-out users are also allowed to use the search
"""
- # The query has to be long enough to clear the trigram similarity
- # threshold (default 0.3) — short terms like "test" get diluted by
- # the trigrams of longer ingredient names and find nothing.
- response = self.client.get(self.url + '?name__search=Ingredient&language__code=en')
+ response = self.client.get(self.url + '?name__search=test&language__code=en')
result1 = response.data['results'][0]
self.assertEqual(response.status_code, status.HTTP_200_OK)
- self.assertEqual(response.data['count'], 4)
- # Trigram ranks shorter names higher (the query is a larger fraction
- # of their trigrams). "Pending ingredient" beats "Test ingredient 1"
- # which beats the longer "Ingredient, test, 2, organic, raw".
- self.assertEqual(result1['name'], 'Pending ingredient')
- self.assertEqual(result1['id'], 7)
+ self.assertEqual(response.data['count'], 2)
+ self.assertEqual(result1['name'], 'Ingredient, test, 2, organic, raw')
+ self.assertEqual(result1['id'], 2)
def test_basic_search_logged_in(self):
"""
Logged-in users get the same results
"""
self.authenticate('test')
- response = self.client.get(self.url + '?name__search=Ingredient&language__code=en')
+ response = self.client.get(self.url + '?name__search=test&language__code=en')
result1 = response.data['results'][0]
self.assertEqual(response.status_code, status.HTTP_200_OK)
- self.assertEqual(response.data['count'], 4)
- self.assertEqual(result1['name'], 'Pending ingredient')
- self.assertEqual(result1['id'], 7)
+ self.assertEqual(response.data['count'], 2)
+ self.assertEqual(result1['name'], 'Ingredient, test, 2, organic, raw')
+ self.assertEqual(result1['id'], 2)
def test_search_language_code_en_no_results(self):
"""
@@ -80,7 +74,7 @@ class SearchIngredientApiTestCase(BaseTestCase, ApiBaseTestCase):
"""
Passing different language codes works correctly
"""
- response = self.client.get(self.url + '?name__search=Needed&language__code=en,de')
+ response = self.client.get(self.url + '?name__search=guest&language__code=en,de')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 5)
@@ -89,7 +83,7 @@ class SearchIngredientApiTestCase(BaseTestCase, ApiBaseTestCase):
"""
Unknown language codes are ignored
"""
- response = self.client.get(self.url + '?name__search=Needed&language__code=en,de,kg')
+ response = self.client.get(self.url + '?name__search=guest&language__code=en,de,kg')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 5)
@@ -98,7 +92,7 @@ class SearchIngredientApiTestCase(BaseTestCase, ApiBaseTestCase):
"""
Disable all language filters
"""
- response = self.client.get(self.url + '?name__search=Needed')
+ response = self.client.get(self.url + '?name__search=guest')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['count'], 7)