Exemplo n.º 1
0
    def test_get_url_no_map(self):
        field = NestedRelatedField(view_name="test_view")
        field.parent = FakeSerializer()

        url = field.get_url(FakeModel(1), "test_view", None, None)

        self.assertEqual(url, "/1/")
Exemplo n.º 2
0
    def test_get_url_with_map_fail(self):
        from django.core.urlresolvers import NoReverseMatch

        field = NestedRelatedField(view_name="test_nested_view", map={
            "invalid": "match",
        })
        field.parent = FakeSerializer()

        with self.assertRaises(NoReverseMatch):
            url = field.get_url(FakeModel(1), "test_nested_view", None, None)
Exemplo n.º 3
0
    def test_get_url_with_map_match(self):
        field = NestedRelatedField(view_name="test_nested_view", map={
            "something": "pk",
        })
        field.parent = FakeSerializer()
        field.parent.context["view"].kwargs["pk"] = "123"

        url = field.get_url(FakeModel(1), "test_nested_view", None, None)

        self.assertEqual(url, "/123/1/")