Beispiel #1
0
    def test_can_get_page_by_uuid(self):
        page = PageFactory.create()
        PageFactory.create()

        loaded_page = Page.by_uuid(page.uuid, self.db)
        expect(loaded_page.id).to_equal(page.id)

        invalid_page = Page.by_uuid(uuid4(), self.db)
        expect(invalid_page).to_be_null()
Beispiel #2
0
    def test_can_get_page_by_uuid(self):
        page = PageFactory.create()
        PageFactory.create()

        loaded_page = Page.by_uuid(page.uuid, self.db)
        expect(loaded_page.id).to_equal(page.id)

        invalid_page = Page.by_uuid(uuid4(), self.db)
        expect(invalid_page).to_be_null()
Beispiel #3
0
    def get(self, uuid="", limit=10):
        uuid = UUID(uuid)

        page = Page.by_uuid(uuid, self.db)

        if not page:
            self.set_status(404, self._("Page UUID [%s] not found") % uuid)
            return

        reviews = (
            self.db.query(Review)
            .filter(Review.page == page)
            .filter(Review.is_complete == True)
            .order_by(Review.completed_date.desc())[:limit]
        )

        result = []
        for review in reviews:
            result.append(
                {
                    "uuid": str(review.uuid),
                    "completedAt": review.completed_date,
                    "violationCount": review.violation_count,
                }
            )

        self.write_json(result)
Beispiel #4
0
    def get(self, page_uuid, review_uuid):
        review = None
        page = None
        if self._parse_uuid(review_uuid):
            review = Review.by_uuid(review_uuid, self.db)

        if self._parse_uuid(page_uuid):
            page = Page.by_uuid(page_uuid, self.db)

        if not review and page:
            self.redirect('/page/%s/review/%s/' % (page_uuid, page.last_review_uuid))
            return

        if not page:
            self.set_status(404, self._('Page UUID [%s] not found') % page_uuid)
            return

        result = review.to_dict(self.application.fact_definitions,
                                self.application.violation_definitions,
                                self._)
        result.update({
            'violationPoints': review.get_violation_points(),
            'violationCount': review.violation_count,
        })

        self.write_json(result)
Beispiel #5
0
    def get(self, page_uuid, review_uuid):
        review = None
        page = None
        if self._parse_uuid(review_uuid):
            review = Review.by_uuid(review_uuid, self.db)

        if self._parse_uuid(page_uuid):
            page = Page.by_uuid(page_uuid, self.db)

        if not review and page:
            self.redirect('/page/%s/review/%s/' %
                          (page_uuid, page.last_review_uuid))
            return

        if not page:
            self.set_status(404,
                            self._('Page UUID [%s] not found') % page_uuid)
            return

        result = review.to_dict(self.application.fact_definitions,
                                self.application.violation_definitions, self._)
        result.update({
            'violationPoints': review.get_violation_points(),
            'violationCount': review.violation_count,
        })

        self.write_json(result)
Beispiel #6
0
    def test_can_save(self):
        self.mock_request(status_code=200, effective_url="http://www.globo.com")

        self.server.application.girl = Mock()

        response = yield self.authenticated_fetch(
            '/page', method='POST', body=dumps({
                'url': 'http://www.globo.com'
            })
        )

        expect(response.code).to_equal(200)

        page_uuid = UUID(response.body)
        page = Page.by_uuid(page_uuid, self.db)

        expect(page).not_to_be_null()
        expect(str(page_uuid)).to_equal(page.uuid)

        expect(self.server.application.girl.expire.call_count).to_equal(4)
        self.server.application.girl.assert_has_calls([
            call.expire('domains_details'),
            call.expire('failed_responses_count'),
            call.expire('violation_count_for_domains'),
            call.expire('top_violations_in_category_for_domains'),
        ])
Beispiel #7
0
    def test_can_get_page_by_url_hash(self):
        page = PageFactory.create()
        PageFactory.create()

        loaded_page = Page.by_url_hash(page.url_hash, self.db)
        expect(loaded_page.id).to_equal(page.id)

        invalid_page = Page.by_uuid('123', self.db)
        expect(invalid_page).to_be_null()
Beispiel #8
0
    def test_can_get_page_by_url_hash(self):
        page = PageFactory.create()
        PageFactory.create()

        loaded_page = Page.by_url_hash(page.url_hash, self.db)
        expect(loaded_page.id).to_equal(page.id)

        invalid_page = Page.by_uuid('123', self.db)
        expect(invalid_page).to_be_null()
