Example #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'}
Example #2
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
Example #3
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
Example #4
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