Self hosted FLOSS fitness/workout, nutrition and weight tracker
Rewrite the tests using the more compact base testcase
Roland Geidera0ec55886b95
diff --git a/wger/weight/tests/entry.py b/wger/weight/tests/entry.pyindex 708157649..5a4124812 100644--- a/wger/weight/tests/entry.py+++ b/wger/weight/tests/entry.py@@ -19,116 +19,33 @@ from django.core.urlresolvers import reversefrom wger.weight.models import WeightEntryfrom wger.manager.tests.testcase import WorkoutManagerTestCase+from wger.manager.tests.testcase import WorkoutManagerDeleteTestCase+from wger.manager.tests.testcase import WorkoutManagerEditTestCase+from wger.manager.tests.testcase import WorkoutManagerAddTestCase-class AddWeightEntryTestCase(WorkoutManagerTestCase):+class AddWeightEntryTestCase(WorkoutManagerAddTestCase):'''Tests adding a weight entry'''- def add_entry(self, fail=False):- '''- Helper function to test adding a weight entry- '''+ object_class = WeightEntry+ url = 'weight-add'+ pk = 8+ user_fail = False+ data = {'weight': 81.1,+ 'creation_date': datetime.date(2013, 2, 1)}- # Fetch the add entry page- response = self.client.get(reverse('weight-add'))- if fail:- self.assertIn(response.status_code, (302, 403))- self.assertTemplateUsed('login.html')-- else:- self.assertEqual(response.status_code, 200)-- # Enter the data- response = self.client.post(reverse('weight-add'),- {'weight': '81',- 'creation_date': '2013-02-01'})- if fail:- self.assertRaises(WeightEntry.DoesNotExist, WeightEntry.objects.get, pk=8)- self.assertIn(response.status_code, (302, 403))- self.assertTemplateUsed('login.html')-- else:- entry = WeightEntry.objects.get(pk=8)- self.assertEqual(response.status_code, 302)- self.assertEqual(entry.weight, 81)- self.assertEqual(entry.creation_date, datetime.date(2013, 2, 1))-- def test_add_entry_anonymous(self):- '''- Test adding a weight entry as an anonymous user- '''-- self.add_entry(fail=True)-- def test_add_entry_logged_in(self):- '''- Test adding a weight entry as a logged in user- '''-- self.user_login('test')- self.add_entry(fail=False)---class EditWeightEntryTestCase(WorkoutManagerTestCase):+class EditWeightEntryTestCase(WorkoutManagerEditTestCase):'''Tests editing a weight entry'''- def edit_entry(self, fail=False):- '''- Helper function- '''-- # Fetch the day edit page- response = self.client.get(reverse('weight-edit', kwargs={'pk': 1}))-- if fail:- self.assertIn(response.status_code, (302, 403))- self.assertTemplateUsed('login.html')-- else:- self.assertEqual(response.status_code, 200)-- # Edit the day- response = self.client.post(reverse('weight-edit', kwargs={'pk': 1}),- {'weight': 100,- 'creation_date': '2005-01-01'})-- entry = WeightEntry.objects.get(pk=1)-- if fail:- self.assertIn(response.status_code, (302, 403))- self.assertTemplateUsed('login.html')- self.assertEqual(entry.weight, 77)- self.assertEqual(entry.creation_date, datetime.date(2012, 10, 1))-- else:- self.assertEqual(response.status_code, 302)- self.assertEqual(entry.weight, 100)- self.assertEqual(entry.creation_date, datetime.date(2005, 1, 1))-- def test_edit_entry_anonymous(self):- '''- Test editing a weight entry as an anonymous user- '''-- self.edit_entry(fail=True)-- def test_edit_entry_owner(self):- '''- Test editing a weight entry as the owner user- '''-- self.user_login('test')- self.edit_entry(fail=False)-- def test_edit_entry_other(self):- '''- Test editing a weight entry as a different user- '''-- self.user_login('admin')- self.edit_entry(fail=True)+ object_class = WeightEntry+ url = reverse('weight-edit', kwargs={'pk': 1})+ pk = 1+ data = {'weight': 100,+ 'creation_date': datetime.date(2013, 2, 1)}+ user_success = 'test'+ user_fail = 'admin'