Esempio n. 1
0
    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'])
Esempio n. 2
0
    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)
Esempio n. 3
0
    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'])
Esempio n. 4
0
    def test_minimal_post(self):
        device = DeviceFactory.build()
        device_count_before = Device.objects.all().count()

        url = reverse('device-list')
        response = self.client.post(url,
                                    data={
                                        "reference": device.reference,
                                        "application": device.application,
                                        "types": []
                                    },
                                    format='json')

        self.assertEqual(status.HTTP_201_CREATED, response.status_code)
        self.assertEqual(device_count_before + 1, Device.objects.all().count())

        last_record_in_db = Device.objects.all().order_by('-id')[:1][0]
        self.assertEqual(last_record_in_db.reference, device.reference)
        self.assertEqual(last_record_in_db.application, device.application)
        self.assertEqual(last_record_in_db.types.count(), 0)
Esempio n. 5
0
 def setUp(self):
     self.device = DeviceFactory.create()