def test_can_get_default_violations_values(self): config = Config() config.BLACKLIST_DOMAIN = ['a.com'] page = PageFactory.create() reviewer = Reviewer( api_url='http://localhost:2368', page_uuid=page.uuid, page_url=page.url, page_score=0.0, config=config, validators=[] ) validator = BlackListValidator(reviewer) violations_values = validator.get_default_violations_values(config) expect(violations_values).to_include('blacklist.domains') expect(violations_values['blacklist.domains']).to_length(2) expect(violations_values['blacklist.domains']).to_be_like({ 'value': config.BLACKLIST_DOMAIN, 'description': config.get_description('BLACKLIST_DOMAIN') })
def test_can_get_default_violations_values(self): config = Config() config.BLACKLIST_DOMAIN = ['a.com'] page = PageFactory.create() reviewer = Reviewer(api_url='http://localhost:2368', page_uuid=page.uuid, page_url=page.url, page_score=0.0, config=config, validators=[]) validator = BlackListValidator(reviewer) violations_values = validator.get_default_violations_values(config) expect(violations_values).to_include('blacklist.domains') expect(violations_values['blacklist.domains']).to_length(2) expect(violations_values['blacklist.domains']).to_be_like({ 'value': config.BLACKLIST_DOMAIN, 'description': config.get_description('BLACKLIST_DOMAIN') })
def test_can_validate(self): config = Config() config.BLACKLIST_DOMAIN = ['a.com'] page = PageFactory.create() reviewer = Reviewer( api_url='http://localhost:2368', page_uuid=page.uuid, page_url=page.url, page_score=0.0, config=config, validators=[] ) content = '<a href="http://a.com/test1">A</a>' \ '<a href="http://b.com/test2">B</a>' result = { 'url': page.url, 'status': 200, 'content': content, 'html': lxml.html.fromstring(content) } reviewer.responses[page.url] = result reviewer.get_response = Mock(return_value=result) validator = BlackListValidator(reviewer) validator.review.data = { 'page.all_links': [ {'href': 'http://a.com/test1'}, {'href': 'http://b.com/test2'} ] } validator.add_violation = Mock() validator.validate() validator.add_violation.assert_called_once_with( points=100, key='blacklist.domains', value=['http://a.com/test1'] )