def test_unicode(self):
        '''
        Test the unicode representation
        '''

        session = WorkoutSession()
        session.workout = Workout.objects.get(pk=1)
        session.date = datetime.date.today()
        self.assertEqual('{0}'.format(session),
                         u'{0} - {1}'.format(Workout.objects.get(pk=1), datetime.date.today()))
Esempio n. 2
0
    def test_get_workout_session(self):
        '''
        Test the get_workout_session method
        '''

        user1 = User.objects.get(pk=1)
        user2 = User.objects.get(pk=2)
        workout1 = Workout.objects.get(pk=2)
        workout2 = Workout.objects.get(pk=2)

        WorkoutLog.objects.all().delete()
        l = WorkoutLog()
        l.user = user1
        l.date = datetime.date(2014, 1, 5)
        l.exercise = Exercise.objects.get(pk=1)
        l.workout = workout1
        l.weight = 10
        l.reps = 10
        l.save()

        session1 = WorkoutSession()
        session1.user = user1
        session1.workout = workout1
        session1.notes = 'Something here'
        session1.impression = '3'
        session1.date = datetime.date(2014, 1, 5)
        session1.save()

        session2 = WorkoutSession()
        session2.user = user1
        session2.workout = workout1
        session2.notes = 'Something else here'
        session2.impression = '1'
        session2.date = datetime.date(2014, 1, 1)
        session2.save()

        session3 = WorkoutSession()
        session3.user = user2
        session3.workout = workout2
        session3.notes = 'The notes here'
        session3.impression = '2'
        session3.date = datetime.date(2014, 1, 5)
        session3.save()

        self.assertEqual(l.get_workout_session(), session1)
Esempio n. 3
0
        for date in WorkoutLog.objects.filter(user=user).dates('date', 'day'):

            # Only process for dates for which there isn't already a session
            if not WorkoutSession.objects.filter(user=user,
                                                 date=date).exists():

                workout = WorkoutLog.objects.filter(user=user,
                                                    date=date).first().workout
                start = datetime.time(hour=random.randint(8, 20),
                                      minute=random.randint(0, 59))
                end = datetime.datetime.combine(datetime.date.today(), start)  \
                    + datetime.timedelta(minutes=random.randint(40, 120))
                end = datetime.time(hour=end.hour, minute=end.minute)

                session = WorkoutSession()
                session.date = date
                session.user = user
                session.time_start = start
                session.time_end = end
                session.workout = workout

                if args.impression_sessions == 'good':
                    session.impression = WorkoutSession.IMPRESSION_GOOD
                elif args.impression_sessions == 'neutral':
                    session.impression = WorkoutSession.IMPRESSION_NEUTRAL
                elif args.impression_sessions == 'bad':
                    session.impression = WorkoutSession.IMPRESSION_BAD
                else:
                    session.impression = random.choice([
                        WorkoutSession.IMPRESSION_GOOD,
Esempio n. 4
0
    def test_workout_session(self):
        """
        Tests that the correct urls and forms for workout session is passed
        """
        WorkoutSession.objects.all().delete()
        self.user_login('test')

        self.client.get(reverse('manager:workout:timer', kwargs={'day_pk': 5}))

        session = WorkoutSession()
        session.user = User.objects.get(username='******')
        session.workout = Workout.objects.get(pk=2)
        session.date = datetime.date.today()
        session.notes = 'Something here'
        session.impression = '2'
        session.time_start = datetime.time(11, 00)
        session.time_end = datetime.time(13, 00)
        session.save()
Esempio n. 5
0
    def test_workout_session(self):
        '''
        Tests that the correct urls and forms for workout session is passed
        '''
        WorkoutSession.objects.all().delete()
        self.user_login('test')

        today = datetime.date.today()
        response = self.client.get(reverse('manager:workout:timer', kwargs={'day_pk': 5}))
        self.assertEqual(response.context['form_action'],
                         reverse('manager:session:add', kwargs={'workout_pk': 3,
                                                                'year': today.year,
                                                                'month': today.month,
                                                                'day': today.day}))

        session = WorkoutSession()
        session.user = User.objects.get(username='******')
        session.workout = Workout.objects.get(pk=2)
        session.date = datetime.date.today()
        session.notes = 'Something here'
        session.impression = '2'
        session.time_start = datetime.time(11, 00)
        session.time_end = datetime.time(13, 00)
        session.save()

        response = self.client.get(reverse('manager:workout:timer', kwargs={'day_pk': 5}))
        self.assertEqual(response.context['form_action'],
                         reverse('manager:session:edit', kwargs={'pk': session.pk}))
    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)
    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)
Esempio n. 8
0
if hasattr(args, 'impression_sessions'):
    print("** Generating workout sessions")

    session_list = []

    for user in User.objects.all():
        print('   - generating for {0}'.format(user.username))

        for date in WorkoutLog.objects.filter(user=user).dates('date', 'day'):

            # Only process for dates for which there isn't already a session
            if not WorkoutSession.objects.filter(user=user, date=date).exists():

                workout = WorkoutLog.objects.filter(user=user, date=date).first().workout

                session = WorkoutSession()
                session.date = date
                session.user = user
                session.workout = workout

                if args.impression_sessions == 'good':
                    session.impression = WorkoutSession.IMPRESSION_GOOD
                elif args.impression_sessions == 'neutral':
                    session.impression = WorkoutSession.IMPRESSION_NEUTRAL
                elif args.impression_sessions == 'bad':
                    session.impression = WorkoutSession.IMPRESSION_BAD
                else:
                    session.impression = random.choice([WorkoutSession.IMPRESSION_GOOD,
                                                        WorkoutSession.IMPRESSION_NEUTRAL,
                                                        WorkoutSession.IMPRESSION_BAD])