def test_can_insert_default_violations_values_for_all_domains(self): DomainsViolationsPrefsFactory.create(domain=Domain(name='globo.com'), key=Key(name='some.random.fact'), value='whatever') for x in range(3): DomainFactory.create(name='g%d.com' % x) domains_violations_prefs = \ DomainsViolationsPrefs.get_domains_violations_prefs(self.db) expect(domains_violations_prefs).to_length(1) default_violations_values = { 'page.title.size': 100, 'total.requests.img': 5, } page_title_size = KeyFactory.create(name='page.title.size') total_requests_img = KeyFactory.create(name='total.requests.img') violation_definitions = { 'page.title.size': { 'key': page_title_size, 'default_value': 100 }, 'total.requests.img': { 'key': total_requests_img, 'default_value': 5 } } DomainsViolationsPrefs.insert_default_violations_values_for_all_domains( self.db, default_violations_values, violation_definitions, self.cache) domains_violations_prefs = \ DomainsViolationsPrefs.get_domains_violations_prefs(self.db) expect(domains_violations_prefs).to_length(4) expect(domains_violations_prefs).to_be_like({ 'globo.com': { 'some.random.fact': 'whatever', 'total.requests.img': 5, 'page.title.size': 100 }, 'g0.com': { 'page.title.size': 100, 'total.requests.img': 5 }, 'g1.com': { 'page.title.size': 100, 'total.requests.img': 5 }, 'g2.com': { 'page.title.size': 100, 'total.requests.img': 5 }, })
def test_can_insert_default_violations_values_for_all_domains(self): DomainsViolationsPrefsFactory.create( domain=Domain(name='globo.com'), key=Key(name='some.random.fact'), value='whatever' ) for x in range(3): DomainFactory.create(name='g%d.com' % x) domains_violations_prefs = \ DomainsViolationsPrefs.get_domains_violations_prefs(self.db) expect(domains_violations_prefs).to_length(1) default_violations_values = { 'page.title.size': 100, 'total.requests.img': 5, } page_title_size = KeyFactory.create(name='page.title.size') total_requests_img = KeyFactory.create(name='total.requests.img') violation_definitions = { 'page.title.size': {'key': page_title_size, 'default_value': 100}, 'total.requests.img': {'key': total_requests_img, 'default_value': 5} } DomainsViolationsPrefs.insert_default_violations_values_for_all_domains( self.db, default_violations_values, violation_definitions, self.cache ) domains_violations_prefs = \ DomainsViolationsPrefs.get_domains_violations_prefs(self.db) expect(domains_violations_prefs).to_length(4) expect(domains_violations_prefs).to_be_like({ 'globo.com': { 'some.random.fact': 'whatever', 'total.requests.img': 5, 'page.title.size': 100 }, 'g0.com': {'page.title.size': 100, 'total.requests.img': 5}, 'g1.com': {'page.title.size': 100, 'total.requests.img': 5}, 'g2.com': {'page.title.size': 100, 'total.requests.img': 5}, })
def test_can_get_domains_violations_prefs(self): data = DomainsViolationsPrefsFactory.create( domain=Domain(name='globo.com'), key=Key(name='some.random.fact'), value='whatever') data = DomainsViolationsPrefs.get_domains_violations_prefs(self.db) expect(data).to_be_like( {'globo.com': { 'some.random.fact': 'whatever' }})
def test_can_get_domains_violations_prefs(self): data = DomainsViolationsPrefsFactory.create( domain=Domain(name='globo.com'), key=Key(name='some.random.fact'), value='whatever' ) data = DomainsViolationsPrefs.get_domains_violations_prefs(self.db) expect(data).to_be_like({ 'globo.com': { 'some.random.fact': 'whatever' } })