def setUp(self): engine.save(AppDetails(100000001, 'us', { 'price': 1.50, 'currency': 'USD' }), overwrite=True) engine.save(AppDetails(100000002, 'us', { 'price': 5.00, 'currency': 'USD' }), overwrite=True) engine.save(AppDetails(100000003, 'us', { 'price': 3.50, 'currency': 'USD' }), overwrite=True) engine.save(AppDetails(100000004, 'us', { 'price': 1.25, 'currency': 'USD' }), overwrite=True) engine.save(AppDetails(100000005, 'us', { 'price': 0, 'currency': 'USD' }), overwrite=True)
def get_search_data(search_str): data = [] db_data = AppDetails.objects.filter(search_str__icontains=search_str) if db_data: # if data not in db for obj in db_data: data.append(obj.ayopop_model_to_dict()) else: # if data not in db data_list = get_play_store_data(search_str) data_list = data_list[0:12] for obj in data_list: try: app = AppDetails.objects.get(app_url=obj.get("app_url")) app.search_str = app.search_str + ", " + search_str app.save() except Exception as e: app = AppDetails() app.app_url = obj.get("app_url") app.app_title = obj.get("app_title") app.app_sub_title = obj.get("app_sub_title") app.app_desc = obj.get("app_desc") app.search_str = search_str app.save() data.append(obj.ayopop_model_to_dict()) return data
def test_free_or_cheap(self): print("\nFind all apps that are free or a price from $1.50 to $3.50.") cheap_apps = AppDetails.with_price('USD', 1.50, 3.50) free_apps = AppDetails.with_price('USD', 0) found_apps = free_apps + cheap_apps self.print_apps(found_apps) # Assert that app details were found. self.assertTrue(found_apps) # Assert that found app details match the given params. for app_details in found_apps: self.assertTrue(app_details.currency == 'USD') self.assertTrue(app_details.price == 0 or ((app_details.price >= 1.5) & (app_details.price <= 3.5)))
def test_free_or_cheap(self): print("\nFind all apps that are free or a price from $1.50 to $3.50.") cheap_apps = AppDetails.with_price('USD', 1.50, 3.50) free_apps = AppDetails.with_price('USD', 0) found_apps = free_apps + cheap_apps self.print_apps(found_apps) # Assert that app details were found. self.assertTrue(found_apps) # Assert that found app details match the given params. for app_details in found_apps: self.assertTrue(app_details.currency == 'USD') self.assertTrue(app_details.price == 0 or ( (app_details.price >= 1.5) & (app_details.price <= 3.5) ))
def test_save(self): app_id = 100 country = 'in' app_details = AppDetails(app_id, country) engine.save(app_details, overwrite=True) engine.delete_key(AppDetails, app_id=app_id, country=country) app_details = engine.get(AppDetails, app_id=app_id, country=country) self.assertIsNone(app_details)
def test_ipad2(self): print("\nFind all apps that work on any model of iPodTouchFourthGen.") device = 'iPodTouchFourthGen' supported_apps = AppDetails.with_supportedDevice(device) self.print_apps(supported_apps) # Assert that app details were found. self.assertTrue(supported_apps) # Assert that found app details match the device given. for app_details in supported_apps: self.assertIn(device, app_details.supportedDevices)
def load_app_details(app_ids, countries): """ Queries external app store API for avaliable data for each app_id/countries combination. If data found, saves details in the AppDetails table. """ for app_id in app_ids: for country in countries: data = get_app_data(app_id, country) if not data: continue app_details = AppDetails(app_id, country, data=data) engine.save(app_details)