0

Risking this question to be too generic...

What would be the advised use case types to test in a regular implementation of a REST API using the djangorestframework plugin?

2
  • 2
    This is basically a question about best practice, which is off topic for stack overflow. It's a matter of opinion. For integration tests, the minimum are smoke tests that make sure every endpoint returns a valid http response without error. Unit tests are less important IMO, since the basic units come from the framework, and that code has solid test coverage already. Commented Jul 9, 2018 at 10:36
  • Yup, that was the grey line I was hoping to avoid: suggestions vs opinion discussion. In any case, replies like yours are what I was hoping for. Thanks @Håken Lid Commented Jul 9, 2018 at 10:39

1 Answer 1

2

I don't know that I understand your question very well,

Code without tests is broken as designed.

So each part of an application need test. you should test the functionality of each API with unit-test, and fortunately, Django rest framework has tools for this action

http://www.django-rest-framework.org/api-guide/testing/

from django.urls import include, path, reverse
from rest_framework.test import APITestCase, URLPatternsTestCase


class AccountTests(APITestCase, URLPatternsTestCase):
    urlpatterns = [
        path('api/', include('api.urls')),
    ]

    def test_create_account(self):
        """
        Ensure we can create a new account object.
        """
        url = reverse('account-list')
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1)
Sign up to request clarification or add additional context in comments.

1 Comment

That seems like a hell of a good place to start, thanks. Quite frankly, it was a logical mindset I was looking for, so I apologise for the vagueness of the question. Thanks again @Mohammad Efazati

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.