Exemplo n.º 1
0
 def test_insert(self):
     yearName = 'First Year'
     old_count = Year.objects.all().count()
     year = Year(yearName=yearName)
     year.save()
     new_count = Year.objects.all().count()
     self.assertNotEqual(old_count, new_count)
Exemplo n.º 2
0
 def test_get(self):
     yearName = 'First Year'
     year = Year(yearName=yearName)
     year.save()
     response = self.client.get('/year/')
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_200_OK)
Exemplo n.º 3
0
 def test_get_by_id(self):
     yearName = 'First Year'
     year = Year(yearName=yearName)
     year.save()
     data = Year.objects.get(yearName=yearName)
     response = self.client.get('/year/%s/' % data.yearId)
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_200_OK)
Exemplo n.º 4
0
 def test_delete(self):
     Year.objects.all().delete()
     year = Year(yearName='First Year')
     year.save()
     saved_data = Year.objects.get(yearName='First Year')
     response = self.client.delete('/year/%s/' % saved_data.yearId)
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_202_ACCEPTED)
Exemplo n.º 5
0
 def test_post_exists(self):
     Year.objects.all().delete()
     yearName = "First Year"
     year = Year(yearName=yearName)
     year.save()
     data = {"yearName": "First Year"}
     response = self.client.post('/year/', data)
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_409_CONFLICT)
Exemplo n.º 6
0
 def test_delete_not_found(self):
     Year.objects.all().delete()
     year = Year(yearName='First Year')
     year.save()
     saved_data = Year.objects.get(yearName='First Year')
     id = int(saved_data.yearId) + 1
     response = self.client.delete('/year/%s/' % id)
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_404_NOT_FOUND)
Exemplo n.º 7
0
 def test_put(self):
     Year.objects.all().delete()
     yearName = "First Year"
     year = Year(yearName=yearName)
     year.save()
     saved_data = Year.objects.get(yearName='First Year')
     data = {"subjectName": "Second Year"}
     response = self.client.put('/year/%s/' % saved_data.yearId, data)
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_201_CREATED)
Exemplo n.º 8
0
 def test_put_not_found(self):
     Year.objects.all().delete()
     yearName = 'First Year'
     year = Year(yearName=yearName)
     year.save()
     data = Year.objects.get(yearName='First Year')
     id = int(data.yearId) + 1
     data = {"yearName": "Second Year"}
     response = self.client.put('/year/%s/' % id)
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_404_NOT_FOUND)
Exemplo n.º 9
0
 def test_put_coflict(self):
     Year.objects.all().delete()
     yearName = "First Year"
     year = Year(yearName=yearName)
     year.save()
     yearName = "Second Year"
     year = Year(yearName=yearName)
     year.save()
     saved_data = Year.objects.get(yearName='Second Year')
     data = {"yearName": "First Year"}
     response = self.client.put('/year/%s/' % saved_data.yearId,
                                data,
                                fomat='json')
     self.assertEqual(
         json.loads(response.content)['Status'], status.HTTP_409_CONFLICT)