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/")
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)
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/")