def test_url(self, reverse): view = views.UrlMixin() returned_url = view.get_url(url='my_url') self.assertFalse(reverse.called, "reverse should not be called") self.assertEqual(returned_url, 'my_url')
def test_without_attribute_with_object_without_pk(self): view = views.UrlMixin() view.object = MagicMock() del view.object.pk returned_args = view.get_url_name_args() self.assertEqual(returned_args, [], "An empty list should be returned")
def test_priority_of_url_name(self, reverse): view = views.UrlMixin() reverse.return_value = 'reverse_url' returned_url = view.get_url(url_name='test_url_name', url='my_url') reverse.assert_called_once_with('test_url_name', args=[]) self.assertEqual(returned_url, 'reverse_url')
def test_without_attribute_with_object_with_pk(self): view = views.UrlMixin() view.object = MagicMock() view.object.pk = 5 returned_args = view.get_url_name_args() self.assertEqual(returned_args, [5], "object.pk should be returned as a one element list")
def test_has_attribute(self): view = views.UrlMixin() view.url_name_args = 'name_args' returned_args = view.get_url_name_args() self.assertEqual( returned_args, 'name_args', "The object attribute 'url_name_args' should be returned")
def test_get_absolute_url_with_invalid_object(self, reverse): view = views.UrlMixin() view.object = MagicMock() del view.object.get_absolute_url with self.assertRaisesRegex( ImproperlyConfigured, 'No url to redirect to\. See openslides\.utils\.views\.UrlMixin ' 'for more details\.'): view.get_url()
def test_get_absolute_url_with_link(self, reverse): view = views.UrlMixin() view.object = MagicMock() view.object.get_absolute_url.return_value = 'object_url' returned_url = view.get_url(use_absolute_url_link='test_link') view.object.get_absolute_url.assert_called_once_with('test_link') self.assertEqual(returned_url, 'object_url') self.assertFalse(reverse.called, "reverse should not be called")
def test_url_name_with_args(self, reverse): """ Tests that the return value of reverse(url_pattern) with args is returned. """ view = views.UrlMixin() reverse.return_value = 'reverse_url' returned_url = view.get_url('test_url_name', args=[1, 2, 3]) reverse.assert_called_once_with('test_url_name', args=[1, 2, 3]) self.assertEqual(returned_url, 'reverse_url')
def test_without_attribute_without_object(self): view = views.UrlMixin() returned_args = view.get_url_name_args() self.assertEqual(returned_args, [], "An empty list should be returned")