def test_ordering_boolean_field_desc(self):
        ExampleModelOneFactory.create(boolean_field=True)
        ExampleModelOneFactory.create(boolean_field=False)
        ExampleModelOneFactory.create(boolean_field=True)
        ExampleModelOneFactory.create(boolean_field=False)
        ExampleModelOneFactory.create(boolean_field=True)

        response = self.client.get(self.url, {"_order": "-boolean_field"})

        self.assertEqual(response.data["results"][4]["boolean_field"], False)
        self.assertEqual(response.data["results"][3]["boolean_field"], False)
        self.assertEqual(response.data["results"][2]["boolean_field"], True)
        self.assertEqual(response.data["results"][1]["boolean_field"], True)
        self.assertEqual(response.data["results"][0]["boolean_field"], True)
    def test_ordering_integer_field_desc(self):
        ExampleModelOneFactory.create(integer_field=4)
        ExampleModelOneFactory.create(integer_field=5)
        ExampleModelOneFactory.create(integer_field=3)
        ExampleModelOneFactory.create(integer_field=1)
        ExampleModelOneFactory.create(integer_field=2)

        response = self.client.get(self.url, {"_order": "-integer_field"})

        self.assertEqual(response.data["total_result_count"], 5)
        self.assertEqual(response.data["results"][0]["integer_field"], 5)
        self.assertEqual(response.data["results"][1]["integer_field"], 4)
        self.assertEqual(response.data["results"][2]["integer_field"], 3)
        self.assertEqual(response.data["results"][3]["integer_field"], 2)
        self.assertEqual(response.data["results"][4]["integer_field"], 1)
Ejemplo n.º 3
0
    def test_general_query(self):
        obj = ExampleModelOneFactory.create(char_field="foobar")

        response = self.client.get(self.url)

        self.assertEqual(response.data["results"][0]["_detail_url"],
                         obj.get_admin_detail_url())
    def test_ordering_decimal_field(self):
        ExampleModelOneFactory.create(decimal_field=Decimal("1.4"))
        ExampleModelOneFactory.create(decimal_field=Decimal("1.5"))
        ExampleModelOneFactory.create(decimal_field=Decimal("1.3"))
        ExampleModelOneFactory.create(decimal_field=Decimal("1.1"))
        ExampleModelOneFactory.create(decimal_field=Decimal("1.2"))

        response = self.client.get(self.url, {"_order": "decimal_field"})

        self.assertEqual(response.data["total_result_count"], 5)

        self.assertEqual(response.data["results"][0]["decimal_field"], "1.10")
        self.assertEqual(response.data["results"][1]["decimal_field"], "1.20")
        self.assertEqual(response.data["results"][2]["decimal_field"], "1.30")
        self.assertEqual(response.data["results"][3]["decimal_field"], "1.40")
        self.assertEqual(response.data["results"][4]["decimal_field"], "1.50")
    def test_ordering_float_field_desc(self):
        ExampleModelOneFactory.create(float_field=1.4)
        ExampleModelOneFactory.create(float_field=1.5)
        ExampleModelOneFactory.create(float_field=1.3)
        ExampleModelOneFactory.create(float_field=1.1)
        ExampleModelOneFactory.create(float_field=1.2)

        response = self.client.get(self.url, {"_order": "-float_field"})

        self.assertEqual(response.data["total_result_count"], 5)

        self.assertEqual(response.data["results"][4]["float_field"], 1.1)
        self.assertEqual(response.data["results"][3]["float_field"], 1.2)
        self.assertEqual(response.data["results"][2]["float_field"], 1.3)
        self.assertEqual(response.data["results"][1]["float_field"], 1.4)
        self.assertEqual(response.data["results"][0]["float_field"], 1.5)
    def test_general_query(self):
        ExampleModelOneFactory.create(char_field="foobar")
        ExampleModelOneFactory.create(text_field="dobeefoobee")
        ExampleModelOneFactory.create(slug_field="lafoot")
        ExampleModelOneFactory.create(text_field="")

        response = self.client.get(self.url, {"_q": "foo"})

        self.assertEqual(response.data["total_result_count"], 3)
    def test_ordering_slug_field(self):
        ExampleModelOneFactory.create(slug_field="echo")
        ExampleModelOneFactory.create(slug_field="delta")
        ExampleModelOneFactory.create(slug_field="alpha")
        ExampleModelOneFactory.create(slug_field="charlie")
        ExampleModelOneFactory.create(slug_field="foxtrot")
        ExampleModelOneFactory.create(slug_field="beta")

        response = self.client.get(self.url, {"_order": "-slug_field"})

        self.assertEqual(response.data["results"][5]["slug_field"], "alpha")
        self.assertEqual(response.data["results"][4]["slug_field"], "beta")
        self.assertEqual(response.data["results"][3]["slug_field"], "charlie")
        self.assertEqual(response.data["results"][2]["slug_field"], "delta")
        self.assertEqual(response.data["results"][1]["slug_field"], "echo")
        self.assertEqual(response.data["results"][0]["slug_field"], "foxtrot")