本文整理汇总了Python中holmes.reviewer.Reviewer类的典型用法代码示例。如果您正苦于以下问题:Python Reviewer类的具体用法?Python Reviewer怎么用?Python Reviewer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Reviewer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_validate_page_with_invalid_url
def test_validate_page_with_invalid_url(self):
config = Config()
page = PageFactory.create(url='http://[globo.com/1?item=test')
reviewer = Reviewer(
api_url='http://localhost:2368',
page_uuid=page.uuid,
page_url=page.url,
page_score=0.0,
config=config,
validators=[]
)
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.called).to_be_false()
示例2: test_can_validate_image_requests_on_globo_html
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
))
示例3: test_handle_sitemap_url_loaded
def test_handle_sitemap_url_loaded(self):
page = PageFactory.create(url="http://g1.globo.com/")
reviewer = Reviewer(
api_url='http://localhost:2368',
page_uuid=page.uuid,
page_url=page.url,
page_score=0.0,
config=Config(),
validators=[]
)
reviewer.enqueue = Mock()
content = self.get_file('url_sitemap.xml')
response = Mock(status_code=200, text=content)
facter = SitemapFacter(reviewer)
facter.async_get = Mock()
facter.get_facts()
facter.handle_sitemap_loaded("http://g1.globo.com/sitemap.xml", response)
expect(facter.review.data['sitemap.files.size']["http://g1.globo.com/sitemap.xml"]).to_equal(0.296875)
expect(facter.review.data['sitemap.urls']["http://g1.globo.com/sitemap.xml"]).to_equal(set(['http://domain.com/1.html', 'http://domain.com/2.html']))
expect(facter.review.facts['total.size.sitemap']['value']).to_equal(0.296875)
expect(facter.review.facts['total.size.sitemap.gzipped']['value']).to_equal(0.1494140625)
expect(facter.review.data['total.size.sitemap']).to_equal(0.296875)
expect(facter.review.data['total.size.sitemap.gzipped']).to_equal(0.1494140625)
expect(facter.review.data['sitemap.files.urls']["http://g1.globo.com/sitemap.xml"]).to_equal(2)
expect(facter.review.facts['total.sitemap.urls']['value']).to_equal(2)
示例4: test_validator
def test_validator(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=[],
)
url = "http://my-site.com/test.html"
content = '<html><a href="%s" rel="nofollow">Test</a></html>' % url
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 = LinkWithRelNofollowValidator(reviewer)
validator.add_violation = Mock()
validator.review.data = {"page.all_links": [{"href": url, "rel": "nofollow"}]}
validator.validate()
validator.add_violation.assert_called_once_with(
key="invalid.links.nofollow", value=["http://my-site.com/test.html"], points=10
)
示例5: test_no_body_tag
def test_no_body_tag(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=[]
)
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)
validator = SchemaOrgItemTypeValidator(reviewer)
validator.add_violation = Mock()
validator.validate()
expect(validator.add_violation.called).to_be_false()
示例6: test_can_validate_js_requests_empty_html
def test_can_validate_js_requests_empty_html(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=[]
)
result = {
'url': page.url,
'status': 200,
'content': None,
'html': None
}
reviewer.responses[page.url] = result
reviewer.get_response = Mock(return_value=result)
validator = JSRequestsValidator(reviewer)
validator.add_violation = Mock()
validator.validate()
expect(validator.add_violation.called).to_be_false()
示例7: test_force_canonical
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)
)
示例8: test_query_string_without_params
def test_query_string_without_params(self):
config = Config()
config.FORCE_CANONICAL = False
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 = "<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.called).to_be_false()
示例9: test_can_get_violation_definitions
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()
示例10: test_handle_url_loaded
def test_handle_url_loaded(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(),
facters=[],
)
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._wait_for_async_requests = Mock()
reviewer.save_review = Mock()
response = Mock(status_code=200, text=content, headers={})
reviewer.content_loaded(page.url, response)
facter = LinkFacter(reviewer)
facter.async_get = Mock()
facter.get_facts()
facter.handle_url_loaded(page.url, response)
expect(facter.review.data).to_include("page.links")
data = set([(page.url, response)])
expect(facter.review.data["page.links"]).to_equal(data)
示例11: _start_reviewer
def _start_reviewer(self, job):
if job:
if count_url_levels(job['url']) > self.config.MAX_URL_LEVELS:
self.info('Max URL levels! Details: %s' % job['url'])
return
self.debug('Starting Review for [%s]' % job['url'])
reviewer = Reviewer(
api_url=self.config.HOLMES_API_URL,
page_uuid=job['page'],
page_url=job['url'],
page_score=job['score'],
increase_lambda_tax_method=self._increase_lambda_tax,
config=self.config,
validators=self.validators,
facters=self.facters,
async_get=self.async_get,
wait=self.otto.wait,
wait_timeout=0, # max time to wait for all requests to finish
db=self.db,
cache=self.cache,
publish=self.publish,
fact_definitions=self.fact_definitions,
violation_definitions=self.violation_definitions
)
reviewer.review()
示例12: test_can_validate_page_with_metatag_description_too_long
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()
示例13: test_can_validate_css_requests_on_globo_html
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
))
示例14: test_can_validate_without_meta_tags
def test_can_validate_without_meta_tags(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=[],
)
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)
validator = OpenGraphValidator(reviewer)
validator.add_violation = Mock()
validator.validate()
expect(validator.add_violation.called).to_be_false()
示例15: test_no_title_tag
def test_no_title_tag(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(),
facters=[]
)
content = '<html></html>'
result = {
'url': page.url,
'status': 200,
'content': content,
'html': lxml.html.fromstring(content)
}
reviewer.responses[page.url] = result
reviewer._wait_for_async_requests = Mock()
reviewer.save_review = Mock()
reviewer.content_loaded(page.url, Mock(status_code=200, text=content, headers={}))
facter = TitleFacter(reviewer)
facter.add_fact = Mock()
facter.get_facts()
expect(facter.add_fact.called).to_be_false()
expect(facter.review.data).to_be_like({})