예제 #1
0
class TrainingTest(TestCase):
    def setUp(self):
        self.simple_user = SimpleUserBuilder().build()
        self.simple_user.save()
        self.exercise_video = ExerciseVideoBuilder().build()
        self.exercise_video.save()
        self.exercise_image = ExerciseImageBuilder().build()
        self.exercise_image.save()
        TrainingBuilder(self.simple_user, self.exercise_image,
                        self.exercise_video).build().save()

    def test_training_name_can_not_be_more_than_255_characters(self):
        incorrect_length = 256
        training = TrainingBuilder(
            self.simple_user,
            self.exercise_image,
            self.exercise_video,
            # incorrect field
            name='x' * incorrect_length).build()
        self.assertRaises(ValidationError, training.full_clean)

    def test_training_has_relation_with_user(self):
        self.assertEqual(
            Training.objects.filter(user__pk=self.simple_user.pk).count(), 1)

    def test_training_has_relation_with_exercise_image(self):
        self.assertEqual(
            Training.objects.filter(
                image_gallery__pk=self.exercise_image.pk).count(), 1)

    def test_training_has_relation_with_exercise_video(self):
        self.assertEqual(
            Training.objects.filter(
                video_gallery__pk=self.exercise_video.pk).count(), 1)
    def setUp(self):
        self.valid_serializer_data = {
            'id':
            '555',
            'name':
            'training name',
            'date':
            timezone.now(),
            'user':
            UserSerializer(instance=SimpleUserBuilder(
                username="******", profile_img=None).build()).data
        }

        simple_user = SimpleUserBuilder().build()
        simple_user.save()
        exercise_video = ExerciseVideoBuilder().build()
        exercise_video.save()
        exercise_image = ExerciseImageBuilder().build()
        exercise_image.save()
        self.training = TrainingBuilder(simple_user,
                                        exercise_image,
                                        exercise_video,
                                        date=timezone.now()).build()
        self.serializer = TrainingSerializer(instance=self.training)
        self.deserializer = TrainingSerializer(data=self.valid_serializer_data)
 def setUp(self):
     self.simple_user = SimpleUserBuilder().build()
     self.simple_user.save()
     self.exercise_video = ExerciseVideoBuilder().build()
     self.exercise_video.save()
     self.exercise_image = ExerciseImageBuilder().build()
     self.exercise_image.save()
예제 #4
0
 def setUpTestData(cls):
     simple_user = SimpleUserBuilder().build()
     simple_user.save()
     exercise_video = ExerciseVideoBuilder().build()
     exercise_video.save()
     exercise_image = ExerciseImageBuilder().build()
     exercise_image.save()
     cls.training = TrainingBuilder(simple_user, exercise_image,
                                    exercise_video).build()
    def setUp(self):
        self.valid_serializer_data = {
            'id': '2',
            'name': 'exercise',
            'description': 'exercise description'
        }

        simple_user = SimpleUserBuilder().build()
        simple_user.save()
        exercise_video = ExerciseVideoBuilder().build()
        exercise_video.save()
        exercise_image = ExerciseImageBuilder().build()
        exercise_image.save()
        training = TrainingBuilder(simple_user, exercise_image,
                                   exercise_video).build()

        self.exercise = ExerciseBuilder(training).build()
        self.serializer = ExerciseSerializer(instance=self.exercise)
        self.deserializer = ExerciseSerializer(data=self.valid_serializer_data)
    def setUp(self):
        self.valid_serializer_data = {
            'id': '555',
            'weight': '105',
            'repetitions': '3',
            'duration': '1',
            'additional': 'additional text',
            'user': UserSerializer(
                instance=SimpleUserBuilder(username="******", profile_img=None).build()).data
        }

        simple_user = SimpleUserBuilder().build()
        simple_user.save()
        exercise_video = ExerciseVideoBuilder().build()
        exercise_video.save()
        exercise_image = ExerciseImageBuilder().build()
        exercise_image.save()
        training = TrainingBuilder(simple_user, exercise_image, exercise_video).build()
        exercise = ExerciseBuilder(training).build()
        exercise.save()

        self.workout_set = WorkoutSetBuilder(exercise).build()
        self.serializer = WorkoutSetSerializer(instance=self.workout_set)
        self.deserializer = WorkoutSetSerializer(data=self.valid_serializer_data)
 def test_exercise_video_name_can_not_be_more_than_40_characters(self):
     incorrect_length = 41
     exercise_video = ExerciseVideoBuilder(
         # incorrect field
         name='x' * incorrect_length).build()
     self.assertRaises(ValidationError, exercise_video.full_clean)
class TrainingViewSetTest(TestCase):
    fixtures = [
        'test/trainings.json', 'workout_portal/fixtures/test/users.json'
    ]

    def setUp(self):
        self.simple_user = SimpleUserBuilder().build()
        self.simple_user.save()
        self.exercise_video = ExerciseVideoBuilder().build()
        self.exercise_video.save()
        self.exercise_image = ExerciseImageBuilder().build()
        self.exercise_image.save()

    def test_should_successful_getting_list_of_trainings(self):
        request = APIRequestFactory().get(TRAININGS_URL)
        training_view_set = TrainingViewSet.as_view(ViewSetsActions.GET_LIST)
        response = training_view_set(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_should_list_should_contains_all_trainings(self):
        request = APIRequestFactory().get(TRAININGS_URL)
        training_view_set = TrainingViewSet.as_view(ViewSetsActions.GET_LIST)
        response = training_view_set(request)
        self.assertEqual(len(Training.objects.all()), response.data['count'])

    def test_should_successful_getting_training_by_id(self):
        request = APIRequestFactory().get(TRAININGS_URL)
        training_view_set = TrainingViewSet.as_view(ViewSetsActions.RETRIEVE)
        response = training_view_set(request, pk=1)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_should_unsuccessful_creating_training(self):
        request_params = {
            'name': 'test training',
            'date': '2019-01-16T07:55:21.526Z',
            'user': {
                "password": "******",
                "last_login": "",
                "is_superuser": 1,
                "username": "******",
                "first_name": "",
                "last_name": "",
                "email": "*****@*****.**",
                "is_staff": 1,
                "is_active": 1,
                "date_joined": "2019-01-31 18:19:44.799979",
                "telephone": "213",
                "profile_img": '',
                "profile_url": "asd"
            }
        }
        request = APIRequestFactory().post(TRAININGS_URL,
                                           request_params,
                                           format='json')
        training_view_set = TrainingViewSet.as_view(ViewSetsActions.CREATE)
        response = training_view_set(request)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertIsNotNone(Training.objects.filter(name='test training'))

    def test_should_successful_partial_update_Training(self):
        created_training = TrainingBuilder(
            self.simple_user,
            self.exercise_image,
            self.exercise_video,
            name='not partial updated Training name yet').build()
        request_params = {'name': 'partial updated Training name'}
        request = APIRequestFactory().patch(TRAININGS_URL, request_params)
        training_view_set = TrainingViewSet.as_view(
            ViewSetsActions.PARTIAL_UPDATE)
        response = training_view_set(request, pk=created_training.id)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertIsNotNone(
            Training.objects.filter(name='partial updated Training name'))

    def test_should_successful_deleting_training(self):
        created_training = TrainingBuilder(
            self.simple_user,
            self.exercise_image,
            self.exercise_video,
            name='not deleted Training yet').build()
        request = APIRequestFactory().delete(TRAININGS_URL)
        training_view_set = TrainingViewSet.as_view(ViewSetsActions.DELETE)
        response = training_view_set(request, pk=created_training.pk)
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        self.assertEqual(
            len(Training.objects.filter(name='not deleted Training yet')), 0)