Exemple #1
0
    def test_can_get_facts_without_head(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()
        response = Mock(status_code=200, text=content, headers={})
        reviewer.content_loaded(page.url, response)

        facter = HeadFacter(reviewer)

        facter.add_fact = Mock()

        facter.get_facts()

        expect(facter.add_fact.called).to_be_false()
        expect(facter.review.data).to_be_like({})
Exemple #2
0
    def test_can_get_fact_definitions(self):
        reviewer = Mock()
        facter = HeadFacter(reviewer)
        definitions = facter.get_fact_definitions()

        expect(definitions).to_length(0)
        expect(definitions).to_equal({})
Exemple #3
0
    def test_can_get_facts(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><head><link rel="canonical" href="http://my-url.com?item=test" /></head></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 = HeadFacter(reviewer)
        facter.add_fact = Mock()

        facter.get_facts()

        expect(facter.review.data).to_length(1)

        expect(facter.review.data).to_include('page.head')
        head = facter.review.data['page.head'][0]
        expect(head.tag).to_equal('head')
        data = [('rel', 'canonical'), ('href', 'http://my-url.com?item=test')]
        expect(head.getchildren()[0].items()).to_equal(data)

        expect(facter.add_fact.called).to_be_false()