コード例 #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()