Пример #1
0
 def test_fetch_series_entries(self, session):
     series_schema = SeriesSchema()
     result = session.query(Series).all()
     series_obj, error = series_schema.dump(result, many=True)
     assert not error
     assert len(series_obj) > 0
     assert not set(series_obj[0].keys()) - \
         {'name', 'date_start', 'date_end', 'id'}
Пример #2
0
 def test_create_series_entry(self, session):
     series_schema = SeriesSchema()
     series_obj, error = series_schema.load(
         dict(name="example series",
              date_start=str(datetime.today()),
              date_end=str(datetime.today() + timedelta(days=30))))
     assert not error
     session.add(series_obj)
     session.commit()
     assert series_obj.id > 0
Пример #3
0
 def all(self, session):
     result = session.query(Tournaments, Series).join(Series).all()
     series_schema = SeriesSchema()
     response = []
     for t_row, s_row in result:
         t_obj, t_err = self.dump(t_row)
         s_obj, s_err = series_schema.dump(s_row)
         if not t_err and not s_err:
             t_obj['series'] = s_obj
             response.append(t_obj)
         else:
             logger.error("Tournament Error: {}, Series Error: {}".format(
                 t_err, s_err))
     return response
Пример #4
0
    def filter_by_date_range(self, session, date_start, date_end):
        result = session.query(Tournaments, Series).join(Series)\
            .filter(Tournaments.date_start >= date_start)\
            .filter(Tournaments.date_end <= date_end)\
            .all()

        series_schema = SeriesSchema()
        response = []
        for t_row, s_row in result:
            t_obj, t_err = self.dump(t_row)
            s_obj, s_err = series_schema.dump(s_row)
            if not t_err and not s_err:
                t_obj['series'] = s_obj
                response.append(t_obj)
            else:
                logger.error("Tournament Error: {}, Series Error: {}".format(
                    t_err, s_err))
        return response
Пример #5
0
def create_series():
    series_schema = SeriesSchema()
    if request.method == "POST":
        form_data = request.form
        data_validation(form_data, ['name', 'date_start', 'date_end'])
        series_obj, error = series_schema.load(
            dict(name=form_data.get("name"),
                 date_start=form_data.get("date_start"),
                 date_end=form_data.get("date_end")))
        try:
            session.add(series_obj)
            session.commit()
        except Exception as exc:
            session.rollback()
            logger.error("Failed to process request {}".format(str(exc)))
            raise HTTPError(500, {"error": str(exc)})
        return redirect(url_for("create_series"))
        flash("Series successfully created")
    return render_template('create_series.html')
Пример #6
0
 def test_create_tournaments_entry(self, session):
     tournaments_schema = TournamentsSchema()
     series_schema = SeriesSchema()
     result = session.query(Series).first()
     series_obj, error = series_schema.dump(result)
     _id = series_obj.get('id')
     assert _id is not None
     assert not error
     tournaments_obj, error = tournaments_schema.load(dict(
         series_id=_id,
         name='Test Tournament',
         city='Bangalore',
         country='India',
         date_start=str(datetime.today()),
         date_end=str(datetime.today() + timedelta(days=30))
     ))
     assert not error
     session.add(tournaments_obj)
     session.commit()
     assert tournaments_obj.id > 0
Пример #7
0
def create_tournament():
    tournament_schema = TournamentsSchema()
    series_schema = SeriesSchema()
    series_names = series_schema.all(session)
    if request.method == "POST":
        form_data = request.form
        data_validation(
            form_data,
            ['series_id', 'name', 'date_start', 'date_end', 'city', 'country'])
        tournaments_obj, error = tournament_schema.load(
            dict(series_id=form_data.get("series_id"),
                 name=form_data.get("name"),
                 city=form_data.get("city"),
                 country=form_data.get("country"),
                 date_start=form_data.get("date_start"),
                 date_end=form_data.get("date_end")))
        try:
            session.add(tournaments_obj)
            session.commit()
        except Exception as exc:
            session.rollback()
            raise HTTPError(500, {"error": str(exc)})
        return redirect(url_for("create_tournament"))
    return render_template('create_tournament.html', series_names=series_names)