Best Python code snippet using localstack_python
test_scraping.py
Source:test_scraping.py  
...38    self.assertTrue(isinstance(article, news_interface.Article),39        'Expected the result to be an Article instance')40    self.assertEqual(article.headline, headline)41    self.assertEqual(article.date, date)42  def get_query_results(self, news_org, query):43    res = news_org.get_query_results(query)44    self.assertEqual(len(res), news_interface.NUM_ARTICLES,45        'Expected %d articles' % news_interface.NUM_ARTICLES)46    self.assertTrue(isinstance(res[0], news_interface.Article),47        'Expected the result to be an Article instance')48  def test_aljazeera_get_article(self):49    news_org = self.AlJazeera50    url = 'http://www.aljazeera.com/indepth/opinion/2015/01/charlie-hebdo-us-them-201511152114498897.html'51    headline = "Charlie Hebdo: 'Us or them'"52    date = "11 Jan 2015 13:35 GMT"53    self.get_article(news_org, url, headline, date)54  def test_aljazeera_get_query_results(self):55    query = 'charlie+hebdo'56    news_org = self.AlJazeera57    self.get_query_results(news_org, query)58  def test_bbc_get_article(self):59    news_org = self.BBC60    url = 'http://www.bbc.co.uk/news/world-europe-30808284'61    headline = 'Charlie Hebdo attack: Print run for new issue expanded'62    date = '14 January 2015'63    self.get_article(news_org, url, headline, date)64  def test_bbc_get_query_results(self):65    query = 'charlie+hebdo'66    news_org = self.BBC67    self.get_query_results(news_org, query)68  def test_cbc_get_article(self):69    news_org = self.CBC70    url = 'http://www.cbc.ca/news/world/greek-election-left-wing-syriza-party-wins-but-number-of-seats-in-question-1.2930923'71    headline = ('Greek election: Left-wing Syriza party wins but number '72                'of seats in question')73    date = 'Posted: Jan 25, 2015 12:54 AM ET'74    self.get_article(news_org, url, headline, date)75  def test_cbc_get_query_results(self):76    query = 'charlie+hebdo'77    news_org = self.CBC78    self.get_query_results(news_org, query)79  def test_cnn_get_article(self):80    news_org = self.CNN81    url = 'http://www.cnn.com/2015/01/31/middleeast/isis-japan-jordan-hostages/index.html'82    headline = 'Video: ISIS purportedly beheads Japanese hostage'83    date = 'Updated 4:58 PM ET, Tue February 3, 2015'84    self.get_article(news_org, url, headline, date)85  def test_cnn_get_query_results(self):86    query = 'charlie+hebdo'87    news_org = self.CNN88    self.get_query_results(news_org, query)89  def test_globe_and_mail_get_article(self):90    news_org = self.GLOBE_AND_MAIL91    url = 'http://www.theglobeandmail.com/news/world/grade-6-student-killed-by-us-drone-strike-in-yemen-rights-group-says/article22648002/'92    headline = ('Grade 6 student killed by U.S. drone strike in Yemen, '93                'rights group says')94    date = 'Tuesday, Jan. 27 2015, 9:42 AM EST'95    self.get_article(news_org, url, headline, date)96  def test_globe_and_mail_get_query_results(self):97    query = 'charlie+hebdo'98    news_org = self.GLOBE_AND_MAIL99    self.get_query_results(news_org, query)100  def test_guardian_get_article(self):101    news_org = self.GUARDIAN102    url = 'http://www.theguardian.com/sport/2015/jan/25/kevin-pietersen-england-surrey-de-register'103    headline = ("Kevin Pietersen's England hopes hit again as Surrey rule "104                "out return")105    date = 'Sunday 25 January 2015'106    self.get_article(news_org, url, headline, date)107  def test_guardian_get_query_results(self):108    query = 'charlie+hebdo'109    news_org = self.GUARDIAN110    self.get_query_results(news_org, query)111  def test_huff_post_get_article(self):112    news_org = self.HUFF_POST113    url = 'http://www.huffingtonpost.com/2015/01/18/charlie-hebdo-cartoons_n_6496414.html'114    headline = ("Charlie Hebdo Editor Slams News Organizations For Not "115                "Publishing Cartoons")116    date = '01/18/2015 12:05 pm EST'117    self.get_article(news_org, url, headline, date)118  def test_huff_post_get_query_results(self):119    query = 'charlie+hebdo'120    news_org = self.HUFF_POST121    self.get_query_results(news_org, query)122  def test_jpost_get_article(self):123    news_org = self.JPOST124    url = 'http://www.jpost.com/Israel-News/Politics-And-Diplomacy/US-challenges-Israel-to-sharpen-alternative-path-on-Iranian-nuclear-negotiations-392974'125    headline = ("US challenges Israel to sharpen alternative path on "126                "Iranian nuclear negotiations")127    date = '03/05/2015 00:14'128    self.get_article(news_org, url, headline, date)129  def test_jpost_get_query_results(self):130    query = 'charlie+hebdo'131    news_org = self.JPOST132    self.get_query_results(news_org, query)133  def test_ny_post_get_article(self):134    news_org = self.NY_POST135    url = 'http://nypost.com/2015/01/25/paris-terrorists-fit-profile-of-homegrown-threat-described-in-2007-nypd-report/'136    headline = ("Paris terrorists fit profile of homegrown threat "137                "described in 2007 NYPD report")138    date = 'January 25, 2015 | 7:48am'139    self.get_article(news_org, url, headline, date)140  def test_ny_post_get_query_results(self):141    query = 'charlie+hebdo'142    news_org = self.NY_POST143    self.get_query_results(news_org, query)144  def test_ny_times_get_article(self):145    news_org = self.NY_TIMES146    url = 'http://query.nytimes.com/gst/fullpage.html?res=9D07E0D9103CF934A35752C1A9679D8B63'147    headline = ("MEDIA DECODER; A Provocative Newspaper Is Attacked in "148                "France, And Support Is Swift")149    date = 'Published: November 7, 2011'150    self.get_article(news_org, url, headline, date)151  def test_ny_times_get_query_results(self):152    query = 'charlie+hebdo'153    news_org = self.NY_TIMES154    self.get_query_results(news_org, query)155  def test_reuters_get_article(self):156    news_org = self.REUTERS157    url = 'http://www.reuters.com/article/2015/03/04/cnews-us-ukraine-crisis-mine-blast-idCAKBN0M00KR20150304'158    headline = "Thirty-three miners dead after pit blast in east Ukraine"159    date = 'Wed Mar 4, 2015 3:23pm EST'160    self.get_article(news_org, url, headline, date)161  def test_reuters_get_query_results(self):162    query = 'charlie+hebdo'163    news_org = self.REUTERS164    self.get_query_results(news_org, query)165  def test_russia_today_get_article(self):166    news_org = self.RUSSIA_TODAY167    url = 'http://rt.com/news/226531-charlie-hebdo-isis-attacks/'168    headline = ("ISIS urges new attacks on infidel West following "169                "Charlie Hebdo massacre")170    date = 'Published time: January 27, 2015 13:16'171    self.get_article(news_org, url, headline, date)172  def test_russia_today_get_query_results(self):173    query = 'charlie+hebdo'174    news_org = self.RUSSIA_TODAY175    self.get_query_results(news_org, query)176  def test_times_of_israel_get_article(self):177    news_org = self.TIMES_OF_ISRAEL178    url = 'http://www.timesofisrael.com/nuclear-deal-with-west-very-close-zarif-says/'179    headline = "Nuclear deal with West 'very close,' Zarif says"180    date = 'March 5, 2015, 12:29 am'181    self.get_article(news_org, url, headline, date)182  def test_times_of_israel_get_query_results(self):183    query = 'charlie+hebdo'184    news_org = self.TIMES_OF_ISRAEL185    self.get_query_results(news_org, query)186  def test_todays_zaman_get_article(self):187    news_org = self.TODAYS_ZAMAN188    url = 'http://www.todayszaman.com/national_turkish-jetliner-skids-off-on-runway-in-kathmandu-passengers-safe_374261.html'189    headline = ("Turkish jetliner skids off on runway in Kathmandu, "190                "passengers safe")191    date = 'March 04, 2015, Wednesday/ 11:10:46/'192    self.get_article(news_org, url, headline, date)193  def test_todays_zaman_get_query_results(self):194    query = 'charlie+hebdo'195    news_org = self.TODAYS_ZAMAN196    self.get_query_results(news_org, query)197  def test_usa_today_get_article(self):198    news_org = self.USA_TODAY199    url = 'http://www.usatoday.com/story/news/nation-now/2015/01/20/democrat-charlie-hebdo-tribute-obama-speech/22070673/'200    headline = "Democrat organizes 'Charlie Hebdo' tribute at Obama speech"201    date = '6:17 p.m. EST January 20, 2015'202    self.get_article(news_org, url, headline, date)203  def test_usa_today_get_query_results(self):204    query = 'charlie+hebdo'205    news_org = self.USA_TODAY206    self.get_query_results(news_org, query)207if __name__ == '__main__':...metadata.py
Source:metadata.py  
...9@meta_endpoints.route('/meta/release_statistics')10def get_release_statistics() -> Response:11    """ Returns statistics about released entries. """12    results = {}13    def get_query_results(cursor: DictCursor, query: str) -> List[Tuple[int, int]]:14        cursor.execute(query, [])15        return cursor.fetchall()16    with PostgresConnection(ets=True) as cur:17        years_to_show = range(1995, datetime.datetime.now().year + 1)18        # Do the queries19        total_released_in_year = get_query_results(cur, released_in_year)20        original_released_in_year = get_query_results(cur, original_release_in_year)21        removed_in_year = get_query_results(cur, withdrawn_entries_in_year)22        removed_from_year = get_query_results(cur, entries_released_this_year_since_withdrawn)23        structure_total_released_in_year = get_query_results(cur, structure_total_in_year)24        structure_adit_nmr_released_in_year = get_query_results(cur, structure_aditnmr_in_year)25        structure_onedep_released_in_year = get_query_results(cur, structure_onedep_in_year)26        structure_bmrbdep_released_in_year = get_query_results(cur, structure_bmrbdep_in_year)27        nonstructure_total_released_in_year = get_query_results(cur, nonstructure_total_in_year)28        nonstructure_adit_nmr_released_in_year = get_query_results(cur, nonstructure_aditnmr_in_year)29        nonstructure_onedep_released_in_year = get_query_results(cur, nonstructure_onedep_in_year)30        nonstructure_bmrbdep_released_in_year = get_query_results(cur, nonstructure_bmrbdep_in_year)31        def lookup_year(res, search_year: int):32            """ Returns the number of entries for a year from a list. """33            for row in res:34                if row[0] == search_year:35                    return row[1]36            return 037        # Use this do to the calculations38        total_released_by_year = 039        original_released_by_year = 040        structure_released_by_year = 041        nonstructure_released_by_year = 042        for year in years_to_show:43            total_released_by_year += lookup_year(total_released_in_year, year)44            original_released_by_year += lookup_year(original_released_in_year, year)...test_db.py
Source:test_db.py  
...4async def test_db_fill():5    """6    Test db recreation.7    """8    recipes_before = await get_query_results("SELECT * FROM recipes")9    new_recipe_name = "test_recipe"10    new_recipe_components = [{"item": "мÑÑо", "q": 1000}]11    await execute_query(12        "INSERT INTO recipes (recipe_name, components) VALUES (?,?)",13        (new_recipe_name, json.dumps(new_recipe_components)),14    )15    recipes_middle = await get_query_results("SELECT * FROM recipes")16    db_fill(force_recreate=True)17    recipes_after = await get_query_results("SELECT * FROM recipes")18    assert recipes_before != recipes_middle19    assert recipes_before == recipes_after20async def test_get_query_results():21    """22    Test db creation, insertion, and selection of data.23    """24    recipes = await get_query_results("SELECT * FROM recipes")25    with FILE_PATH.open(encoding="UTF-8") as f:26        original_recipes = json.load(f)["recipes"]27    formatted_recipes = []28    for recipe in original_recipes:29        formatted_recipes.append(30            (recipe["name"], json.dumps(recipe["components"], ensure_ascii=False), 0)31        )32    assert recipes == formatted_recipes33async def test_execute_query():34    """35    Test insert query execution.36    """37    recipes_before = await get_query_results("SELECT * FROM recipes")38    new_recipe_name = "test_recipe"39    new_recipe_components = [{"item": "мÑÑо", "q": 1000}]40    await execute_query(41        "INSERT INTO recipes (recipe_name, components) VALUES (?,?)",42        (new_recipe_name, json.dumps(new_recipe_components)),43    )44    recipes_after = await get_query_results("SELECT * FROM recipes")45    recipes_before.append((new_recipe_name, json.dumps(new_recipe_components), 0))...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
