当前位置: 首页>>代码示例>>Python>>正文


Python Reviewer.get_response方法代码示例

本文整理汇总了Python中holmes.reviewer.Reviewer.get_response方法的典型用法代码示例。如果您正苦于以下问题:Python Reviewer.get_response方法的具体用法?Python Reviewer.get_response怎么用?Python Reviewer.get_response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在holmes.reviewer.Reviewer的用法示例。


在下文中一共展示了Reviewer.get_response方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_force_canonical

# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import get_response [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)
        )
开发者ID:skyonamine,项目名称:holmes-api,代码行数:32,代码来源:test_link_with_rel_canonical.py

示例2: test_can_validate_css_requests_empty_html

# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import get_response [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()
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:36,代码来源:test_css_requests.py

示例3: test_validator

# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import get_response [as 别名]
    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
        )
开发者ID:pombredanne,项目名称:holmes-api,代码行数:35,代码来源:test_links_with_rel_nofollow.py

示例4: test_can_validate_without_meta_tags

# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import get_response [as 别名]
    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()
开发者ID:pombredanne,项目名称:holmes-api,代码行数:29,代码来源:test_open_graph.py

示例5: test_can_validate

# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import get_response [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=[],
        )

        content = '<html><meta charset="UTF-8"></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.review.data = {"meta.tags": [{"key": "meta", "content": "utf-8", "property": ""}]}

        validator.validate()

        expect(validator.add_violation.call_args_list).to_include(
            call(points=200, key="absent.metatags.open_graph", value=["og:title", "og:type", "og:image", "og:url"])
        )
开发者ID:pombredanne,项目名称:holmes-api,代码行数:29,代码来源:test_open_graph.py

示例6: test_can_validate_css_requests_on_globo_html

# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import get_response [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
            ))
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:62,代码来源:test_css_requests.py

示例7: test_can_validate_js_requests_empty_html

# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import get_response [as 别名]
    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()
开发者ID:pombredanne,项目名称:holmes-api,代码行数:32,代码来源:test_js_requests_validator.py

示例8: test_no_body_tag

# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import get_response [as 别名]
    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()
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:33,代码来源:test_schema_org_item_type.py

示例9: test_query_string_without_params

# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import get_response [as 别名]
    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()
开发者ID:skyonamine,项目名称:holmes-api,代码行数:30,代码来源:test_link_with_rel_canonical.py

示例10: test_can_validate_page_without_meta_tags

# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import get_response [as 别名]
    def test_can_validate_page_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 = MetaTagsValidator(reviewer)
        validator.add_fact = Mock()
        validator.add_violation = Mock()
        validator.validate()

        validator.add_violation.assert_called_once_with(
            key='absent.metatags',
            value='No metatags.',
            points=100
        )
开发者ID:pombredanne,项目名称:holmes-api,代码行数:37,代码来源:test_meta_tags.py

示例11: test_can_get_violation_definitions

# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import get_response [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()
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:37,代码来源:test_js_requests_validator.py

示例12: test_validate_page_with_invalid_url

# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import get_response [as 别名]
    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()
开发者ID:pombredanne,项目名称:holmes-api,代码行数:34,代码来源:test_link_with_rel_canonical.py

示例13: test_can_validate_image_requests_on_globo_html

# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import get_response [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
            ))
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:62,代码来源:test_img_requests.py

示例14: test_can_validate_no_title_tag

# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import get_response [as 别名]
    def test_can_validate_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(),
            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 = TitleValidator(reviewer)

        validator.add_violation = Mock()

        validator.validate()

        validator.add_violation.assert_called_once_with(
            key='page.title.not_found',
            value=page.url,
            points=50)
开发者ID:pombredanne,项目名称:holmes-api,代码行数:35,代码来源:test_title.py

示例15: test_validator

# 需要导入模块: from holmes.reviewer import Reviewer [as 别名]
# 或者: from holmes.reviewer.Reviewer import get_response [as 别名]
    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=[]
        )

        url1 = 'http://globo.com/b.html'
        url2 = 'http://globo.com/a.html'

        content = '<html><a href="%s">Test</a><a href="%s">Test</a></html>' % (
            url1, url2)

        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 = LinkWithRedirectValidator(reviewer)

        validator.add_violation = Mock()

        status_307 = Mock(status_code=307, text='Temporary Redirect')
        status_302 = Mock(status_code=302, text='Found')

        validator.review.data = {
            'page.links': [
                (url1, status_307),
                (url2, status_302)
            ]
        }

        validator.validate()

        expect(validator.add_violation.call_args_list).to_include(
            call(
                key='link.redirect.307',
                value=307,
                points=10
            ))

        expect(validator.add_violation.call_args_list).to_include(
            call(
                key='link.redirect.302',
                value=302,
                points=10
            ))
开发者ID:diegosaouda,项目名称:holmes-api,代码行数:61,代码来源:test_link_with_redirect.py


注:本文中的holmes.reviewer.Reviewer.get_response方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。