Ejemplo n.º 1
0
    def test_read_from_closed_db(self, app):
        with app.app_context():
            db = get_db()
            assert db is get_db()

        try:
            s_all()
        except Exception as e:
            assert 'Working outside of application context' in str(e)
Ejemplo n.º 2
0
    def games_all():
        conn = db.get_db()
        cursor = conn.cursor()

        games = db.find_all(models.Game, cursor)
        game_dicts = [game.__dict__ for game in games]
        return json.dumps(game_dicts, default = str)
Ejemplo n.º 3
0
    def incidents():
        conn = db.get_db()
        cursor = conn.cursor()

        incidents = db.find_all(models.Incident, cursor)
        incident_dicts = [incident.__dict__ for incident in incidents]
        return json.dumps(incident_dicts, default=str)
Ejemplo n.º 4
0
    def cheapest_by_name(name):
        conn = db.get_db()
        cursor = conn.cursor()

        hotel_rates_min_avg = models.Hotel.min_avg_rate(cursor)
        rate_min_avg_dict = [
            dict(
                zip([
                    'hotel', 'currency', 'cheapest', 'average',
                    'percent_discount'
                ], hotel)) for hotel in hotel_rates_min_avg
        ]
        name_cleaned = name.title()
        hotels = []
        for hotel in rate_min_avg_dict:
            if name_cleaned in hotel['hotel']:
                hotels.append(hotel)
        selected_name, selected_rate = hotels[0]["hotel"], hotels[0][
            "cheapest"]
        cheapest_dates = models.Hotel.cheapest_dates(cursor, selected_name,
                                                     selected_rate)
        cheapest_dates_dict = [
            dict(
                zip(['hotel', 'check_in', 'currency', 'rate', 'created_at'],
                    date)) for date in cheapest_dates
        ]
        return json.dumps(cheapest_dates_dict, default=str)
Ejemplo n.º 5
0
    def venues():
        conn = db.get_db()
        cursor = conn.cursor()

        venues = db.find_all(models.Venue, cursor)
        venue_dicts = [venue.__dict__ for venue in venues]
        return json.dumps(venue_dicts, default=str)
Ejemplo n.º 6
0
 def games_search_with_earnings():
     conn = db.get_db()
     cursor = conn.cursor()
     params = dict(request.args)
     earnings = models.Earnings.search(params, cursor)
     earnings_dicts = [earning.to_json(cursor) for earning in earnings]
     return json.dumps(earnings_dicts, default = str)
Ejemplo n.º 7
0
    def search_incidents():
        conn = db.get_db()
        cursor = conn.cursor()

        params = dict(request.args)
        incidents = models.Incident.search(params, cursor)
        incident_dicts = [incident.to_json(cursor) for incident in incidents]
        return json.dumps(incident_dicts, default=str)
Ejemplo n.º 8
0
    def search_venues():
        conn = db.get_db()
        cursor = conn.cursor()

        params = dict(request.args)
        venues = models.Venue.search(params, cursor)
        venue_dicts = [venue.to_json(cursor) for venue in venues]
        return json.dumps(venue_dicts, default=str)
Ejemplo n.º 9
0
    def hotels():
        conn = db.get_db()
        cursor = conn.cursor()

        hotels_detail = models.Hotel.hotel_locations(cursor)
        details_dict = [
            dict(zip(['id', 'name', 'lon', 'lat'], hotel_detail))
            for hotel_detail in hotels_detail
        ]
        return json.dumps(details_dict, default=str)
Ejemplo n.º 10
0
    def agencies():
        conn = db.get_db()
        cursor = conn.cursor()

        agency_names = models.Complaint.get_agency_names(
        )  #list of strings ['NYPD', 'FDNY', 'DSNY']
        agency_dicts = [
            models.Complaint.complaint_total_for_agency(agency_name)
            for agency_name in agency_names
        ]
        return json.dumps(agency_dicts, default=str)
Ejemplo n.º 11
0
 def cheapest():
     conn = db.get_db()
     cursor = conn.cursor()
     hotel_rates_min_avg = models.Hotel.min_avg_rate(cursor)
     rate_min_avg_dict = [
         dict(
             zip([
                 'hotel', 'currency', 'cheapest', 'average',
                 'percent_discount'
             ], hotel)) for hotel in hotel_rates_min_avg
     ]
     return json.dumps(rate_min_avg_dict, default=str)
Ejemplo n.º 12
0
    def select_hotel_by_name(name):
        conn = db.get_db()
        cursor = conn.cursor()
        cleaned_name = name.capitalize()

        selected_hotel_rates = models.Hotel.selected_hotel_rates(
            cursor, cleaned_name)
        hotel_rates_dict = [
            dict(
                zip(['hotel', 'currency', 'check_in', 'rate', 'created_at'],
                    hotel)) for hotel in selected_hotel_rates
        ]
        return json.dumps(hotel_rates_dict, default=str)
Ejemplo n.º 13
0
    def test_reading(self, app):
        with app.app_context():
            db = get_db()
            db.execute(
                "INSERT INTO `chats` (`channel`, `username`, `message`, `created_at`, `created_at_second`) VALUES(?, ?, ?, ?, ?)",
                ('shroud', 'whiplk', 'Test message, shroud rules!',
                 '201811060420', '20181106042020'))

            response = s_all()

            obj = response.pop()
            assert obj.get('channel') == 'shroud'
            assert obj.get('username') == 'whiplk'
            assert obj.get('message') == 'Test message, shroud rules!'
            assert obj.get('created_at') == '20181106042020'
Ejemplo n.º 14
0
    def search_offers(id):
        conn = db.get_db()
        cursor = conn.cursor()

        hotel = db.find(models.Hotel, id, cursor)
        return json.dumps(hotel.to_json(cursor), default=str)
Ejemplo n.º 15
0
 def games_with_earnings_ratings():
     conn = db.get_db()
     cursor = conn.cursor()
     ratings = db.find_all(models.Rating, cursor)
     ratings_dicts = [rating.to_json(cursor) for rating in ratings]
     return json.dumps(ratings_dicts, default = str)
Ejemplo n.º 16
0
 def game_with_earnings_ratings(id):
     conn = db.get_db()
     cursor = conn.cursor()
     ratings = db.find_by_game_id(models.Rating, id, cursor)
     ratings_dict = [rating.to_json(cursor) for rating in ratings]
     return json.dumps(ratings_dict, default = str)
Ejemplo n.º 17
0
 def game(id):
     conn = db.get_db()
     cursor = conn.cursor()
     game = db.find(models.Game, id, cursor)
     return json.dumps(game.__dict__, default = str)
Ejemplo n.º 18
0
    def venue(id):
        conn = db.get_db()
        cursor = conn.cursor()
        venue = db.find(models.Venue, id, cursor)

        return json.dumps(venue.__dict__, default=str)
Ejemplo n.º 19
0
    def incident(id):
        conn = db.get_db()

        cursor = conn.cursor()
        incident = db.find(models.Incident, id, cursor)
        return json.dumps(incident.__dict__, default=str)