Beispiel #1
0
    def test_post_not_allowed(self):
        client = APIClient()

        response = client.post(reverse('astrobin_apps_equipment:camera-list'),
                               {
                                   'brand': EquipmentGenerators.brand().pk,
                                   'sensor': EquipmentGenerators.sensor().pk,
                                   'name': 'Camera Foo',
                                   'type': CameraType.DEDICATED_DEEP_SKY,
                               },
                               format='json')
        self.assertEquals(403, response.status_code)

        user = Generators.user()
        client.login(username=user.username, password=user.password)
        client.force_authenticate(user=user)

        response = client.post(reverse('astrobin_apps_equipment:camera-list'),
                               {
                                   'brand': EquipmentGenerators.brand().pk,
                                   'sensor': EquipmentGenerators.sensor().pk,
                                   'name': 'Camera Foo',
                                   'type': CameraType.DEDICATED_DEEP_SKY,
                               },
                               format='json')
        self.assertEquals(403, response.status_code)
Beispiel #2
0
    def test_list_returns_only_own_DIYs(self):
        user = Generators.user()
        first = EquipmentGenerators.sensor(created_by=user)
        first.brand = None
        first.save()

        second = EquipmentGenerators.sensor()
        second.brand = None
        second.save()

        client = APIClient()
        client.force_authenticate(user=user)

        response = client.get(reverse('astrobin_apps_equipment:sensor-list'),
                              format='json')
        self.assertEquals(1, response.data['count'])
        self.assertEquals(first.name, response.data['results'][0]['name'])
    def test_list_with_items(self):
        client = APIClient()

        sensor = EquipmentGenerators.sensor()

        response = client.get(reverse('astrobin_apps_equipment:sensor-list'),
                              format='json')
        self.assertEquals(1, response.data['count'])
        self.assertEquals(sensor.name, response.data['results'][0]['name'])
Beispiel #4
0
    def test_created_by(self):
        client = APIClient()

        user = Generators.user(groups=['equipment_moderators'])
        client.login(username=user.username, password=user.password)
        client.force_authenticate(user=user)

        response = client.post(reverse('astrobin_apps_equipment:camera-list'), {
            'brand': EquipmentGenerators.brand().pk,
            'sensor': EquipmentGenerators.sensor().pk,
            'name': 'Camera Foo',
            'type': CameraType.DEDICATED_DEEP_SKY,
        }, format='json')
        self.assertEquals(201, response.status_code)
        self.assertEquals(user.pk, response.data['created_by'])
    def test_not_allowed_for_modified_camera(self):
        user = Generators.user(groups=['equipment_moderators'])
        client = APIClient()
        client.force_authenticate(user=user)

        camera = EquipmentGenerators.camera(modified=True)

        response = client.post(reverse('astrobin_apps_equipment:camera-edit-proposal-list'), {
            'editProposalTarget': camera.pk,
            'brand': EquipmentGenerators.brand().pk,
            'sensor': EquipmentGenerators.sensor().pk,
            'name': 'Camera Foo',
            'type': CameraType.DEDICATED_DEEP_SKY,
        }, format='json')

        self.assertContains(response, "Modified cameras do not support edit proposals", status_code=400)
    def test_deleting_not_allowed(self):
        client = APIClient()

        sensor = EquipmentGenerators.sensor()

        response = client.delete(reverse(
            'astrobin_apps_equipment:sensor-detail', args=(sensor.pk, )),
                                 format='json')
        self.assertEquals(405, response.status_code)

        user = Generators.user(groups=['equipment_moderators'])
        client.login(username=user.username, password=user.password)
        client.force_authenticate(user=user)

        response = client.delete(reverse(
            'astrobin_apps_equipment:sensor-detail', args=(sensor.pk, )),
                                 format='json')
        self.assertEquals(405, response.status_code)