Ejemplo n.º 1
0
    def test_delete_actor(self):
        """Tests delete an actor success"""
        actor = Actor(
            name=self.actor_2['name'],
            age=self.actor_2['age'],
            gender=self.actor_2['gender'],
            image_link=self.actor_2['imageLink'],
            phone=self.actor_2['phone'],
            website=self.actor_2['website'],
        )

        actor.insert()

        actor_id = actor.id

        # try to delete the actor
        response = self.client.delete(f'/api/actors/{actor_id}',
                                      headers=self.director_header)
        data = json.loads(response.data)

        # check the status code / message
        self.assertEqual(response.status_code, 200)
        self.assertEqual(data['success'], True)

        # check if the actor id matches the deleted_id field
        self.assertEqual(data['deleted_id'], actor_id)

        # check if the actor has been deleted
        a = Actor.query.filter(Actor.id == actor_id).one_or_none()

        # see if the actor is now None after it has been deleted
        self.assertEqual(a, None)
Ejemplo n.º 2
0
 def test_delete_movies_success(self):
     movie = Actor(title="LALALA", release_data="05022023", genre="malodrama")
     movie.insert()
     res = self.client.delete('/movies/%s' % movie.id)
     data = json.loads(res.data)
     self.assertEqual(res.status_code, 200)
     self.assertTrue(data['success'])
     self.assertEqual(data['movie_id'], movie.id)
Ejemplo n.º 3
0
 def test_delete_actor_success(self):
     actor = Actor(name="Prince", age="52", gender="male")
     actor.insert()
     res = self.client.delete('/actors/%s' % actor.id)
     data = json.loads(res.data)
     self.assertEqual(res.status_code, 200)
     self.assertTrue(data['success'])
     self.assertEqual(data['actor_id'], actor.id)
Ejemplo n.º 4
0
 def test_actors_list_success(self):
     actor = Actor(name="Yara Shahidi", age="20", gender="female")
     actor.insert()
     res = self.client().get('/actors')
     data = json.loads(res.data)
     self.assertEqual(res.status_code, 200)
     self.assertTrue(data['success'])
     actors = Actor.query.all()
     self.assertEqual(len(data['actors']), len(actors))
Ejemplo n.º 5
0
def restart_db_with_test_data():
    db_drop_and_create_all()
    for actor in actors:
        actor_obj = Actor(name=actor["name"],
                          age=actor["age"],
                          gender=actor["gender"])
        actor_obj.insert()

    for movie in movies:
        movie_obj = Movie(title=movie["title"],
                          release_date=movie["release_date"])
        movie_obj.insert()
Ejemplo n.º 6
0
def create_actor(jwt):
    data = request.get_json()
    # checks for presence of content in data
    if not data:
        abort(400)

    # retrieves data from request
    name = data['name']
    age = data['age']
    gender = data['gender']
    # creates a new instance of actor passing the retrieved data
    actor = Actor(name=name, age=age, gender=gender)
    try:
        actor.insert()
    except:
        abort(422)

    return jsonify({'success': True, 'actor': actor.format()})
Ejemplo n.º 7
0
    def test_delete_actor_403(self):
        """Tests delete an actor cannot be created by an assistant"""
        actor = Actor(
            name=self.actor_2['name'],
            age=self.actor_2['age'],
            gender=self.actor_2['gender'],
            image_link=self.actor_2['imageLink'],
            phone=self.actor_2['phone'],
            website=self.actor_2['website'],
        )

        actor.insert()

        actor_id = actor.id

        # try to delete the actor
        response = self.client.delete(f'/api/actors/{actor_id}',
                                      headers=self.assistant_header)
        data = json.loads(response.data)

        # check the status code / message
        self.assertEqual(response.status_code, 403)
        self.assertEqual(data['success'], False)