@@ -0,0 +1,3529 @@
+# This file is part of wger Workout Manager.%0A#%0A# wger Workout Manager is free software: you can redistribute it and/or modify%0A# it under the terms of the GNU Affero General Public License as published by%0A# the Free Software Foundation, either version 3 of the License, or%0A# (at your option) any later version.%0A#%0A# wger Workout Manager is distributed in the hope that it will be useful,%0A# but WITHOUT ANY WARRANTY; without even the implied warranty of%0A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A# GNU General Public License for more details.%0A#%0A# You should have received a copy of the GNU Affero General Public License%0A%0Aimport json%0Aimport decimal%0Aimport datetime%0A%0Afrom django.core.urlresolvers import reverse%0Afrom django.contrib.auth.models import User%0A%0Afrom wger.weight.models import WeightEntry%0Afrom wger.manager.tests.testcase import WorkoutManagerTestCase%0A%0A%0Aclass BmiTestCase(WorkoutManagerTestCase):%0A    '''%0A    Tests the BMI methods and views%0A    '''%0A%0A    def test_page(self):%0A        '''%0A        Access the BMI page%0A        '''%0A%0A        response = self.client.get(reverse('bmi-view'))%0A        self.assertEqual(response.status_code, 200)%0A%0A    def test_calculator(self):%0A        '''%0A        Tests the calculator itself%0A        '''%0A%0A        self.user_login('test')%0A        response = self.client.post(reverse('bmi-calculate'),%0A                                    %7B'height': 180,%0A                                     'weight': 80%7D)%0A        self.assertEqual(response.status_code, 200)%0A        bmi = json.loads(response.content)%0A        self.assertEqual(decimal.Decimal(bmi%5B'bmi'%5D), decimal.Decimal('24.69'))%0A        self.assertEqual(decimal.Decimal(bmi%5B'weight'%5D), decimal.Decimal('80'))%0A        self.assertEqual(decimal.Decimal(bmi%5B'height'%5D), decimal.Decimal('180'))%0A%0A    def test_automaitc_weight_entry(self):%0A        '''%0A        Tests that weight entries are automatically created or updated%0A        '''%0A%0A        self.user_login('test')%0A        user = User.objects.get(username=self.current_user)%0A%0A        # Existing weight entry is old, a new one is created%0A        entry1 = WeightEntry.objects.filter(user=user).latest()%0A        response = self.client.post(reverse('bmi-calculate'),%0A                                    %7B'height': 180,%0A                                     'weight': 80%7D)%0A        self.assertEqual(response.status_code, 200)%0A        entry2 = WeightEntry.objects.filter(user=user).latest()%0A        self.assertEqual(entry1.weight, 83)%0A        self.assertEqual(entry2.weight, 80)%0A%0A        # Existing weight entry is from today, is updated%0A        entry2.delete()%0A        entry1.creation_date = datetime.date.today()%0A        entry1.save()%0A        response = self.client.post(reverse('bmi-calculate'),%0A                                    %7B'height': 180,%0A                                     'weight': 80%7D)%0A        self.assertEqual(response.status_code, 200)%0A        entry2 = WeightEntry.objects.filter(user=user).latest()%0A        self.assertEqual(entry1.pk, entry2.pk)%0A        self.assertEqual(entry2.weight, 80)%0A%0A        # No existing entries%0A        WeightEntry.objects.filter(user=user).delete()%0A        response = self.client.post(reverse('bmi-calculate'),%0A                                    %7B'height': 180,%0A                                     'weight': 80%7D)%0A        self.assertEqual(response.status_code, 200)%0A        entry = WeightEntry.objects.filter(user=user).latest()%0A        self.assertEqual(entry.weight, 80)%0A        self.assertEqual(entry.creation_date, datetime.date.today())%0A

Add tests for the BMI calculator