Example #1
0
    def test_priority_on_create(self):
        rule1 = PriorityRule(path="/", method="GET", priority=PriorityRule.PRIOR_HIGH)
        rule1.save()

        self.client.get("/")

        self.assertTrue(RequestLog.high_priority.filter(path="/"))
Example #2
0
    def test_detect_priority(self):
        self.assertEqual(self.log1.priority, 0)
        rule1 = PriorityRule(path=self.log1.path, method=self.log1.method, priority=PriorityRule.PRIOR_HIGH)
        rule1.save()

        self.assertEqual(self.log1.detect_priority(), rule1.priority)
        self.assertEqual(self.log1.priority, PriorityRule.PRIOR_HIGH)
Example #3
0
    def test_apply_to_existed(self):
        rule1 = PriorityRule(path="/test/2/", method="GET", priority=PriorityRule.PRIOR_HIGH)
        rule1.save()

        rule1.apply_to_existed()
        self.assertEqual(list(RequestLog.high_priority.all().order_by("id")), [self.log2, self.log3])

        rule2 = PriorityRule(path="/test/2/", method="POST", priority=PriorityRule.PRIOR_HIGH)
        rule2.save()
        rule2.apply_to_existed()
        self.assertEqual(list(RequestLog.high_priority.all().order_by("id")), [self.log2, self.log3, self.log4])
Example #4
0
    def test_requests_page(self):
        resp = self.client.get(reverse("requests"))
        self.assertEqual(resp.status_code, 200)

        rule1 = PriorityRule(method="GET", priority=PriorityRule.PRIOR_HIGH)
        rule1.save()
        rule1.apply_to_existed()

        # Show only high priority

        resp = self.client.get(reverse("requests") + "?priority=1")
        self.assertEqual(resp.status_code, 200)

        real = sorted(resp.context["requests"].values_list("id", flat=True))
        expected = sorted(RequestLog.high_priority.all()[:10].values_list("id", flat=True))

        self.assertEqual(real, expected)

        # Show only default priority

        resp = self.client.get(reverse("requests") + "?priority=0")
        self.assertEqual(resp.status_code, 200)

        real = sorted(resp.context["requests"].values_list("id", flat=True))
        expected = sorted(RequestLog.default_priority.all()[:10].values_list("id", flat=True))

        self.assertEqual(real, expected)

        # Show all priority
        resp = self.client.get(reverse("requests") + "?priority=")
        self.assertEqual(resp.status_code, 200)

        real = sorted(resp.context["requests"].values_list("id", flat=True))
        expected = sorted(RequestLog.objects.all()[:10].values_list("id", flat=True))

        self.assertEqual(real, expected)
Example #5
0
 def test_prior_all_post(self):
     rule1 = PriorityRule(method="POST", priority=PriorityRule.PRIOR_HIGH)
     rule1.save()
     rule1.apply_to_existed()
     self.assertEqual(list(RequestLog.high_priority.all().order_by("id")), [self.log4, self.log5])