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
        )
Exemplo n.º 2
0
    def test_can_get_violation_definitions(self):
        reviewer = Mock()
        validator = LinkWithRelNofollowValidator(reviewer)

        definitions = validator.get_violation_definitions()

        expect(definitions).to_length(1)
        expect('invalid.links.nofollow' in definitions).to_be_true()

        links_nofollow = validator.get_links_nofollow_parsed_value(
            ['http://my-site.com/test.html'])
        expect(links_nofollow).to_equal({
            'links':
            '<a href="http://my-site.com/test.html" target="_blank">#0</a>'
        })
    def test_can_get_violation_definitions(self):
        reviewer = Mock()
        validator = LinkWithRelNofollowValidator(reviewer)

        definitions = validator.get_violation_definitions()

        expect(definitions).to_length(1)
        expect('invalid.links.nofollow' in definitions).to_be_true()

        links_nofollow = validator.get_links_nofollow_parsed_value(
            ['http://my-site.com/test.html']
        )
        expect(links_nofollow).to_equal({
            'links': '<a href="http://my-site.com/test.html" target="_blank">#0</a>'
        })
    def test_can_get_violation_definitions(self):
        reviewer = Mock()
        validator = LinkWithRelNofollowValidator(reviewer)

        definitions = validator.get_violation_definitions()

        links_nofollow_message = validator.get_links_nofollow_message(["http://my-site.com/test.html"])

        expect(definitions).to_length(1)
        expect("invalid.links.nofollow" in definitions).to_be_true()

        url = "http://my-site.com/test.html"
        expect(links_nofollow_message).to_equal(
            'Links with rel="nofollow" to the same domain as the page make '
            "it harder for search engines to crawl the website. Links with "
            'rel="nofollow" were found for hrefs (<a href="%s" '
            'target="_blank">#0</a>).' % url
        )
Exemplo n.º 5
0
    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)
    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
        )