Advertisement
szabozoltan69

Test api call

Jul 4th, 2018
181
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import json
  2. from django.test import TestCase
  3. from rest_framework.test import APITestCase
  4. from django.contrib.auth.models import User
  5. import api.models as models
  6. import api.drf_views as views
  7.  
  8. ...
  9.  
  10. class SituationReportTypeTest(APITestCase):
  11.  
  12.     fixtures = ['DisasterTypes']
  13.  
  14.     def setUp(self):
  15.         type1 = models.DocumentType.objects.create(type='Strange')
  16.         type2 = models.DocumentType.objects.create(type='Lyric')
  17.         type3 = models.DocumentType.objects.create(type='Epic')
  18.         dtype1 = models.DisasterType.objects.get(pk=1)
  19.         dtype2 = models.DisasterType.objects.get(pk=2)
  20.         dtype3 = models.DisasterType.objects.get(pk=4)
  21.         event1 = models.Event.objects.create(name='disaster1', summary='test disaster1', dtype=dtype1)
  22.         event2 = models.Event.objects.create(name='disaster2', summary='test disaster2', dtype=dtype2)
  23.         event3 = models.Event.objects.create(name='disaster3', summary='test disaster3', dtype=dtype3)
  24.         report1 = models.SituationReport.objects.create(name='test1', event=event1, type=type1)
  25.         report2 = models.SituationReport.objects.create(name='test2', event=event2, type=type2)
  26.         report3 = models.SituationReport.objects.create(name='test3', event=event3, type=type3)
  27.  
  28.     def test_sit_rep_types(self):
  29.         type1 = models.DocumentType.objects.get(type='Strange')
  30.         type2 = models.DocumentType.objects.get(type='Lyric')
  31.         type3 = models.DocumentType.objects.get(type='Epic')
  32.         report1 = models.SituationReport.objects.get(name='test1')
  33.         report2 = models.SituationReport.objects.get(name='test2')
  34.         report3 = models.SituationReport.objects.get(name='test3')
  35.         self.assertIsNotNone(type1)
  36.         self.assertIsNotNone(type2)
  37.         self.assertIsNotNone(type3)
  38.         self.assertIsNotNone(report1)
  39.         self.assertIsNotNone(report2)
  40.         self.assertIsNotNone(report3)
  41.         print(report3)
  42.         body = {
  43.             'limit': 100,
  44.             'event': 2,
  45.         }
  46.         headers = {'CONTENT_TYPE': 'application/json'}
  47. #        response = self.client.post('/api/v2/situation_report', body, format='json', headers=headers)
  48.         response = self.client.get('/api/v2/situation_report/?limit=100&event=1')
  49.         print(response.content)
  50.         # response.content:
  51.         self.assertEqual(response.status_code, 200)
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement