def demo_entries(request): """ Creates a set of sample entries for guest users """ if not settings.WGER_SETTINGS['ALLOW_GUEST_USERS']: return HttpResponseRedirect(reverse('software:features')) if (((not request.user.is_authenticated or request.user.userprofile.is_temporary) and not request.session['has_demo_data'])): # If we reach this from a page that has no user created by the # middleware, do that now if not request.user.is_authenticated: user = create_temporary_user() django_login(request, user) # OK, continue create_demo_entries(request.user) request.session['has_demo_data'] = True messages.success( request, _('We have created sample workout, workout schedules, weight ' 'logs, (body) weight and nutrition plan entries so you can ' 'better see what this site can do. Feel free to edit or ' 'delete them!')) return HttpResponseRedirect(reverse('core:dashboard'))
def test_demo_data(self): ''' Tests that the helper function creates demo data (workout, etc.) for the demo users ''' self.client.get(reverse('core:dashboard')) self.assertEqual(self.count_temp_users(), 2) user = User.objects.get(pk=4) self.assertEqual(user.userprofile.is_temporary, True) self.assertEqual(Workout.objects.filter(user=user).count(), 0) create_demo_entries(user) # Workout self.assertEqual(Workout.objects.filter(user=user).count(), 4) self.assertEqual(Day.objects.filter(training__user=user).count(), 2) self.assertEqual(WorkoutLog.objects.filter(user=user).count(), 56) # Schedule self.assertEqual(Schedule.objects.filter(user=user).count(), 3) self.assertEqual(ScheduleStep.objects.filter(schedule__user=user).count(), 6) # Nutrition self.assertEqual(NutritionPlan.objects.filter(user=user).count(), 1) self.assertEqual(Meal.objects.filter(plan__user=user).count(), 3) # Body weight self.assertEqual(WeightEntry.objects.filter(user=user).count(), 19)
def demo_entries(request): ''' Creates a set of sample entries for guest users ''' if (((not request.user.is_authenticated() or request.user.userprofile.is_temporary) and not request.session['has_demo_data'])): # If we reach this from a page that has no user created by the # middleware, do that now if not request.user.is_authenticated(): user = create_temporary_user() django_login(request, user) # OK, continue create_demo_entries(request.user) request.session['has_demo_data'] = True messages.success(request, _('We have created sample workout, workout schedules, weight ' 'logs, (body) weight and nutrition plan entries so you can ' 'better see what this site can do. Feel free to edit or ' 'delete them!')) return HttpResponseRedirect(reverse('core:dashboard'))
def test_demo_data_body_weight(self): """ Tests that the helper function that creates demo data filters out existing dates for the weight entries """ self.client.get(reverse('core:dashboard')) self.assertEqual(self.count_temp_users(), 2) user = User.objects.get(pk=4) temp = [] for i in range(1, 5): creation_date = datetime.date.today() - datetime.timedelta(days=i) entry = WeightEntry(user=user, weight=80 + 0.5 * i + random.randint(1, 3), date=creation_date) temp.append(entry) WeightEntry.objects.bulk_create(temp) create_demo_entries(user) # Body weight self.assertEqual(WeightEntry.objects.filter(user=user).count(), 19)
def test_demo_data_body_weight(self): ''' Tests that the helper function that creates demo data filters out existing dates for the weight entries ''' self.client.get(reverse('core:dashboard')) self.assertEqual(self.count_temp_users(), 2) user = User.objects.get(pk=4) temp = [] for i in range(1, 5): creation_date = datetime.date.today() - datetime.timedelta(days=i) entry = WeightEntry(user=user, weight=80 + 0.5 * i + random.randint(1, 3), date=creation_date) temp.append(entry) WeightEntry.objects.bulk_create(temp) create_demo_entries(user) # Body weight self.assertEqual(WeightEntry.objects.filter(user=user).count(), 19)