Skip to content

Commit

Permalink
test view and view done
Browse files Browse the repository at this point in the history
  • Loading branch information
ameek committed Aug 2, 2018
1 parent 5a02f82 commit 235cdc1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
19 changes: 19 additions & 0 deletions medicine_reminder/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
# Create your tests here.
from .models import Bucketlist

from rest_framework.test import APIClient
from rest_framework import status
form django.core.urlresolvers import reverse


class ModelTestCase(TestCase):
"""This class defines the test suite for the bucketlist model."""

Expand All @@ -17,3 +22,17 @@ def test_model_can_create_a_bucketlist(self):
self.bucketlist.save()
new_count = Bucketlist.objects.count()
self.assertNotEqual(old_count, new_count)

class ViewTestCase(TestCase):
def setUp(self):
"define the tet client and other test variables"
self.client = APIClient()
self.bucketlist_data = {'name': "Go to Ibiza"}
self.response = self.client.post(
reverse('create'),
self.bucketlist_data
format="Json"
)
def test_api_can_create_a_bucketlist(self):
"""Test the api has bucket creation capability."""
self.assertEqual(self.response.status_code, status.HTTP_201_CREATED)
12 changes: 11 additions & 1 deletion medicine_reminder/api/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
from django.shortcuts import render
#from django.shortcuts import render

from rest_framework import generics
from .serializers import BucketlistSerializer
from .models import Bucketlist

# Create your views here.
Class CreateView(generics.ListCreateAPIView):
queryset = Bucketlist.objects.all()
serializer_class = BucketlistSerializer

def perform_create(self, serializers):
serializer.save()

0 comments on commit 235cdc1

Please sign in to comment.