def test_merge_differing_capitalization(self): # this tests #19 insert_rows(self.scratch_db, 'brand', [ dict(brand='CardScan', company='Newell Rubbermaid', scraper_id='sr.campaign.hrc'), dict(brand='Cardscan', company='Newell Rubbermaid', scraper_id='sr.campaign.hrc'), ]) insert_row(self.output_db, 'scraper_company_map', dict( company='Newell Rubbermaid', scraper_company='Newell Rubbermaid', scraper_id='sr.campaign.hrc') ) build_scraper_brand_map_table(self.output_db, self.scratch_db) self.assertEqual( select_all(self.output_db, 'scraper_brand_map'), [dict(brand='CardScan', company='Newell Rubbermaid', scraper_brand='CardScan', scraper_company='Newell Rubbermaid', scraper_id='sr.campaign.hrc'), dict(brand='CardScan', company='Newell Rubbermaid', scraper_brand='Cardscan', scraper_company='Newell Rubbermaid', scraper_id='sr.campaign.hrc'), ])
def test_discard_null_judgment(self): # this tests issue #22 insert_row(self.scratch_db, 'claim', dict( scraper_id='sr.campaign.qux', campaign_id='qux', company='Foo & Co.', brand='', claim='>80% of variables are metasyntactic')) build_claim_table(self.output_db, self.scratch_db) self.assertEqual(select_all(self.output_db, 'claim'), [])
def test_one_row_group(self): ONE_ROW = dict( company='Foo', scraper_company='Foo', scraper_id='sr.campaign.bar') insert_row(self.output_db, 'scraper_company_map', ONE_ROW) self.assertEqual( list(select_groups( self.output_db, 'scraper_company_map', ['company'])), [(('Foo',), [ONE_ROW])])
def test_discard_null_judgment(self): # this tests issue #22 insert_row(self.scratch_db, 'rating', dict( scraper_id='sr.campaign.qux', campaign_id='qux', company='Foo & Co.', brand='', scope='')) build_rating_table(self.output_db, self.scratch_db) self.assertEqual(select_all(self.output_db, 'rating'), [])
def setUp(self): super().setUp() # have company/brand maps ready insert_row(self.output_db, 'scraper_company_map', dict( scraper_id='sr.campaign.qux', company='Foo', scraper_company='Foo & Co.')) insert_row(self.output_db, 'scraper_brand_map', dict( scraper_id='sr.campaign.qux', company='Foo', brand='Bar', scraper_company='Foo & Co.', scraper_brand='BAR™'))
def test_map_brand(self): insert_row(self.scratch_db, 'rating', dict( scraper_id='sr.campaign.qux', campaign_id='qux', company='Foo & Co.', brand='BAR™', judgment=-1)) build_rating_table(self.output_db, self.scratch_db) self.assertEqual( [strip_null(row) for row in select_all(self.output_db, 'rating')], [dict(campaign_id='qux', company='Foo', brand='Bar', scope='', judgment=-1)])
def test_map_brand(self): insert_row(self.scratch_db, 'claim', dict( scraper_id='sr.campaign.qux', campaign_id='qux', company='Foo & Co.', brand='BAR™', claim='code of conduct mandates unreadable code', judgment=-1)) build_claim_table(self.output_db, self.scratch_db) self.assertEqual( [strip_null(row) for row in select_all(self.output_db, 'claim')], [dict(campaign_id='qux', company='Foo', brand='Bar', scope='', claim='code of conduct mandates unreadable code', judgment=-1)])
def test_map_company(self): insert_row(self.scratch_db, 'claim', dict( scraper_id='sr.campaign.qux', campaign_id='qux', company='Foo & Co.', brand='', claim='>80% of variables are metasyntactic', judgment=1)) build_claim_table(self.output_db, self.scratch_db) self.assertEqual( [strip_null(row) for row in select_all(self.output_db, 'claim')], [dict(campaign_id='qux', company='Foo', brand='', scope='', claim='>80% of variables are metasyntactic', judgment=1)])
def test_infer_judgment_from_grade(self): # this tests issue #23 insert_row(self.scratch_db, 'rating', dict( scraper_id='sr.campaign.qux', campaign_id='qux', company='Foo & Co.', brand='', scope='', grade='B')) build_rating_table(self.output_db, self.scratch_db) self.assertEqual( [strip_null(row) for row in select_all(self.output_db, 'rating')], [dict(campaign_id='qux', company='Foo', brand='', scope='', grade='B', judgment=1)])
def insert_rows(db, table_name, rows): """Call insert_row() multiple times. Would want to use multi-row insert syntax before putting this in msd.db (but we don't actually need it).""" for row in rows: insert_row(db, table_name, row)