Beispiel #9
0
    def get(self, uuid=""):
        uuid = UUID(uuid)

        page = Page.by_uuid(uuid, self.db)

        if not page:
            self.set_status(404, self._("Page UUID [%s] not found") % uuid)
            return

        page_json = {"uuid": str(page.uuid), "url": page.url}

        self.write(page_json)
Beispiel #10
0
    def get(self, uuid):
        page = Page.by_uuid(uuid, self.db)

        if not page:
            self.set_status(404, self._('Page UUID [%s] not found') % uuid)
            return

        violations_per_day = page.get_violations_per_day(self.db)

        page_json = {"violations": violations_per_day}

        self.write_json(page_json)
Beispiel #11
0
    def get(self, uuid=''):
        uuid = UUID(uuid)

        page = Page.by_uuid(uuid, self.db)

        if not page:
            self.set_status(404, self._('Page UUID [%s] not found') % uuid)
            return

        page_json = {"uuid": str(page.uuid), "url": page.url}

        self.write(page_json)
Beispiel #12
0
    def get(self, uuid):
        page = Page.by_uuid(uuid, self.db)

        if not page:
            self.set_status(404, self._("Page UUID [%s] not found") % uuid)
            return

        violations_per_day = page.get_violations_per_day(self.db)

        page_json = {"violations": violations_per_day}

        self.write_json(page_json)
Beispiel #13
0
    def test_can_save_known_domain(self):
        DomainFactory.create(url='http://www.globo.com', name='globo.com')

        self.mock_request(status_code=200, effective_url="http://www.globo.com")

        response = yield self.authenticated_fetch(
            '/page',
            method='POST',
            body=dumps({
                'url': 'http://www.globo.com'
            })
        )

        expect(response.code).to_equal(200)

        page_uuid = UUID(response.body)
        page = Page.by_uuid(page_uuid, self.db)

        expect(page).not_to_be_null()
        expect(str(page_uuid)).to_equal(page.uuid)
Beispiel #14
0
    def test_can_save_known_domain(self):
        DomainFactory.create(url='http://www.globo.com', name='globo.com')

        self.mock_request(status_code=200, effective_url="http://www.globo.com")

        response = self.fetch(
            '/page',
            method='POST',
            body=dumps({
                'url': 'http://www.globo.com'
            })
        )

        expect(response.code).to_equal(200)

        page_uuid = UUID(response.body)
        page = Page.by_uuid(page_uuid, self.db)

        expect(page).not_to_be_null()
        expect(str(page_uuid)).to_equal(page.uuid)
Beispiel #15
0
    def test_can_save(self):
        def side_effect(*args, **kw):
            response_mock = Mock(status_code=200, effective_url="http://www.globo.com")
            kw['callback'](response_mock)

        self.mock_request(status_code=200, effective_url="http://www.globo.com")

        response = yield self.http_client.fetch(
            self.get_url('/page'),
            method='POST',
            body=dumps({
                'url': 'http://www.globo.com'
            })
        )

        expect(response.code).to_equal(200)

        page_uuid = UUID(response.body)
        page = Page.by_uuid(page_uuid, self.db)

        expect(page).not_to_be_null()
        expect(str(page_uuid)).to_equal(page.uuid)
Beispiel #16
0
    def get(self, uuid='', limit=10):
        uuid = UUID(uuid)

        page = Page.by_uuid(uuid, self.db)

        if not page:
            self.set_status(404, 'Page UUID [%s] not found' % uuid)
            return

        reviews = self.db.query(Review) \
            .filter(Review.page == page) \
            .filter(Review.is_complete == True) \
            .order_by(Review.completed_date.desc())[:limit]

        result = []
        for review in reviews:
            result.append({
                'uuid': str(review.uuid),
                'completedAt': review.completed_date,
                'violationCount': review.violation_count
            })

        self.write_json(result)
Beispiel #17
0
    def get(self, uuid='', limit=10):
        uuid = UUID(uuid)

        page = Page.by_uuid(uuid, self.db)

        if not page:
            self.set_status(404, self._('Page UUID [%s] not found') % uuid)
            return

        reviews = self.db.query(Review) \
            .filter(Review.page == page) \
            .filter(Review.is_complete == True) \
            .order_by(Review.completed_date.desc())[:limit]

        result = []
        for review in reviews:
            result.append({
                'uuid': str(review.uuid),
                'completedAt': review.completed_date,
                'violationCount': review.violation_count
            })

        self.write_json(result)