Skip to content

Instantly share code, notes, and snippets.

@alvarocavalcanti
Last active August 15, 2019 10:23
Show Gist options
  • Save alvarocavalcanti/a3fc1cdd4be9163323bf647e28fe2aea to your computer and use it in GitHub Desktop.
Save alvarocavalcanti/a3fc1cdd4be9163323bf647e28fe2aea to your computer and use it in GitHub Desktop.
Files from TDD + Mob Programming Exercise

wpe-tdd-mob-programming

Overview

This is the scope of this exercise:

  • Create an endpoint GET /v1/howmanybooks/author+name that will return a phrase stating how many books the specified author has
  • The Open Library Search API should be used

TDD Resources

Pairing Resources

DAMP vs DRY

Anemic REST

import json
from rest_framework import status
from rest_framework.test import APITestCase
class TestNumberOfBooksByAuthorEndpoint(APITestCase):
BASE_URL = '/v1/numberofbooksbyauthor'
def test_returns_200_for_known_author(self):
response = self.client.get(f'{self.BASE_URL}/neil+gaiman')
self.assertEqual(status.HTTP_200_OK, response.status_code)
def test_returns_zero_for_unknown_author(self):
response = self.client.get(f'{self.BASE_URL}/alvaro+cavalcanti')
self.assertEqual(0, response.status_code)
def test_returns_proper_number_of_books_for_known_author(self):
response = self.client.get(f'{self.BASE_URL}/neil+gaiman')
response_data = json.loads(response.content)
self.assertEqual(384, response_data['num_found'])
from django.conf.urls import url
from apps.wpe_tdd_mob_programming.views import StatusView, numberofbooksbyauthor
urlpatterns = [
url(r'^v1/numberofbooksbyauthor/(?P<author_name>.+)/?$', numberofbooksbyauthor),
]
@api_view(['GET'])
@permission_classes((IsAuthenticatedOrReadOnly,))
@parser_classes((JSONParser,))
def numberofbooksbyauthor(request, author_name):
return JsonResponse({'num_found': 384})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment