Answer the question
In order to leave comments, you need to log in
What else to add to the unit test for the sort function?
Hello! Please help me figure it out.
The page displays a list of article titles. The user can drag and drop them and sort them as they wish. Used jQuery UI. This behavior is implemented by this view (see below).
The question is the following. Could someone help to make a unit test for this view. I had little to do with unit testing. At the moment, I only checked the status_code. It would be interesting to know your opinions. I will be grateful for any help!
views.py:
from braces.views import CsrfExemptMixin, JsonRequestResponseMixin
class ArticleSortingView(CsrfExemptMixin, JsonRequestResponseMixin, FormView):
def post(self, request, *args, **kwargs):
for pk, idx in self.request_json.items():
Slide.objects.filter(pk=pk).update(idx=idx)
return self.render_json_response({'saved': 'OK'})
class ArticleViewTestCase(TestCase):
def setUp(self):
self.client = Client()
self.credentials = {'username': 'user', 'password': 'password'}
self.user = User.objects.create_user(**self.credentials)
def test_sorting_article(self):
self.assertTrue(self.user)
logged_in = self.client.login(**self.credentials)
self.assertTrue(logged_in)
response = self.client.post(reverse("article:article_sorting"), follow=True)
self.assertEqual(response.status_code, 200)
Answer the question
In order to leave comments, you need to log in
setUp
create multiple Slide objectsself.client.post(reverse("article:article_sorting"), follow=True)
json, which will change the sorting of these objectsDidn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question