Example #1
0
 def get(self, uuid=None):
     if not uuid:
         films = FilmService.fetch_all_films(db.session).all()
         return self.film_schema.dump(films, many=True), 200
     film = FilmService.fetch_film_by_uuid(db.session, uuid)
     if not film:
         return '', 404
     return self.film_schema.dump(film), 200
Example #2
0
 def get(self, uuid=None):
     if not uuid:
         films = FilmService.fetch_all_films(db.session).options(
             selectinload(Film.actors)).all()
         return self.film_schema.dump(films, many=True), 200
     film = FilmService.fetch_film_by_uuid(db.session, uuid)
     if not film:
         return "", 404
     return self.film_schema.dump(film), 200
Example #3
0
 def delete(self, uuid):
     film = FilmService.fetch_film_by_uuid(db.session, uuid)
     if not film:
         return "", 404
     db.session.delete(film)
     db.session.commit()
     return '', 204
Example #4
0
    def test_get_film_by_uuid_with_db(self):
        client = app.test_client()
        uuid = FilmService.fetch_all_films(db.session).first().uuid

        response = client.get(f'/films/{uuid}')

        assert response.status_code == http.HTTPStatus.OK
Example #5
0
 def delete(self, uuid):
     film = FilmService.fetch_film_by_uuid(db.session, uuid)
     if not film:
         return '', 404
     db.session.delete(film)
     db.session.commit()
     return {'message': 'Deleted successfully'}, 204
Example #6
0
 def put(self, uuid):
     film = FilmService.fetch_film_by_uuid(db.session, uuid)
     if not film:
         return "", 404
     try:
         film = self.film_schema.load(request.json,
                                      instance=film,
                                      session=db.session)
     except ValidationError as e:
         return {'message': str(e)}, 400
     db.session.add(film)
     db.session.commit()
     return self.film_schema.dump(film), 200
Example #7
0
 def put(self, uuid):
     film = FilmService.fetch_film_by_uuid(db.session, uuid)
     if not film:
         return '', 404
     try:
         film = self.film_shema.load(request.json,
                                     instance=film,
                                     session=db.session)
     except ValidationError as e:
         return {'Message': f'error: {e}'}, 400
     db.session.add(film)
     db.session.commit()
     return jsonify(self.film_shema.dump(film)), 200
Example #8
0
 def patch(self, uuid):
     film = FilmService.fetch_film_by_uuid(db.session, uuid)
     print(film)
     if not film:
         return '', 404
     try:
         print(request.json)
         film = self.schema.load(request.json,
                                 instance=film,
                                 session=db.session,
                                 partial=True)
     except ValidationError as err:
         return {'message': str(err)}, 400
     db.session.add(film)
     db.session.commit()
     return self.schema.dump(film), 200
Example #9
0
 def put(self, uuid):
     film = FilmService.fetch_film_by_uuid(db.session, uuid)
     if not film:
         return {'message': 'Not Found'}, 404
     try:
         film = self.film_schema.load(request.json,
                                      instance=film,
                                      session=db.session)
     except ValidationError as e:
         return {'message': str(e)}, 400
     try:
         db.session.add(film)
         db.session.commit()
     except IntegrityError:
         db.session.rollback()
         message = 'Such film exists'
         return {'message': message}, 409
     return self.film_schema.dump(film), 200
Example #10
0
 def populate_db_with_films(films):
     return FilmService.bulk_create_films(db.session, films)