Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add tests for the resources in the weight app
Roland Geider145eddadca58
diff --git a/wger/urls.py b/wger/urls.pyindex 9e9599fe6..7446e08e5 100644--- a/wger/urls.py+++ b/wger/urls.py@@ -11,6 +11,7 @@ from tastypie.api import Apifrom wger.exercises.api import resources as exercises_apifrom wger.nutrition.api import resources as nutrition_apifrom wger.manager.api import resources as manager_api+from wger.weight.api import resources as weight_api## REST API@@ -43,6 +44,9 @@ v1_api.register(manager_api.SetResource())v1_api.register(manager_api.SettingResource())v1_api.register(manager_api.WorkoutLogResource())+# Weight app+v1_api.register(weight_api.WeightEntryResource())+from django.contrib import adminadmin.autodiscover()diff --git a/wger/weight/api/__init__.py b/wger/weight/api/__init__.pynew file mode 100644index 000000000..e69de29bbdiff --git a/wger/weight/api/resources.py b/wger/weight/api/resources.pynew file mode 100644index 000000000..9a3e85eef--- /dev/null+++ b/wger/weight/api/resources.py@@ -0,0 +1,40 @@+# -*- coding: utf-8 -*-++# This file is part of wger Workout Manager.+#+# wger Workout Manager is free software: you can redistribute it and/or modify+# it under the terms of the GNU Affero General Public License as published by+# the Free Software Foundation, either version 3 of the License, or+# (at your option) any later version.+#+# wger Workout Manager is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU Affero General Public License++from tastypie.authentication import ApiKeyAuthentication+from tastypie.resources import ModelResource++from wger.weight.models import WeightEntry+from wger.utils.resources import UserObjectsOnlyAuthorization+++class WeightEntryResource(ModelResource):+ '''+ Resource for weight entries+ '''++ #meals = fields.ToManyField('wger.nutrition.api.resources.MealResource', 'meal_set')++ def authorized_read_list(self, object_list, bundle):+ '''+ Filter to own objects+ '''+ return object_list.filter(user=bundle.request.user)++ class Meta:+ queryset = WeightEntry.objects.all()+ authentication = ApiKeyAuthentication()+ authorization = UserObjectsOnlyAuthorization()diff --git a/wger/weight/tests/test_entry.py b/wger/weight/tests/test_entry.pyindex f39506623..f7b1a79bb 100644--- a/wger/weight/tests/test_entry.py+++ b/wger/weight/tests/test_entry.py@@ -22,6 +22,7 @@ from wger.manager.tests.testcase import WorkoutManagerTestCasefrom wger.manager.tests.testcase import WorkoutManagerDeleteTestCasefrom wger.manager.tests.testcase import WorkoutManagerEditTestCasefrom wger.manager.tests.testcase import WorkoutManagerAddTestCase+from wger.manager.tests.testcase import ApiBaseResourceTestCaseclass AddWeightEntryTestCase(WorkoutManagerAddTestCase):@@ -49,3 +50,18 @@ class EditWeightEntryTestCase(WorkoutManagerEditTestCase):'creation_date': datetime.date(2013, 2, 1)}user_success = 'test'user_fail = 'admin'+++class WeightEntryTestCase(ApiBaseResourceTestCase):+ '''+ Tests the weight entry overview resource+ '''+ resource = 'weightentry'+ resource_updatable = False+++class WeightEntryDetailApiTestCase(ApiBaseResourceTestCase):+ '''+ Tests accessing a specific weight entry+ '''+ resource = 'weightentry/3'\ No newline at end of file