本文整理汇总了Python中holmes.reviewer.Reviewer.violation_definitions方法的典型用法代码示例。如果您正苦于以下问题:Python Reviewer.violation_definitions方法的具体用法?Python Reviewer.violation_definitions怎么用?Python Reviewer.violation_definitions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类holmes.reviewer.Reviewer
的用法示例。
在下文中一共展示了Reviewer.violation_definitions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_can_validate_css_requests_empty_html
# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import violation_definitions [as 别名]
def test_can_validate_css_requests_empty_html(self):
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=[],
cache=self.sync_cache
)
reviewer.violation_definitions = {
'total.requests.css': {'default_value': 1},
'total.size.css': {'default_value': 0.0},
}
result = {
'url': page.url,
'status': 200,
'content': None,
'html': None
}
reviewer.responses[page.url] = result
reviewer.get_response = Mock(return_value=result)
validator = CSSRequestsValidator(reviewer)
validator.add_violation = Mock()
validator.validate()
expect(validator.add_violation.called).to_be_false()
示例2: test_can_validate_css_requests_on_globo_html
# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import violation_definitions [as 别名]
def test_can_validate_css_requests_on_globo_html(self):
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=[],
cache=self.sync_cache
)
reviewer.violation_definitions = {
'total.requests.css': {'default_value': 1},
'total.size.css': {'default_value': 0.0},
}
content = self.get_file('globo.html')
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 = CSSRequestsValidator(reviewer)
css = {
'url': 'some_style.css',
'status': 200,
'content': '#id{display:none}',
'html': None
}
validator.get_response = Mock(return_value=css)
validator.add_violation = Mock()
validator.review.data = {
'total.requests.css': 7,
'total.size.css.gzipped': 0.05
}
validator.validate()
expect(validator.add_violation.call_args_list).to_include(
call(
key='total.requests.css',
value={'over_limit': 6, 'total_css_files': 7},
points=30
))
expect(validator.add_violation.call_args_list).to_include(
call(
key='total.size.css',
value=0.05,
points=0
))
示例3: test_can_validate_image_requests_on_globo_html
# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import violation_definitions [as 别名]
def test_can_validate_image_requests_on_globo_html(self):
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=[],
cache=self.sync_cache
)
content = self.get_file('globo.html')
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)
reviewer.violation_definitions = {
'single.size.img': {'default_value': 6},
'total.requests.img': {'default_value': 50},
'total.size.img': {'default_value': 100},
}
validator = ImageRequestsValidator(reviewer)
validator.add_violation = Mock()
validator.review.data = {
'page.images': [
(
'some_image.jpg',
Mock(status_code=200, text=self.get_file('2x2.png'))
) for i in range(60)
],
'total.size.img': 106,
}
validator.validate()
expect(validator.add_violation.call_args_list).to_include(
call(
key='total.requests.img',
value={'total': 60, 'limit': 10},
points=50
))
expect(validator.add_violation.call_args_list).to_include(
call(
key='single.size.img',
value={
'limit': 6,
'over_max_size': set([('some_image.jpg', 6.57421875)])
},
points=0.57421875
))
示例4: test_can_validate_page_with_metatag_description_too_long
# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import violation_definitions [as 别名]
def test_can_validate_page_with_metatag_description_too_long(self):
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=[],
cache=self.sync_cache
)
reviewer.violation_definitions = {
'page.metatags.description_too_big': {'default_value': 300},
}
validator = MetaTagsValidator(reviewer)
validator.add_violation = Mock()
validator.review.data['meta.tags'] = [
{'content': 'X' * 301, 'property': 'name', 'key': 'description'},
]
validator.validate()
validator.add_violation.assert_called_once_with(
key='page.metatags.description_too_big',
value={'max_size': 300},
points=20
)
validator.add_violation = Mock()
validator.review.data['meta.tags'] = [
{'content': 'X' * 300, 'property': 'name', 'key': 'description'},
]
validator.validate()
expect(validator.add_violation.called).to_be_false()
示例5: test_force_canonical
# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import violation_definitions [as 别名]
def test_force_canonical(self):
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=[],
cache=self.sync_cache,
)
reviewer.violation_definitions = {"absent.meta.canonical": {"default_value": True}}
content = "<html><head></head></html>"
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 = LinkWithRelCanonicalValidator(reviewer)
validator.add_violation = Mock()
validator.review.data = {"page.head": [{}]}
validator.validate()
expect(validator.add_violation.call_args_list).to_include(
call(key="absent.meta.canonical", value=None, points=30)
)
示例6: test_can_get_violation_definitions
# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import violation_definitions [as 别名]
def test_can_get_violation_definitions(self):
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=[]
)
reviewer.violation_definitions = {
'total.size.js': {'default_value': 0.03},
'total.requests.js': {'default_value': 1},
}
content = self.get_file('globo.html')
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 = JSRequestsValidator(reviewer)
definitions = validator.get_violation_definitions()
expect(definitions).to_length(2)
expect('total.size.js' in definitions).to_be_true()
expect('total.requests.js' in definitions).to_be_true()
示例7: test_can_validate_title_size_with_domain
# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import violation_definitions [as 别名]
def test_can_validate_title_size_with_domain(self):
self.db.query(Key).delete()
self.db.query(KeysCategory).delete()
config = Config()
config.MAX_TITLE_SIZE = 70
key = Key(name='page.title.size')
domain = DomainFactory.create(name='globo.com', url='http://globo.com')
page = PageFactory.create(domain=domain, url='http://globo.com/a.html')
self.sync_cache.redis.delete('violations-prefs-%s' % domain.name)
DomainsViolationsPrefsFactory.create(
domain=domain,
key=key,
value='10'
)
reviewer = Reviewer(
api_url='http://localhost:2368',
page_uuid=page.uuid,
page_url=page.url,
page_score=0.0,
config=config,
validators=[],
cache=self.sync_cache
)
title = 'a' * 80
content = '<html><title>%s</title></html>' % title
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)
reviewer.violation_definitions = {
'page.title.size': {'default_value': 70, 'key': key},
}
validator = TitleValidator(reviewer)
validator.add_violation = Mock()
validator.review.data = {
'page.title_count': 1,
'page.title': title
}
validator.validate()
validator.add_violation.assert_called_once_with(
key='page.title.size',
value={'max_size': 10, 'page_url': page.url},
points=10
)
示例8: test_can_validate_heading_hierarchy
# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import violation_definitions [as 别名]
def test_can_validate_heading_hierarchy(self):
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=[],
cache=self.sync_cache
)
reviewer.violation_definitions = {
'page.heading_hierarchy.size': {'default_value': 150},
}
content = self.get_file('globo.html')
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 = HeadingHierarchyValidator(reviewer)
# expecting no call of add_violation method
validator.add_violation = Mock()
validator.review.data = {
'page.heading_hierarchy': [
('h1', 'Loren ipsum dolor sit amet'),
]
}
validator.validate()
expect(validator.add_violation.called).to_be_false()
# expecting calling add_violation for `page.heading_hierarchy.size`
validator.add_violation = Mock()
hh_list = [
('h1', 'Loren ipsum dolor sit amet' * 10),
('h1', 'Loren ipsum dolor sit amet' * 10),
]
validator.review.data = {'page.heading_hierarchy': hh_list}
validator.validate()
expect(validator.add_violation.called).to_be_true()
validator.add_violation.assert_called_once_with(
key='page.heading_hierarchy.size',
value={
'max_size': 150, 'hh_list': hh_list,
},
points=40
)
示例9: test_can_validate_title_size
# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import violation_definitions [as 别名]
def test_can_validate_title_size(self):
config = Config()
config.MAX_TITLE_SIZE = 70
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=[],
cache=self.sync_cache
)
title = 'a' * 80
content = '<html><title>%s</title></html>' % title
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)
reviewer.violation_definitions = {
'page.title.size': {'default_value': 70},
}
validator = TitleValidator(reviewer)
validator.add_violation = Mock()
validator.review.data = {
'page.title_count': 1,
'page.title': title
}
validator.validate()
validator.add_violation.assert_called_once_with(
key='page.title.size',
value={'max_size': 70, 'page_url': page.url},
points=10
)
示例10: test_has_invalid_itemtype
# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import violation_definitions [as 别名]
def test_has_invalid_itemtype(self):
config = Config()
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=[],
cache=self.sync_cache
)
reviewer.violation_definitions = {
'invalid.schema.itemtype': {
'default_value': ['http://schema.org/AboutPage']
}
}
content = '<html><body itemtype="http://schema.org/a"></body></html>'
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 = SchemaOrgItemTypeValidator(reviewer)
validator.add_violation = Mock()
validator.review.data = {
'page.body': [{'itemtype': 'a'}]
}
validator.validate()
expect(validator.add_violation.call_args_list).to_include(
call(
key='invalid.schema.itemtype',
value=None,
points=10
))
示例11: test_can_validate
# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import violation_definitions [as 别名]
def test_can_validate(self):
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=[],
cache=self.sync_cache
)
reviewer.violation_definitions = {
'blacklist.domains': {'default_value': ['a.com']},
}
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']
)
示例12: test_can_validate_page_without_required_meta_tag
# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import violation_definitions [as 别名]
def test_can_validate_page_without_required_meta_tag(self):
config = Config()
config.REQUIRED_META_TAGS = ['description']
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=[],
cache=self.sync_cache
)
content = '<html></html>'
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)
reviewer.violation_definitions = {
'absent.meta.tags': {'default_value': ['description']},
}
validator = RequiredMetaTagsValidator(reviewer)
validator.add_violation = Mock()
validator.review.data = {
'meta.tags': [{'key': None}]
}
validator.validate()
for tag in reviewer.config.REQUIRED_META_TAGS:
validator.add_violation.assert_called_with(
key='absent.meta.tags',
value=[tag],
points=20
)
示例13: test_can_validate_single_image_html
# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import violation_definitions [as 别名]
def test_can_validate_single_image_html(self):
page = PageFactory.create(url="http://globo.com")
reviewer = Reviewer(
api_url='http://localhost:2368',
page_uuid=page.uuid,
page_url=page.url,
page_score=0.0,
config=Config(),
validators=[],
cache=self.sync_cache
)
reviewer.violation_definitions = {
'single.size.img': {'default_value': 6},
'total.requests.img': {'default_value': 50},
'total.size.img': {'default_value': 100},
}
content = "<html><img src='/some_image.jpg'/></html>"
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 = ImageRequestsValidator(reviewer)
validator.add_violation = Mock()
validator.review.data = {
'page.images': [
('http://globo.com/some_image.jpg', Mock(status_code=200, text='bla'))
],
'total.size.img': 60,
}
validator.validate()
expect(validator.add_violation.called).to_be_false()
示例14: test_can_get_violation_pref
# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import violation_definitions [as 别名]
def test_can_get_violation_pref(self):
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=[],
cache=self.sync_cache
)
reviewer.violation_definitions = {
'page.title.size': {'default_value': 70},
}
validator = Validator(reviewer)
page_title_size = validator.get_violation_pref('page.title.size')
expect(page_title_size).to_equal(70)
示例15: test_can_validate_title
# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import violation_definitions [as 别名]
def test_can_validate_title(self):
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=[],
cache=self.sync_cache
)
content = self.get_file('globo.html')
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)
reviewer.violation_definitions = {
'page.title.size': {'default_value': 70},
}
validator = TitleValidator(reviewer)
validator.add_violation = Mock()
validator.review.data = {
'page.title_count': 1,
'page.title': ['the title']
}
validator.validate()
expect(validator.add_violation.called).to_be_false()