Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Remove more unused code

Roland Geider2cb3b97e2463
diff --git a/wger/manager/tests/test_schedule.py b/wger/manager/tests/test_schedule.py
deleted file mode 100644
index 68bdb6685..000000000
--- a/wger/manager/tests/test_schedule.py
+++ /dev/null
@@ -1,732 +0,0 @@
-# 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
-
-# Standard Library
-import datetime
-import logging
-
-# Django
-from django.contrib.auth.models import User
-from django.urls import reverse
-
-# wger
-from wger.core.tests import api_base_test
-from wger.core.tests.base_testcase import (
- STATUS_CODES_FAIL,
- WgerAddTestCase,
- WgerDeleteTestCase,
- WgerEditTestCase,
- WgerTestCase,
-)
-from wger.manager.models import (
- Schedule,
- ScheduleStep,
- Workout,
-)
-from wger.utils.helpers import make_token
-
-
-logger = logging.getLogger(__name__)
-
-
-class ScheduleAccessTestCase(WgerTestCase):
- """
- Test accessing the workout page
- """
-
- def test_access_shared(self):
- """
- Test accessing the URL of a shared workout
- """
- workout = Schedule.objects.get(pk=2)
-
- self.user_login('admin')
- response = self.client.get(workout.get_absolute_url())
- self.assertEqual(response.status_code, 200)
-
- self.user_login('test')
- response = self.client.get(workout.get_absolute_url())
- self.assertEqual(response.status_code, 200)
-
- self.user_logout()
- response = self.client.get(workout.get_absolute_url())
- self.assertEqual(response.status_code, 200)
-
- def test_access_not_shared(self):
- """
- Test accessing the URL of a private workout
- """
- workout = Schedule.objects.get(pk=1)
-
- self.user_login('admin')
- response = self.client.get(workout.get_absolute_url())
- self.assertEqual(response.status_code, 403)
-
- self.user_login('test')
- response = self.client.get(workout.get_absolute_url())
- self.assertEqual(response.status_code, 200)
-
- self.user_logout()
- response = self.client.get(workout.get_absolute_url())
- self.assertEqual(response.status_code, 403)
-
-
-class ScheduleRepresentationTestCase(WgerTestCase):
- """
- Test the representation of a model
- """
-
- def test_representation(self):
- """
- Test that the representation of an object is correct
- """
- self.assertEqual(
- str(Schedule.objects.get(pk=1)),
- 'my cool schedule that i found on the internet',
- )
-
-
-class CreateScheduleTestCase(WgerAddTestCase):
- """
- Tests adding a schedule
- """
-
- object_class = Schedule
- url = 'manager:schedule:add'
- user_success = 'test'
- user_fail = False
- data = {
- 'name': 'My cool schedule',
- 'start_date': datetime.date.today(),
- 'is_active': True,
- 'is_loop': True,
- }
-
-
-class DeleteScheduleTestCase(WgerDeleteTestCase):
- """
- Tests deleting a schedule
- """
-
- object_class = Schedule
- url = 'manager:schedule:delete'
- pk = 1
- user_success = 'test'
- user_fail = 'admin'
-
-
-class EditScheduleTestCase(WgerEditTestCase):
- """
- Tests editing a schedule
- """
-
- object_class = Schedule
- url = 'manager:schedule:edit'
- pk = 3
- data = {
- 'name': 'An updated name',
- 'start_date': datetime.date.today(),
- 'is_active': True,
- 'is_loop': True,
- }
-
-
-class ScheduleTestCase(WgerTestCase):
- """
- Other tests
- """
-
- def schedule_detail_page(self):
- """
- Helper function
- """
-
- response = self.client.get(reverse('manager:schedule:view', kwargs={'pk': 2}))
- self.assertEqual(response.status_code, 200)
- self.assertContains(response, 'This schedule is a loop')
-
- schedule = Schedule.objects.get(pk=2)
- schedule.is_loop = False
- schedule.save()
-
- response = self.client.get(reverse('manager:schedule:view', kwargs={'pk': 2}))
- self.assertEqual(response.status_code, 200)
- self.assertNotContains(response, 'This schedule is a loop')
-
- def test_schedule_detail_page_owner(self):
- """
- Tests the schedule detail page as the owning user
- """
- self.user_login()
- self.schedule_detail_page()
-
- def test_schedule_overview(self):
- """
- Tests the schedule overview
- """
- self.user_login()
-
- response = self.client.get(reverse('manager:schedule:overview'))
- self.assertEqual(response.status_code, 200)
- self.assertEqual(len(response.context['schedules']), 3)
- self.assertTrue(response.context['schedules'][0].is_active)
- schedule = Schedule.objects.get(pk=4)
- schedule.is_active = False
- schedule.save()
-
- response = self.client.get(reverse('manager:schedule:overview'))
- self.assertEqual(response.status_code, 200)
- self.assertEqual(len(response.context['schedules']), 3)
- for i in range(0, 3):
- self.assertFalse(response.context['schedules'][i].is_active)
-
- def test_schedule_active(self):
- """
- Tests that only one schedule can be active at a time (per user)
- """
-
- def get_schedules():
- schedule1 = Schedule.objects.get(pk=2)
- schedule2 = Schedule.objects.get(pk=3)
- schedule3 = Schedule.objects.get(pk=4)
-
- return (schedule1, schedule2, schedule3)
-
- self.user_login()
- (schedule1, schedule2, schedule3) = get_schedules()
- self.assertTrue(schedule3.is_active)
-
- schedule1.is_active = True
- schedule1.save()
- (schedule1, schedule2, schedule3) = get_schedules()
- self.assertTrue(schedule1.is_active)
- self.assertFalse(schedule2.is_active)
- self.assertFalse(schedule3.is_active)
-
- schedule2.is_active = True
- schedule2.save()
- (schedule1, schedule2, schedule3) = get_schedules()
- self.assertFalse(schedule1.is_active)
- self.assertTrue(schedule2.is_active)
- self.assertFalse(schedule3.is_active)
-
- def start_schedule(self, fail=False):
- """
- Helper function
- """
-
- schedule = Schedule.objects.get(pk=2)
- self.assertFalse(schedule.is_active)
- self.assertNotEqual(schedule.start_date, datetime.date.today())
-
- response = self.client.get(reverse('manager:schedule:start', kwargs={'pk': 2}))
- schedule = Schedule.objects.get(pk=2)
- if fail:
- self.assertIn(response.status_code, STATUS_CODES_FAIL)
- self.assertFalse(schedule.is_active)
- self.assertNotEqual(schedule.start_date, datetime.date.today())
- else:
- self.assertEqual(response.status_code, 302)
- self.assertTrue(schedule.is_active)
- self.assertEqual(schedule.start_date, datetime.date.today())
-
- def test_start_schedule_owner(self):
- """
- Tests starting a schedule as the owning user
- """
-
- self.user_login()
- self.start_schedule()
-
- def test_start_schedule_other(self):
- """
- Tests starting a schedule as a different user
- """
-
- self.user_login('test')
- self.start_schedule(fail=True)
-
- def test_start_schedule_anonymous(self):
- """
- Tests starting a schedule as a logged out user
- """
-
- self.start_schedule(fail=True)
-
-
-class ScheduleEndDateTestCase(WgerTestCase):
- """
- Test the schedule's get_end_date method
- """
-
- def test_loop_schedule(self):
- """
- Loop schedules have no end date
- """
- schedule = Schedule.objects.get(pk=2)
- self.assertTrue(schedule.is_loop)
- self.assertFalse(schedule.get_end_date())
-
- def test_calculate(self):
- """
- Test the actual calculation
-
- Steps: 3, 5 and 2 weeks, starting on the 2013-04-21
- """
- schedule = Schedule.objects.get(pk=2)
- schedule.is_loop = False
- schedule.save()
- self.assertEqual(schedule.get_end_date(), datetime.date(2013, 6, 30))
-
- def test_empty_schedule(self):
- """
- Test the end date with an empty schedule
- """
- schedule = Schedule.objects.get(pk=3)
- self.assertEqual(schedule.get_end_date(), schedule.start_date)
-
-
-class ScheduleModelTestCase(WgerTestCase):
- """
- Tests the model methods
- """
-
- def delete_objects(self, user):
- """
- Helper function
- """
-
- Workout.objects.filter(user=user).delete()
- Schedule.objects.filter(user=user).delete()
-
- def create_schedule(self, user, start_date=datetime.date.today(), is_loop=False):
- """
- Helper function
- """
-
- schedule = Schedule()
- schedule.user = user
- schedule.name = 'temp'
- schedule.is_active = True
- schedule.start_date = start_date
- schedule.is_loop = is_loop
- schedule.save()
- return schedule
-
- def create_workout(self, user):
- """
- Helper function
- """
-
- workout = Workout()
- workout.user = user
- workout.save()
- return workout
-
- def test_get_workout_steps_test_1(self):
- """
- Test with no workouts and no schedule steps
- """
- self.user_login('test')
- user = User.objects.get(pk=2)
- self.delete_objects(user)
-
- schedule = self.create_schedule(user)
- self.assertFalse(schedule.get_current_scheduled_workout())
-
- def test_get_workout_steps_test_2(self):
- """
- Test with one schedule step
- """
- self.user_login('test')
- user = User.objects.get(pk=2)
- self.delete_objects(user)
-
- schedule = self.create_schedule(user)
- workout = self.create_workout(user)
- step = ScheduleStep()
- step.schedule = schedule
- step.workout = workout
- step.duration = 3
- step.save()
- self.assertEqual(schedule.get_current_scheduled_workout().workout, workout)
-
- def test_get_workout_steps_test_3(self):
- """
- Test with 3 steps
- """
- self.user_login('test')
- user = User.objects.get(pk=2)
- self.delete_objects(user)
-
- start_date = datetime.date.today() - datetime.timedelta(weeks=4)
- schedule = self.create_schedule(user, start_date=start_date)
- workout = self.create_workout(user)
- step = ScheduleStep()
- step.schedule = schedule
- step.workout = workout
- step.duration = 3
- step.order = 1
- step.save()
-
- workout2 = self.create_workout(user)
- step2 = ScheduleStep()
- step2.schedule = schedule
- step2.workout = workout2
- step2.duration = 1
- step2.order = 2
- step2.save()
-
- workout3 = self.create_workout(user)
- step3 = ScheduleStep()
- step3.schedule = schedule
- step3.workout = workout3
- step3.duration = 2
- step3.order = 3
- step3.save()
- self.assertEqual(schedule.get_current_scheduled_workout().workout, workout2)
-
- def test_get_workout_steps_test_4(self):
- """
- Test with 3 steps. Start is too far in the past, schedule ist not a loop
- """
- self.user_login('test')
- user = User.objects.get(pk=2)
- self.delete_objects(user)
-
- start_date = datetime.date.today() - datetime.timedelta(weeks=7)
- schedule = self.create_schedule(user, start_date=start_date)
- workout = self.create_workout(user)
- step = ScheduleStep()
- step.schedule = schedule
- step.workout = workout
- step.duration = 3
- step.order = 1
- step.save()
-
- workout2 = self.create_workout(user)
- step2 = ScheduleStep()
- step2.schedule = schedule
- step2.workout = workout2
- step2.duration = 1
- step2.order = 2
- step2.save()
-
- workout3 = self.create_workout(user)
- step3 = ScheduleStep()
- step3.schedule = schedule
- step3.workout = workout3
- step3.duration = 2
- step3.order = 3
- step3.save()
- self.assertFalse(schedule.get_current_scheduled_workout())
-
- def test_get_workout_steps_test_5(self):
- """
- Test with 3 steps. Start is too far in the past but schedule is a loop
- """
- self.user_login('test')
- user = User.objects.get(pk=2)
- self.delete_objects(user)
-
- start_date = datetime.date.today() - datetime.timedelta(weeks=7)
- schedule = self.create_schedule(user, start_date=start_date, is_loop=True)
- workout = self.create_workout(user)
- step = ScheduleStep()
- step.schedule = schedule
- step.workout = workout
- step.duration = 3
- step.order = 1
- step.save()
-
- workout2 = self.create_workout(user)
- step2 = ScheduleStep()
- step2.schedule = schedule
- step2.workout = workout2
- step2.duration = 1
- step2.order = 2
- step2.save()
-
- workout3 = self.create_workout(user)
- step3 = ScheduleStep()
- step3.schedule = schedule
- step3.workout = workout3
- step3.duration = 2
- step3.order = 3
- step3.save()
- self.assertTrue(schedule.get_current_scheduled_workout().workout, workout)
-
-
-class SchedulePdfExportTestCase(WgerTestCase):
- """
- Test exporting a schedule as a pdf
- """
-
- def export_pdf_token(self, pdf_type='log'):
- """
- Helper function to test exporting a workout as a pdf using tokens
- """
-
- user = User.objects.get(username='test')
- uid, token = make_token(user)
- response = self.client.get(
- reverse(
- f'manager:schedule:pdf-{pdf_type}',
- kwargs={'pk': 1, 'uidb64': uid, 'token': token},
- )
- )
-
- self.assertEqual(response.status_code, 200)
- self.assertEqual(response['Content-Type'], 'application/pdf')
- self.assertEqual(
- response['Content-Disposition'],
- f'attachment; filename=Schedule-1-{pdf_type}.pdf',
- )
-
- # Approximate size only
- self.assertGreater(int(response['Content-Length']), 29000)
- self.assertLess(int(response['Content-Length']), 35000)
-
- # Wrong or expired token
- uid = 'MQ'
- token = '3xv-57ef74923091fe7f186e'
- response = self.client.get(
- reverse(
- f'manager:schedule:pdf-{pdf_type}',
- kwargs={'pk': 1, 'uidb64': uid, 'token': token},
- )
- )
- self.assertEqual(response.status_code, 403)
-
- def export_pdf(self, fail=False, pdf_type='log'):
- """
- Helper function to test exporting a workout as a pdf
- """
-
- response = self.client.get(reverse(f'manager:schedule:pdf-{pdf_type}', kwargs={'pk': 1}))
-
- if fail:
- self.assertIn(response.status_code, (403, 404, 302))
- else:
- self.assertEqual(response.status_code, 200)
- self.assertEqual(response['Content-Type'], 'application/pdf')
- self.assertEqual(
- response['Content-Disposition'],
- f'attachment; filename=Schedule-1-{pdf_type}.pdf',
- )
-
- # Approximate size only
- self.assertGreater(int(response['Content-Length']), 29000)
- self.assertLess(int(response['Content-Length']), 35000)
-
- def export_pdf_with_comments(self, fail=False, pdf_type='log'):
- """
- Helper function to test exporting a workout as a pdf, with exercise coments
- """
-
- user = User.objects.get(username='test')
- uid, token = make_token(user)
- response = self.client.get(
- reverse(
- f'manager:schedule:pdf-{pdf_type}',
- kwargs={'pk': 3, 'images': 0, 'comments': 1, 'uidb64': uid, 'token': token},
- )
- )
-
- if fail:
- self.assertIn(response.status_code, (403, 404, 302))
- else:
- self.assertEqual(response.status_code, 200)
- self.assertEqual(response['Content-Type'], 'application/pdf')
- self.assertEqual(
- response['Content-Disposition'],
- f'attachment; filename=Schedule-3-{pdf_type}.pdf',
- )
-
- # Approximate size only
- self.assertGreater(int(response['Content-Length']), 29000)
- self.assertLess(int(response['Content-Length']), 35000)
-
- def export_pdf_with_images(self, fail=False, pdf_type='log'):
- """
- Helper function to test exporting a workout as a pdf, with exercise images
- """
- user = User.objects.get(username='test')
- uid, token = make_token(user)
- response = self.client.get(
- reverse(
- f'manager:schedule:pdf-{pdf_type}',
- kwargs={'pk': 3, 'images': 1, 'comments': 0, 'uidb64': uid, 'token': token},
- )
- )
-
- if fail:
- self.assertIn(response.status_code, (403, 404, 302))
- else:
- self.assertEqual(response.status_code, 200)
- self.assertEqual(response['Content-Type'], 'application/pdf')
- self.assertEqual(
- response['Content-Disposition'],
- f'attachment; filename=Schedule-3-{pdf_type}.pdf',
- )
-
- # Approximate size only
- self.assertGreater(int(response['Content-Length']), 29000)
- self.assertLess(int(response['Content-Length']), 35000)
-
- def export_pdf_with_images_and_comments(self, fail=False, pdf_type='log'):
- """
- Helper function to test exporting a workout as a pdf, with images and comments
- """
-
- user = User.objects.get(username='test')
- uid, token = make_token(user)
- response = self.client.get(
- reverse(
- f'manager:schedule:pdf-{pdf_type}',
- kwargs={'pk': 3, 'images': 1, 'comments': 1, 'uidb64': uid, 'token': token},
- )
- )
-
- if fail:
- self.assertIn(response.status_code, (403, 404, 302))
- else:
- self.assertEqual(response.status_code, 200)
- self.assertEqual(response['Content-Type'], 'application/pdf')
- self.assertEqual(
- response['Content-Disposition'],
- f'attachment; filename=Schedule-3-{pdf_type}.pdf',
- )
-
- # Approximate size only
- self.assertGreater(int(response['Content-Length']), 29000)
- self.assertLess(int(response['Content-Length']), 35000)
-
- def test_export_pdf_log_anonymous(self):
- """
- Tests exporting a workout as a pdf as an anonymous user
- """
-
- self.export_pdf(fail=True)
- self.export_pdf_token()
-
- def test_export_pdf_log_owner(self):
- """
- Tests exporting a workout as a pdf as the owner user
- """
-
- self.user_login('test')
- self.export_pdf(fail=False)
- self.export_pdf_token()
-
- def test_export_pdf_log_other(self):
- """
- Tests exporting a workout as a pdf as a logged user not owning the data
- """
-
- self.user_login('admin')
- self.export_pdf(fail=True)
- self.export_pdf_token()
-
- def test_export_pdf_log_with_comments(self, fail=False):
- """
- Tests exporting a workout as a pdf as the owner user with comments
- """
- self.user_login('test')
- self.export_pdf_with_comments(fail=False)
- self.export_pdf_token()
-
- def test_export_pdf_log_with_images(self, fail=False):
- """
- Tests exporting a workout as a pdf as the owner user with images
- """
- self.user_login('test')
- self.export_pdf_with_images(fail=False)
- self.export_pdf_token()
-
- def test_export_pdf_log_with_images_and_comments(self, fail=False):
- """
- Tests exporting a workout as a pdf as the owner user with images andcomments
- """
- self.user_login('test')
- self.export_pdf_with_images_and_comments(fail=False)
- self.export_pdf_token()
-
- # #####TABLE#####
-
- def test_export_pdf_table_anonymous(self):
- """
- Tests exporting a workout as a pdf as an anonymous user
- """
-
- self.export_pdf(fail=True, pdf_type='table')
- self.export_pdf_token(pdf_type='table')
-
- def test_export_pdf_table_owner(self):
- """
- Tests exporting a workout as a pdf as the owner user
- """
-
- self.user_login('test')
- self.export_pdf(fail=False, pdf_type='table')
- self.export_pdf_token(pdf_type='table')
-
- def test_export_pdf_table_other(self):
- """
- Tests exporting a workout as a pdf as a logged user not owning the data
- """
-
- self.user_login('admin')
- self.export_pdf(fail=True, pdf_type='table')
- self.export_pdf_token(pdf_type='table')
-
- def test_export_pdf_table_with_comments(self, fail=False):
- """
- Tests exporting a workout as a pdf as the owner user with comments
- """
- self.user_login('test')
- self.export_pdf_with_comments(fail=False, pdf_type='table')
- self.export_pdf_token(pdf_type='table')
-
- def test_export_pdf_table_with_images(self, fail=False):
- """
- Tests exporting a workout as a pdf as the owner user with images
- """
- self.user_login('test')
- self.export_pdf_with_images(fail=False, pdf_type='table')
- self.export_pdf_token(pdf_type='table')
-
- def test_export_pdf_table_with_images_and_comments(self, fail=False):
- """
- Tests exporting a workout as a pdf as the owner user with images andcomments
- """
- self.user_login('test')
- self.export_pdf_with_images_and_comments(fail=False, pdf_type='table')
- self.export_pdf_token(pdf_type='table')
-
-
-class ScheduleApiTestCase(api_base_test.ApiBaseResourceTestCase):
- """
- Tests the schedule overview resource
- """
-
- pk = 1
- resource = Schedule
- private_resource = True
- data = {
- 'name': 'An updated name',
- 'start_date': datetime.date.today(),
- 'is_active': True,
- 'is_loop': True,
- }
diff --git a/wger/manager/tests/test_schedule_step.py b/wger/manager/tests/test_schedule_step.py
deleted file mode 100644
index bf364cf4a..000000000
--- a/wger/manager/tests/test_schedule_step.py
+++ /dev/null
@@ -1,107 +0,0 @@
-# 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
-
-# Standard Library
-import datetime
-
-# Django
-from django.urls import reverse_lazy
-
-# wger
-from wger.core.tests import api_base_test
-from wger.core.tests.base_testcase import (
- WgerAddTestCase,
- WgerDeleteTestCase,
- WgerEditTestCase,
- WgerTestCase,
-)
-from wger.manager.models import ScheduleStep
-
-
-class ScheduleStepRepresentationTestCase(WgerTestCase):
- """
- Test the representation of a model
- """
-
- def test_representation(self):
- """
- Test that the representation of an object is correct
- """
- self.assertEqual(str(ScheduleStep.objects.get(pk=1)), 'A test workout')
-
-
-class ScheduleStepTestCase(WgerTestCase):
- """
- Other tests
- """
-
- def test_schedule_dates_util(self, fail=False):
- """
- Test the get_dates() method
- """
- s1 = ScheduleStep.objects.get(pk=1)
- s2 = ScheduleStep.objects.get(pk=2)
- s3 = ScheduleStep.objects.get(pk=3)
-
- self.assertEqual(s1.get_dates(), (datetime.date(2013, 4, 21), datetime.date(2013, 5, 12)))
- self.assertEqual(s2.get_dates(), (datetime.date(2013, 5, 12), datetime.date(2013, 6, 16)))
- self.assertEqual(s3.get_dates(), (datetime.date(2013, 6, 16), datetime.date(2013, 6, 30)))
-
-
-class CreateScheduleStepTestCase(WgerAddTestCase):
- """
- Tests adding a schedule
- """
-
- object_class = ScheduleStep
- url = reverse_lazy('manager:step:add', kwargs={'schedule_pk': 1})
- user_success = 'test'
- user_fail = False
- data = {'workout': 3, 'duration': 4}
-
-
-class EditScheduleStepTestCase(WgerEditTestCase):
- """
- Tests editing a schedule
- """
-
- object_class = ScheduleStep
- url = 'manager:step:edit'
- pk = 2
- data = {'workout': 1, 'duration': 8}
-
-
-class DeleteScheduleStepTestCase(WgerDeleteTestCase):
- """
- Tests editing a schedule
- """
-
- object_class = ScheduleStep
- url = 'manager:step:delete'
- pk = 2
-
-
-class ScheduleStepApiTestCase(api_base_test.ApiBaseResourceTestCase):
- """
- Tests the schedule step overview resource
- """
-
- pk = 4
- resource = ScheduleStep
- private_resource = True
- data = {
- 'workout': '3',
- 'schedule': '1',
- 'duration': '8',
- }
diff --git a/wger/manager/tests/test_weight_log.py b/wger/manager/tests/test_weight_log.py
index dae0227ce..6d00b793d 100644
--- a/wger/manager/tests/test_weight_log.py
+++ b/wger/manager/tests/test_weight_log.py
@@ -36,224 +36,6 @@ from wger.utils.cache import cache_mapper
logger = logging.getLogger(__name__)
-class WeightLogAccessTestCase(WgerTestCase):
- """
- Test accessing the weight log page
- """
-
- def test_access(self):
- """
- Test accessing the URL of a weight log
- """
- url = reverse('manager:log:log', kwargs={'pk': 1})
-
- self.user_login('admin')
- response = self.client.get(url)
- self.assertEqual(response.status_code, 200)
-
- self.user_login('test')
- response = self.client.get(url)
- self.assertEqual(response.status_code, 200)
-
- self.user_logout()
- response = self.client.get(url)
- self.assertEqual(response.status_code, 403)
-
-
-class CalendarAccessTestCase(WgerTestCase):
- """
- Test accessing the calendar page
- """
-
- def test_access(self):
- """
- Test accessing the URL of the calendar page
- """
- url = reverse('manager:workout:calendar')
-
- self.user_login('admin')
- response = self.client.get(url)
- self.assertEqual(response.status_code, 200)
-
- def test_access_not_shared(self):
- """
- Test accessing the URL of an unshared calendar page
- """
- url = reverse('manager:workout:calendar')
-
- response = self.client.get(url)
- self.assertEqual(response.status_code, 403)
-
-
-class WeightLogOverviewAddTestCase(WgerTestCase):
- """
- Tests the weight log functionality
- """
-
- def add_weight_log(self, fail=True):
- """
- Helper function to test adding weight log entries
- """
-
- # Open the log entry page
- response = self.client.get(reverse('manager:day:log', kwargs={'pk': 1}))
- if fail:
- self.assertIn(response.status_code, (302, 403))
- else:
- self.assertEqual(response.status_code, 200)
-
- # Add new log entries
- count_before = WorkoutLog.objects.count()
- form_data = {
- 'date': '2012-01-01',
- 'notes': 'My cool impression',
- 'impression': '3',
- 'time_start': datetime.time(10, 0),
- 'time_end': datetime.time(12, 0),
- 'form-0-reps': 10,
- 'form-0-repetition_unit': 1,
- 'form-0-weight': 10,
- 'form-0-weight_unit': 1,
- 'form-0-rir': '1',
- 'form-1-reps': 10,
- 'form-1-repetition_unit': 1,
- 'form-1-weight': 10,
- 'form-1-weight_unit': 1,
- 'form-1-rir': '2',
- 'form-TOTAL_FORMS': 3,
- 'form-INITIAL_FORMS': 0,
- 'form-MAX-NUM_FORMS': 3,
- }
-
- response = self.client.post(reverse('manager:day:log', kwargs={'pk': 1}), form_data)
- count_after = WorkoutLog.objects.count()
-
- # Logged out users get a 302 redirect to login page
- # Users not owning the workout, a 403, forbidden
- if fail:
- self.assertIn(response.status_code, (302, 403))
- self.assertEqual(count_before, count_after)
- else:
- self.assertEqual(response.status_code, 302)
- self.assertGreater(count_after, count_before)
-
- #
- # Post log without RiR
- #
- form_data['form-0-rir'] = ''
- form_data['form-1-rir'] = ''
- count_before = WorkoutLog.objects.count()
- response = self.client.post(reverse('manager:day:log', kwargs={'pk': 1}), form_data)
- count_after = WorkoutLog.objects.count()
-
- if fail:
- self.assertIn(response.status_code, (302, 403))
- self.assertEqual(count_before, count_after)
- else:
- self.assertEqual(response.status_code, 302)
- self.assertGreater(count_after, count_before)
-
- def test_add_weight_log_anonymous(self):
- """
- Tests adding weight log entries as an anonymous user
- """
-
- self.add_weight_log(fail=True)
-
- def test_add_weight_log_owner(self):
- """
- Tests adding weight log entries as the owner user
- """
-
- self.user_login('admin')
- self.add_weight_log(fail=False)
-
- def test_add_weight_log_other(self):
- """
- Tests adding weight log entries as a logged user not owning the data
- """
-
- self.user_login('test')
- self.add_weight_log(fail=True)
-
-
-class WeightLogDeleteTestCase(WgerDeleteTestCase):
- """
- Tests deleting a WorkoutLog
- """
-
- object_class = WorkoutLog
- url = reverse_lazy('manager:log:delete', kwargs={'pk': 1})
- pk = 1
-
-
-class WeightLogEntryEditTestCase(WgerTestCase):
- """
- Tests editing individual weight log entries
- """
-
- def edit_log_entry(self, fail=True):
- """
- Helper function to test edit log entries
- """
-
- response = self.client.get(reverse('manager:log:edit', kwargs={'pk': 1}))
- if fail:
- self.assertTrue(response.status_code in (302, 403))
-
- else:
- self.assertEqual(response.status_code, 200)
-
- date_before = WorkoutLog.objects.get(pk=1).date
- response = self.client.post(
- reverse('manager:log:edit', kwargs={'pk': 1}),
- {
- 'date': '2012-01-01',
- 'reps': 10,
- 'repetition_unit': 2,
- 'weight_unit': 3,
- 'weight': 10,
- 'exercise_base': 1,
- 'rir': 2,
- },
- )
-
- date_after = WorkoutLog.objects.get(pk=1).date
-
- if fail:
- # Logged out users get a 302 redirect to login page
- # Users not owning the workout, a 403, forbidden
- self.assertTrue(response.status_code in (302, 403))
- self.assertEqual(date_before, date_after)
-
- else:
- self.assertEqual(response.status_code, 302)
- self.assertEqual(date_after, datetime.date(2012, 1, 1))
-
- def test_edit_log_entry_anonymous(self):
- """
- Tests editing a weight log entries as an anonymous user
- """
-
- self.edit_log_entry(fail=True)
-
- def test_edit_log_entry_owner(self):
- """
- Tests editing a weight log entries as the owner user
- """
-
- self.user_login('admin')
- self.edit_log_entry(fail=False)
-
- def test_edit_log_entry_other(self):
- """
- Tests editing a weight log entries as a logged user not owning the data
- """
-
- self.user_login('test')
- self.edit_log_entry(fail=True)
-
-
class WorkoutLogApiTestCase(api_base_test.ApiBaseResourceTestCase):
"""
Tests the workout log overview resource
diff --git a/wger/manager/tests/test_workout.py b/wger/manager/tests/test_workout.py
index 3cab7ea4a..d3258214f 100644
--- a/wger/manager/tests/test_workout.py
+++ b/wger/manager/tests/test_workout.py
@@ -15,95 +15,12 @@
# Standard Library
import datetime
-# Django
-from django.urls import reverse
-
# wger
from wger.core.tests import api_base_test
-from wger.core.tests.base_testcase import (
- WgerDeleteTestCase,
- WgerEditTestCase,
- WgerTestCase,
-)
+from wger.core.tests.base_testcase import WgerTestCase
from wger.manager.models import Workout
-class AddWorkoutTestCase(WgerTestCase):
- """
- Tests adding a Workout
- """
-
- def create_workout(self):
- """
- Helper function to test creating workouts
- """
-
- # Create a workout
- count_before = Workout.objects.count()
- response = self.client.get(reverse('manager:workout:add'))
- count_after = Workout.objects.count()
-
- # There is always a redirect
- self.assertEqual(response.status_code, 302)
-
- # Test creating workout
- self.assertGreater(count_after, count_before)
-
- # Test accessing workout
- response = self.client.get(reverse('manager:workout:view', kwargs={'pk': 1}))
- self.assertEqual(response.status_code, 200)
-
- def test_create_workout_logged_in(self):
- """
- Test creating a workout a logged in user
- """
-
- self.user_login()
- self.create_workout()
- self.user_logout()
-
-
-class DeleteTestWorkoutTestCase(WgerDeleteTestCase):
- """
- Tests deleting a Workout
- """
-
- object_class = Workout
- url = 'manager:workout:delete'
- pk = 3
- user_success = 'test'
- user_fail = 'admin'
-
-
-class EditWorkoutTestCase(WgerEditTestCase):
- """
- Tests editing a Workout
- """
-
- object_class = Workout
- url = 'manager:workout:edit'
- pk = 3
- user_success = 'test'
- user_fail = 'admin'
- data = {'name': 'A new comment'}
-
-
-class WorkoutOverviewTestCase(WgerTestCase):
- """
- Tests the workout overview
- """
-
- def get_workout_overview(self):
- """
- Helper function to test the workout overview
- """
-
- response = self.client.get(reverse('manager:routine:overview'))
-
- # Page exists
- self.assertEqual(response.status_code, 200)
-
-
class WorkoutModelTestCase(WgerTestCase):
"""
Tests other functionality from the model
diff --git a/wger/manager/tests/test_workout_session.py b/wger/manager/tests/test_workout_session.py
index 4de05e8a4..f81d8bb17 100644
--- a/wger/manager/tests/test_workout_session.py
+++ b/wger/manager/tests/test_workout_session.py
@@ -15,180 +15,9 @@
# Standard Library
import datetime
-# Django
-from django.contrib.auth.models import User
-from django.core.cache import cache
-from django.core.exceptions import ValidationError
-from django.urls import (
- reverse,
- reverse_lazy,
-)
-
# wger
from wger.core.tests import api_base_test
-from wger.core.tests.base_testcase import (
- WgerAddTestCase,
- WgerDeleteTestCase,
- WgerEditTestCase,
- WgerTestCase,
-)
-from wger.manager.models import (
- Workout,
- WorkoutLog,
- WorkoutSession,
-)
-from wger.utils.cache import cache_mapper
-
-
-"""
-Tests for workout sessions
-"""
-
-
-class AddWorkoutSessionTestCase(WgerAddTestCase):
- """
- Tests adding a workout session
- """
-
- object_class = WorkoutSession
- url = reverse_lazy(
- 'manager:session:add',
- kwargs={
- 'workout_pk': 1,
- 'year': datetime.date.today().year,
- 'month': datetime.date.today().month,
- 'day': datetime.date.today().day,
- },
- )
- data = {
- 'user': 1,
- 'workout': 1,
- 'date': datetime.date.today(),
- 'notes': 'Some interesting and deep insights',
- 'impression': '3',
- 'time_start': datetime.time(10, 0),
- 'time_end': datetime.time(13, 0),
- }
-
-
-class EditWorkoutSessionTestCase(WgerEditTestCase):
- """
- Tests editing a workout session
- """
-
- object_class = WorkoutSession
- url = 'manager:session:edit'
- pk = 3
- data = {
- 'user': 1,
- 'workout': 2,
- 'date': datetime.date(2014, 1, 30),
- 'notes': 'My new insights',
- 'impression': '3',
- 'time_start': datetime.time(10, 0),
- 'time_end': datetime.time(13, 0),
- }
-
-
-class WorkoutSessionModelTestCase(WgerTestCase):
- """
- Tests other functionality from the model
- """
-
- def test_unicode(self):
- """
- Test the unicode representation
- """
-
- session = WorkoutSession()
- session.workout = Workout.objects.get(pk=1)
- session.date = datetime.date.today()
- self.assertEqual(
- str(session),
- f'{Workout.objects.get(pk=1)} - {datetime.date.today()}',
- )
-
-
-class DeleteTestWorkoutTestCase(WgerDeleteTestCase):
- """
- Tests deleting a Workout
- """
-
- object_class = WorkoutSession
- url = 'manager:session:delete'
- pk = 3
-
-
-class WorkoutSessionDeleteLogsTestCase(WgerTestCase):
- """
- Tests that deleting a session can also delete all weight logs
- """
-
- def test_delete_logs(self):
- self.user_login('admin')
-
- session = WorkoutSession.objects.get(pk=1)
- self.assertEqual(WorkoutSession.objects.all().count(), 4)
- count_before = WorkoutLog.objects.filter(
- user__username=session.user.username,
- date=session.date,
- ).count()
- self.assertEqual(count_before, 1)
-
- response = self.client.post(
- reverse('manager:session:delete', kwargs={'pk': 1, 'logs': 'logs'})
- )
- self.assertEqual(response.status_code, 302)
- self.assertEqual(WorkoutSession.objects.all().count(), 3)
-
- count_after = WorkoutLog.objects.filter(
- user__username=session.user.username,
- date=session.date,
- ).count()
- self.assertEqual(count_after, 0)
-
-
-class WorkoutSessionTestCase(WgerTestCase):
- """
- Tests other workout session methods
- """
-
- def test_model_validation(self):
- """
- Tests the custom clean() method
- """
- self.user_login('admin')
-
- # Values OK
- session = WorkoutSession()
- session.workout = Workout.objects.get(pk=2)
- session.user = User.objects.get(pk=1)
- session.date = datetime.date.today()
- session.time_start = datetime.time(12, 0)
- session.time_end = datetime.time(13, 0)
- session.impression = '3'
- session.notes = 'Some notes here'
- self.assertFalse(session.full_clean())
-
- # No start or end times, also OK
- session.time_start = None
- session.time_end = None
- self.assertFalse(session.full_clean())
-
- # Start time but not end time
- session.time_start = datetime.time(17, 0)
- session.time_end = None
- self.assertRaises(ValidationError, session.full_clean)
-
- # No start time but end time
- session.time_start = None
- session.time_end = datetime.time(17, 0)
- self.assertRaises(ValidationError, session.full_clean)
-
- # Start time after end time
- session.time_start = datetime.time(17, 0)
- session.time_end = datetime.time(13, 0)
- self.assertRaises(ValidationError, session.full_clean)
+from wger.manager.models import WorkoutSession
class WorkoutSessionApiTestCase(api_base_test.ApiBaseResourceTestCase):