Exemple #1
0
    def test_get_url(self):
        field = MultiplePKsHyperlinkedIdentityField(
            'foo',
            lookup_fields=['one', 'two'],
            lookup_url_kwargs=['foo', 'bar'],
        )
        mock_reverse = field.reverse = mock.MagicMock()

        actual = field.get_url(
            mock.Mock(pk=1, one='value', two='here'),
            mock.sentinel.view_name,
            mock.sentinel.request,
            mock.sentinel.format,
        )

        assert actual == mock_reverse.return_value
        mock_reverse.assert_called_once_with(
            mock.sentinel.view_name,
            kwargs={'foo': 'value', 'bar': 'here'},
            request=mock.sentinel.request,
            format=mock.sentinel.format,
        )
Exemple #2
0
    def test_get_url_no_obj_pk(self):
        field = MultiplePKsHyperlinkedIdentityField('foo')

        assert field.get_url(mock.Mock(pk=None), None, None, None) is None