Self hosted FLOSS fitness/workout, nutrition and weight tracker
Rename migrations
Roland Geider6eb94d2b8c13
diff --git a/wger/measurements/migrations/0006_category_externally_synced_category_metric_type_and_more.py b/wger/measurements/migrations/0006_health_sync.pysimilarity index 100%rename from wger/measurements/migrations/0006_category_externally_synced_category_metric_type_and_more.pyrename to wger/measurements/migrations/0006_health_sync.pydiff --git a/wger/measurements/migrations/0007_official_categories.py b/wger/measurements/migrations/0007_migrate_weight.pysimilarity index 98%rename from wger/measurements/migrations/0007_official_categories.pyrename to wger/measurements/migrations/0007_migrate_weight.pyindex 74df4d41f..4a4ca652c 100644--- a/wger/measurements/migrations/0007_official_categories.py+++ b/wger/measurements/migrations/0007_migrate_weight.py@@ -100,7 +100,7 @@ class Migration(migrations.Migration):dependencies = [('measurements',- '0006_category_externally_synced_category_metric_type_and_more',+ '0006_health_sync',),('weight', '0005_add_uuid'),('core', '0002_auto_20141225_1512'),diff --git a/wger/weight/migrations/0006_delete_weightentry.py b/wger/weight/migrations/0006_delete_weightentry.pyindex 6a1e96c95..5626f4f42 100644--- a/wger/weight/migrations/0006_delete_weightentry.py+++ b/wger/weight/migrations/0006_delete_weightentry.py@@ -57,7 +57,7 @@ class Migration(migrations.Migration):# may only be dropped afterwards. On a full rollback this ordering# also runs the restore here before measurements.0007 deletes the# official categories.- ('measurements', '0007_official_categories'),+ ('measurements', '0007_migrate_weight'),]operations = [diff --git a/wger/weight/tests/test_entry.py b/wger/weight/tests/test_entry.pyindex efd21d7ff..47f6932e7 100644--- a/wger/weight/tests/test_entry.py+++ b/wger/weight/tests/test_entry.py@@ -27,6 +27,7 @@ from wger.measurements.models import (Measurement,)from wger.measurements.models.category import MetricType+from wger.utils.api_token import create_tokenclass WeightEntryTestCase(api_base_test.ApiBaseResourceTestCase):@@ -221,3 +222,48 @@ class WeightEntryLimitsTestCase(api_base_test.ApiBaseTestCase, WgerTestCase):self.assertEqual(self.add_entry(360).status_code, 201)self.assertEqual(self.add_entry(800).status_code, 400)+++class WeightEntryTokenAuthTestCase(WgerTestCase):+ """+ The legacy token path openScale-sync uses++ It authenticates with `Authorization: Token`, never with JWT, and its+ update and delete first look an entry up by date. The 2.6 auth migration+ removed the login endpoints, so this is the contract the sync depends on.+ """++ url = '/api/v2/weightentry/'++ def setUp(self):+ super().setUp()+ self.user = User.objects.get(username='test')+ self.token = create_token(self.user, force_new=True)+ self.auth = {'HTTP_AUTHORIZATION': f'Token {self.token.key}'}++ def test_crud_with_a_token(self):+ """+ Test that a token authenticates the whole find-then-modify cycle+ """+ date = timezone.now()++ response = self.client.post(self.url, {'weight': 81.5, 'date': date}, **self.auth)+ self.assertEqual(response.status_code, 201)+ pk = response.data['id']++ self.assertEqual(self.client.get(self.url, **self.auth).status_code, 200)++ response = self.client.patch(+ f'{self.url}{pk}/',+ {'weight': 82},+ content_type='application/json',+ **self.auth,+ )+ self.assertEqual(response.status_code, 200)+ self.assertEqual(self.client.delete(f'{self.url}{pk}/', **self.auth).status_code, 204)++ def test_without_a_token(self):+ """+ Test that the endpoint is not open to anonymous callers+ """+ self.assertEqual(self.client.get(self.url).status_code, 403)