Beispiel #1
0
    def __init__(self, *args, **kwargs):  # noqa
        super().__init__(*args, **kwargs)

        if MyTestCase.app is None:
            MyTestCase.app = create_app()
        MyTestCase.client = self.app.test_client()
        if MyTestCase.db is None:
            setup_db(self.app, self.database_path)
            MyTestCase.db = db

        self.db.drop_all()
        self.db.create_all()

        self.sample_actor = dict(
            name='My actor',
            age=4,
            gender=0,
        )
        self.bad_actor = dict(
            name='',  # oops, empty name
            age=42,
            gender=0,
        )
        self.sample_movie = dict(
            title='My movie',
            release_date=date(2021, 3, 30).isoformat(),
        )
        self.bad_movie = dict(
            title='',
            release_date=date(2021, 3, 30).isoformat(),
        )
        m = Movie(**self.sample_movie)
        m.id = 499
        m.insert()
Beispiel #2
0
def post_movie():
    post_data = request.get_json()
    try:
        movie = Movie(post_data['title'],
                      date.fromisoformat(post_data['release_date']))
        movie.actors = Actor.query.filter(
            Actor.id.in_(post_data.get('actors', []))).all()
        movie.insert()
        return jsonify({'success': True, 'movie_id': movie.id})
    except Exception:
        db.session.rollback()
        print(sys.exc_info())
        abort(422, 'Unprocessable request to add new Movie')