def find_or_create_by_name(self, name, conn, cursor): category = self.find_by_name(name, cursor) if not category: new_category = models.Category() new_category.name = name db.save(new_category, conn, cursor) category = self.find_by_name(name, cursor) return category
def find_or_create_complaint_type(self, name, conn, cursor): complaint = self.find_by_complaint_type(name, cursor) if not complaint: new_complaint = models.Complaint() new_complaint.name = name db.save(new_complaint, conn, cursor) complaint = self.find_by_complaint_type(name, cursor) return complaint
def test_find_or_create_by_finds_when_existing_category(conn): cursor = conn.cursor() cb = adapters.CategoryBuilder() category = db.save(models.Category(name='Taco Places'), conn, cursor) new_categories = cb.find_or_create_categories(['Taco Places'], conn, cursor) assert category.id == new_categories[0].id
def test_inserted_data(test_conn): test_cursor = test_conn.cursor() builder = adapters.HotelBuilder() builder_details = builder.select_attributes(json) hotel = db.save(builder_details, test_conn, test_cursor) hotel_data = db.find(models.Hotel, hotel.id, test_cursor) assert hotel_data.name == 'BULGARI HOTELS RESORTS MILANO'
def build_records(conn, cursor): famiglia = Venue(foursquare_id='1234', name='La Famiglia', price=1, rating=2, likes=3, menu_url='lafamig.com') mogador = Venue(foursquare_id='5678', name='Cafe Mogador', price=3, rating=4, likes=15, menu_url='cafemogador.com') save(famiglia, conn, cursor) save(mogador, conn, cursor) pizza = Category(name='Pizza') italian = Category(name='Italian') save(pizza, conn, cursor) save(italian, conn, cursor)
def build_records(test_conn, test_cursor): new_york = save(State(name='New York'), test_conn, test_cursor) pennsylvania = save(State(name='Pennsylvania'), test_conn, test_cursor) brooklyn = save(City(name='Brooklyn', state_id=new_york.id), test_conn, test_cursor) manhattan = save(City(name='Manhattan', state_id=new_york.id), test_conn, test_cursor) philadelphia = save(City(name='Philadelphia', state_id=pennsylvania.id), test_conn, test_cursor) south_philly_zip = save(Zipcode(code=19019, city_id=philadelphia.id), test_conn, test_cursor) chelsea_zip = save(Zipcode(code=10001, city_id=manhattan.id), test_conn, test_cursor) dumbo_zip = save(Zipcode(code=11210, city_id=brooklyn.id), test_conn, test_cursor) venue = save( Venue(name='Los Tacos Al Pastor', price=1, foursquare_id='1234'), test_conn, test_cursor) grimaldis = save( Venue(name='Grimaldis', price=2, foursquare_id='4bf58dd8d48988d151941735'), test_conn, test_cursor) pizza = save(Category(name='Pizza'), test_conn, test_cursor) tourist_spot = save(Category(name='Tourist Spot'), test_conn, test_cursor) save(VenueCategory(venue_id=grimaldis.id, category_id=pizza.id), test_conn, test_cursor) save(VenueCategory(venue_id=grimaldis.id, category_id=tourist_spot.id), test_conn, test_cursor) grimaldi_location = save( Location(longitude=40.7024, latitude=-73.9875, address='1 Front Street', zipcode_id=dumbo_zip.id, venue_id=grimaldis.id), test_conn, test_cursor) taco_location = save( Location(longitude=40.7024, latitude=-73.9875, address='141 Front Street', zipcode_id=dumbo_zip.id, venue_id=venue.id), test_conn, test_cursor) zahav = save( Venue(foursquare_id='9912', name='Zahavs', price=4, rating=5, likes=100, menu_url='zahavs.com'), test_conn, test_cursor) save( Location(longitude=40.7024, latitude=-73.9875, address='237 James Street', zipcode_id=south_philly_zip.id, venue_id=zahav.id), test_conn, test_cursor)
def build_records_test_flask(conn, cursor): flask_r1 = { "id": 1, "game_id": 1, "metacritic": 84, "TS_rating": 4.43, "rank_type": "top free", "ranking": 1, "date_created": "2021-01-01" } flask_g1 = { "id": 1, "name": "Among Us", "platform": "android", "publisher": "Innersloth LLC", "release_date": "2018-07-25", "genre": "action", "game_engine": "Unity" } flask_e1 = { "id": 1, "game_id": 1, "price": 0.0, "inapp": True, "shows_ads": False, "revenue": 2000000, "downloads": 29000000 } flask_r2 = { "id": 2, "game_id": 2, "metacritic": 83, "TS_rating": 4.53, "rank_type": "top paid", "ranking": 1, "date_created": "2021-01-01" } flask_g2 = { "id": 2, "name": "Minecraft", "platform": "android", "publisher": "Mojang", "release_date": "2009-05-10", "genre": "arcade", "game_engine": "Lightweight Java Game Library" } flask_e2 = { "id": 2, "game_id": 2, "price": 7.49, "inapp": True, "shows_ads": False, "revenue": 4000000, "downloads": 400000 } flask_r3 = { "id": 3, "game_id": 3, "metacritic": None, "TS_rating": 4.42, "rank_type": "top grossing", "ranking": 1, "date_created": "2021-01-01" } flask_g3 = { "id": 3, "name": "Roblox", "platform": "android", "publisher": "Roblox Corporation", "release_date": None, "genre": "adventure", "game_engine": None } flask_e3 = { "id": 3, "game_id": 3, "price": 0.0, "inapp": True, "shows_ads": False, "revenue": 37000000, "downloads": 9000000 } flask_r4 = { "id": 4, "game_id": 4, "metacritic": None, "TS_rating": 4.48, "rank_type": "top free", "ranking": 1, "date_created": "2021-01-01" } flask_g4 = { "id": 4, "name": "Among Us!", "platform": "iOS", "publisher": "InnerSloth LLC", "release_date": "2018-07-25", "genre": "action", "game_engine": "Unity" } flask_e4 = { "id": 4, "game_id": 4, "price": 0.0, "inapp": True, "shows_ads": False, "revenue": 6000000, "downloads": 12000000 } flask_r5 = { "id": 5, "game_id": 5, "metacritic": 83, "TS_rating": 4.49, "rank_type": "top paid", "ranking": 1, "date_created": "2021-01-01" } flask_g5 = { "id": 5, "name": "Minecraft", "platform": "iOS", "publisher": "Mojang", "release_date": "2009-05-10", "genre": "arcade", "game_engine": "Lightweight Java Game Library" } flask_e5 = { "id": 5, "game_id": 5, "price": 6.99, "inapp": True, "shows_ads": True, "revenue": 10000000, "downloads": 300000 } flask_r6 = { "id": 6, "game_id": 6, "metacritic": None, "TS_rating": 4.60, "rank_type": "top grossing", "ranking": 1, "date_created": "2021-01-01" } flask_g6 = { "id": 6, "name": "Roblox", "platform": "iOS", "publisher": "Roblox Corporation", "release_date": None, "genre": "adventure", "game_engine": None } flask_e6 = { "id": 6, "game_id": 6, "price": 0.0, "inapp": True, "shows_ads": True, "revenue": 60000000, "downloads": 4000000 } db.save(models.Game(**flask_g1), conn, cursor) db.save(models.Game(**flask_g2), conn, cursor) db.save(models.Game(**flask_g3), conn, cursor) db.save(models.Game(**flask_g4), conn, cursor) db.save(models.Game(**flask_g5), conn, cursor) db.save(models.Game(**flask_g6), conn, cursor) db.save(models.Rating(**flask_r1), conn, cursor) db.save(models.Rating(**flask_r2), conn, cursor) db.save(models.Rating(**flask_r3), conn, cursor) db.save(models.Rating(**flask_r4), conn, cursor) db.save(models.Rating(**flask_r5), conn, cursor) db.save(models.Rating(**flask_r6), conn, cursor) db.save(models.Earnings(**flask_e1), conn, cursor) db.save(models.Earnings(**flask_e2), conn, cursor) db.save(models.Earnings(**flask_e3), conn, cursor) db.save(models.Earnings(**flask_e4), conn, cursor) db.save(models.Earnings(**flask_e5), conn, cursor) db.save(models.Earnings(**flask_e6), conn, cursor)