Ejemplo n.º 1
0
    def test_find_all_by_user_id(self):
        """Test if all the user's trainings are found"""
        self._create_sample_training(self.user, "test training1")
        self._create_sample_training(self.user, "test training2")
        found_trainings = TrainingModel.find_all_by_user_id(
            user_id=self.user.id
        )

        self.assertEqual(len(found_trainings), 2)
Ejemplo n.º 2
0
    def test_find_all_by_user_id_current_user_only(self):
        """Test if only trainings which belong to the given user are returned"""
        training1 = self._create_sample_training(self.user, "test training1")
        training2 = self._create_sample_training(self.user, "test training2")
        user2 = self._create_sample_user("user2")
        training3 = self._create_sample_training(user2, "test training3")
        found_trainings = TrainingModel.find_all_by_user_id(self.user.id)

        self.assertIn(training1, found_trainings)
        self.assertIn(training2, found_trainings)
        self.assertNotIn(training3, found_trainings)
Ejemplo n.º 3
0
 def get(cls):
     """Get method"""
     current_user_id = get_jwt_identity()
     return (
         {
             "trainings":
             training_list_schema.dump(
                 TrainingModel.find_all_by_user_id(current_user_id))
         },
         200,
     )
Ejemplo n.º 4
0
    def test_get_trainings_data(self):
        """Test if the correct data is returned"""
        response = self.client.get(
            path="trainings/",
            headers={
                "Content-Type": "application/json",
                "Authorization": f"Bearer {self.access_token}",
            },
        )
        trainings_data = training_list_schema.dump(
            TrainingModel.find_all_by_user_id(self.user.id))

        expected_trainings_num = 2

        self.assertEqual(len(response.json["trainings"]),
                         expected_trainings_num)
        self.assertEqual(response.json["trainings"], trainings_data)
Ejemplo n.º 5
0
    def test_find_all_by_user_id_no_trainings(self):
        """Test if an empty list is returned if the user has no trainings"""
        found_trainings = TrainingModel.find_all_by_user_id(self.user.id)

        self.assertEqual(found_trainings, [])