Ejemplo n.º 1
0
    def test_count_by_violation_key_name(self):
        self.db.query(Review).delete()
        self.db.query(Violation).delete()

        review = ReviewFactory.create(is_active=True)
        for i in range(3):
            key = Key.get_or_create(self.db, 'violation.%d' % i)
            review.add_violation(key, 'value', 100, review.domain)

        self.db.flush()

        key_id = review.violations[0].key_id
        count = Review.count_by_violation_key_name(self.db, key_id)
        expect(count).to_equal(1)

        for i in range(3):
            key = Key.get_or_create(self.db, 'violation.0')
            review.add_violation(key, 'value', 100, review.domain)

        key_id = review.violations[0].key_id
        count = Review.count_by_violation_key_name(self.db, key_id)
        expect(count).to_equal(4)
Ejemplo n.º 2
0
    def get(self, key_name):
        current_page = int(self.get_argument('current_page', 1))
        page_size = int(self.get_argument('page_size', 10))
        domain_filter = self.get_argument('domain_filter', None)
        page_filter = self.get_argument('page_filter', None)

        domain = None
        if domain_filter is not None:
            domain = Domain.get_domain_by_name(domain_filter, self.db)
            if not domain:
                self.set_status(404,
                                self._('Domain %s not found') % domain_filter)
                self.finish()
                return

        violations = self.application.violation_definitions
        if key_name not in violations:
            self.set_status(404, self._('Invalid violation key %s') % key_name)
            self.finish()
            return

        violation_title = violations[key_name]['title']
        key_id = violations[key_name]['key'].id

        violation = yield self.application.search_provider.get_by_violation_key_name(
            key_id=key_id,
            current_page=current_page,
            page_size=page_size,
            domain=domain,
            page_filter=page_filter,
        )

        if 'error' in violation:
            self.set_status(violation['error']['status_code'],
                            violation['error']['reason'])
            self.finish()
            return

        if 'reviewsCount' not in violation:
            if not domain and not page_filter:
                violation['reviewsCount'] = Review.count_by_violation_key_name(
                    self.db, key_id)
            else:
                violation['reviewsCount'] = None

        violation['title'] = violation_title

        self.write_json(violation)
        self.finish()
Ejemplo n.º 3
0
    def test_count_by_violation_key_name(self):
        self.db.query(Review).delete()
        self.db.query(Violation).delete()

        review = ReviewFactory.create(is_active=True)
        for i in range(3):
            key = Key.get_or_create(self.db, "violation.%d" % i)
            review.add_violation(key, "value", 100, review.domain)
            review.page.last_review_id = review.id
            review.page.last_review_uuid = review.uuid
            review.page.last_review_date = review.completed_date

        self.db.flush()

        key_id = review.violations[0].key_id
        count = Review.count_by_violation_key_name(self.db, key_id)
        expect(count).to_equal(1)
Ejemplo n.º 4
0
    def test_count_by_violation_key_name(self):
        self.db.query(Review).delete()
        self.db.query(Violation).delete()

        review = ReviewFactory.create(is_active=True)
        for i in range(3):
            key = Key.get_or_create(self.db, 'violation.%d' % i)
            review.add_violation(key, 'value', 100, review.domain)
            review.page.last_review_id = review.id
            review.page.last_review_uuid = review.uuid
            review.page.last_review_date = review.completed_date

        self.db.flush()

        key_id = review.violations[0].key_id
        count = Review.count_by_violation_key_name(self.db, key_id)
        expect(count).to_equal(1)
Ejemplo n.º 5
0
    def get(self, key_name):
        current_page = int(self.get_argument('current_page', 1))
        page_size = int(self.get_argument('page_size', 10))
        domain_filter = self.get_argument('domain_filter', None)
        page_filter = self.get_argument('page_filter', None)

        violations = self.application.violation_definitions
        violation_title = violations[key_name]['title']
        key_id = violations[key_name]['key'].id

        reviews = Review.get_by_violation_key_name(
            self.db,
            key_id,
            current_page=current_page,
            page_size=page_size,
            domain_filter=domain_filter,
            page_filter=page_filter,
        )

        reviews_count = Review.count_by_violation_key_name(
            self.db,
            key_id,
            domain_filter=domain_filter,
            page_filter=page_filter
        )

        reviews_data = []
        for item in reviews:
            reviews_data.append({
                'uuid': item.review_uuid,
                'page': {
                    'uuid': item.page_uuid,
                    'url': item.url,
                    'completedAt': item.completed_date
                }
            })

        violation = {
            'title': violation_title,
            'reviews': reviews_data,
            'reviewsCount': reviews_count
        }

        self.write_json(violation)
        self.finish()
Ejemplo n.º 6
0
    def get(self, key_name):
        current_page = int(self.get_argument("current_page", 1))
        page_size = int(self.get_argument("page_size", 10))
        domain_filter = self.get_argument("domain_filter", None)
        page_filter = self.get_argument("page_filter", None)

        domain = None
        if domain_filter is not None:
            domain = Domain.get_domain_by_name(domain_filter, self.db)
            if not domain:
                self.set_status(404, self._("Domain %s not found") % domain_filter)
                self.finish()
                return

        violations = self.application.violation_definitions
        if key_name not in violations:
            self.set_status(404, self._("Invalid violation key %s") % key_name)
            self.finish()
            return

        violation_title = violations[key_name]["title"]
        key_id = violations[key_name]["key"].id

        violation = yield self.application.search_provider.get_by_violation_key_name(
            key_id=key_id, current_page=current_page, page_size=page_size, domain=domain, page_filter=page_filter
        )

        if "error" in violation:
            self.set_status(violation["error"]["status_code"], violation["error"]["reason"])
            self.finish()
            return

        if "reviewsCount" not in violation:
            if not domain and not page_filter:
                violation["reviewsCount"] = Review.count_by_violation_key_name(self.db, key_id)
            else:
                violation["reviewsCount"] = None

        violation["title"] = violation_title

        self.write_json(violation)
        self.finish()