예제 #1
0
파일: test_api.py 프로젝트: koenw/iot-api
    def test_list_pagination(self):
        DeviceFactory.create_batch(9)

        t = TypeFactory.create()
        DeviceFactory.create(types=[
            t,
        ])

        url = '{}?page_size=5'.format(reverse('device-list'))
        response = self.client.get(url)

        self.assertEqual(status.HTTP_200_OK, response.status_code,
                         'Wrong response code for {}'.format(url))

        data = response.json()

        self.assertEqual(10, data['count'])
        self.assertEqual(5, len(data['results']))

        self.assertIsNotNone(data['_links']['next']['href'])
        self.assertIsNone(data['_links']['previous']['href'])

        response = self.client.get(data['_links']['next']['href'])

        self.assertEqual(status.HTTP_200_OK, response.status_code,
                         'Wrong response code for {}'.format(url))

        data = response.json()

        self.assertEqual(10, data['count'])
        self.assertEqual(5, len(data['results']))

        self.assertIsNone(data['_links']['next']['href'])
        self.assertIsNotNone(data['_links']['previous']['href'])
예제 #2
0
파일: test_api.py 프로젝트: koenw/iot-api
    def test_delete(self):
        device = DeviceFactory.create()

        url = reverse('device-detail', kwargs={'pk': device.pk})
        response = self.client.delete(url)

        self.assertEqual(status.HTTP_405_METHOD_NOT_ALLOWED,
                         response.status_code)
예제 #3
0
파일: test_api.py 프로젝트: koenw/iot-api
    def test_detail(self):
        device = DeviceFactory.create()

        url = reverse('device-detail', kwargs={'pk': device.pk})
        response = self.client.get(url)

        self.assertEqual(status.HTTP_200_OK, response.status_code,
                         'Wrong response code for {}'.format(url))

        data = response.json()

        self.assertEqual(device.reference, data['reference'])
        self.assertEqual(device.application, data['application'])
        self.assertEqual(len(device.categories.split(',')),
                         len(data['categories']))
        self.assertAlmostEqual(float(device.geometrie.x),
                               float(data['longitude']))
        self.assertAlmostEqual(float(device.geometrie.y),
                               float(data['latitude']))
        self.assertEqual(device.owner.organisation, data['organisation'])
예제 #4
0
 def setUp(self):
     self.device = DeviceFactory.create()