Пример #1
0
    def test_training_is_deleted_from_db(self):
        """Test if the training
        has been successfully deleted from the database"""
        training = self._create_sample_training(self.user)
        training.delete_from_db()
        found_training = TrainingModel.find_by_name("test training")

        self.assertIsNone(found_training)
Пример #2
0
    def test_find_by_name(self):
        """Test if the training is found"""
        training = self._create_sample_training(
            user=self.user, name="test training"
        )
        found_training = TrainingModel.find_by_name("test training")

        self.assertEqual(found_training, training)
Пример #3
0
    def test_training_is_saved_in_db(self):
        """Test if the training has been successfully saved in the database"""
        training = TrainingModel(
            name="test training",
            user_id=self.user.id,
            distance=10,
            time_in_seconds=3600,
        )
        training.save_to_db()
        found_training = TrainingModel.find_by_name("test training")

        self.assertIsNotNone(found_training)
Пример #4
0
    def test_post_training_data_in_db(self):
        """Test if the correct data is saved in the database"""
        data = {
            "name": "test3",
            "distance": 10,
            "time_in_seconds": 3600,
        }
        self.client.post(
            path="trainings/",
            data=json.dumps(data),
            headers={
                "Content-Type": "application/json",
                "Authorization": f"Bearer {self.access_token}",
            },
        )

        training = TrainingModel.find_by_name(data["name"])

        self.assertEqual(training.name, data["name"])
        self.assertEqual(training.distance, data["distance"])
        self.assertEqual(training.time_in_seconds, data["time_in_seconds"])
Пример #5
0
    def test_find_by_name_no_training(self):
        """Test if None is returned
        if the training with the given name doesn't exist"""
        found_training = TrainingModel.find_by_name("test training")

        self.assertIsNone(found_training)