Ejemplo n.º 1
0
    def test_list_with_items(self):
        client = APIClient()

        camera = EquipmentGenerators.camera()

        response = client.get(reverse('astrobin_apps_equipment:camera-list'), format='json')
        self.assertEquals(1, response.data['count'])
        self.assertEquals(camera.name, response.data['results'][0]['name'])
Ejemplo n.º 2
0
    def test_list_returns_only_own_DIYs(self):
        user = Generators.user()
        first = EquipmentGenerators.camera(created_by=user)
        first.brand = None
        first.save()

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

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

        response = client.get(reverse('astrobin_apps_equipment:camera-list'),
                              format='json')
        self.assertEquals(1, response.data['count'])
        self.assertEquals(first.name, response.data['results'][0]['name'])
Ejemplo n.º 3
0
    def test_mirror_modified_camera(self):
        camera = EquipmentGenerators.camera()
        modified = EquipmentGenerators.camera(
            created_by=camera.created_by,
            brand=camera.brand,
            name=camera.name,
            image=camera.image,
            type=camera.type,
            sensor=camera.sensor,
            cooled=camera.cooled,
            max_cooling=camera.max_cooling,
            back_focus=camera.back_focus,
            modified=True,
        )

        camera.name = camera.name + ' updated'
        camera.save()

        modified = Camera.objects.get(pk=modified.pk)

        self.assertEqual(camera.name, modified.name)
Ejemplo n.º 4
0
    def test_deleting_not_allowed(self):
        client = APIClient()

        camera = EquipmentGenerators.camera()

        response = client.delete(reverse('astrobin_apps_equipment:camera-detail', args=(camera.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:camera-detail', args=(camera.pk,)), format='json')
        self.assertEquals(405, response.status_code)
Ejemplo n.º 5
0
    def test_find_recently_used_wrong_usage_type(self):
        user = Generators.user()
        camera = EquipmentGenerators.camera(created_by=user)
        image = Generators.image(user=user)
        image.imaging_cameras_2.add(camera)

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

        response = client.get(reverse('astrobin_apps_equipment:camera-list') +
                              'recently-used/?usage-type=guiding',
                              format='json')

        self.assertEquals(0, len(response.data))
    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)
Ejemplo n.º 7
0
    def test_get_equipment_list_when_mix(self):
        image = Generators.image()

        image.imaging_telescopes.add(
            Generators.telescope(make='My make', name='My imaging telescope'))
        image.imaging_cameras.add(
            Generators.camera(make='My make', name='My imaging camera'))
        image.mounts.add(Generators.mount(make='My make', name='My mount'))
        image.filters.add(Generators.filter(make='My make', name='My filter'))
        image.accessories.add(
            Generators.accessory(make='My make', name='My accessory'))
        image.focal_reducers.add(
            Generators.focal_reducer(make='My make', name='My focal reducer'))
        image.software.add(
            Generators.software(make='My make', name='My software'))
        image.guiding_telescopes.add(
            Generators.telescope(make='My make', name='My guiding telescope'))
        image.guiding_cameras.add(
            Generators.camera(make='My make', name='My guiding camera'))

        brand = EquipmentGenerators.brand(name='My brand')

        image.imaging_telescopes_2.add(
            EquipmentGenerators.telescope(brand=brand,
                                          name='My new imaging telescope'))
        image.imaging_cameras_2.add(
            EquipmentGenerators.camera(brand=brand,
                                       name='My new imaging camera'))
        image.mounts_2.add(
            EquipmentGenerators.mount(brand=brand, name='My new mount'))
        image.filters_2.add(
            EquipmentGenerators.filter(brand=brand, name='My new filter'))
        image.accessories_2.add(
            EquipmentGenerators.accessory(brand=brand,
                                          name='My new accessory'))
        image.software_2.add(
            EquipmentGenerators.software(brand=brand, name='My new software'))
        image.guiding_telescopes_2.add(
            EquipmentGenerators.telescope(brand=brand,
                                          name='My new guiding telescope'))
        image.guiding_cameras_2.add(
            EquipmentGenerators.camera(brand=brand,
                                       name='My new guiding camera'))

        equipment_list = ImageService(image).get_equipment_list()

        self.assertEqual(2, len(equipment_list['imaging_telescopes']))
        self.assertEqual(2, len(equipment_list['imaging_cameras']))
        self.assertEqual(2, len(equipment_list['mounts']))
        self.assertEqual(2, len(equipment_list['filters']))
        self.assertEqual(3, len(equipment_list['accessories']))
        self.assertEqual(2, len(equipment_list['software']))
        self.assertEqual(2, len(equipment_list['guiding_telescopes']))
        self.assertEqual(2, len(equipment_list['guiding_cameras']))

        self.assertTrue('id' in equipment_list['imaging_telescopes'][0])
        self.assertEqual('My brand My new imaging telescope',
                         equipment_list['imaging_telescopes'][0]['label'])
        self.assertEqual('NEW',
                         equipment_list['imaging_telescopes'][0]['version'])

        self.assertTrue('id' in equipment_list['imaging_cameras'][0])
        self.assertEqual('My brand My new imaging camera',
                         equipment_list['imaging_cameras'][0]['label'])
        self.assertEqual('NEW',
                         equipment_list['imaging_cameras'][0]['version'])

        self.assertTrue('id' in equipment_list['mounts'][0])
        self.assertEqual('My brand My new mount',
                         equipment_list['mounts'][0]['label'])
        self.assertEqual('NEW', equipment_list['mounts'][0]['version'])

        self.assertTrue('id' in equipment_list['filters'][0])
        self.assertEqual('My brand My new filter',
                         equipment_list['filters'][0]['label'])
        self.assertEqual('NEW', equipment_list['filters'][0]['version'])

        self.assertTrue('id' in equipment_list['accessories'][0])
        self.assertEqual('My brand My new accessory',
                         equipment_list['accessories'][0]['label'])
        self.assertEqual('NEW', equipment_list['accessories'][0]['version'])

        self.assertTrue('id' in equipment_list['software'][0])
        self.assertEqual('My brand My new software',
                         equipment_list['software'][0]['label'])
        self.assertEqual('NEW', equipment_list['software'][0]['version'])

        self.assertTrue('id' in equipment_list['guiding_telescopes'][0])
        self.assertEqual('My brand My new guiding telescope',
                         equipment_list['guiding_telescopes'][0]['label'])
        self.assertEqual('NEW',
                         equipment_list['guiding_telescopes'][0]['version'])

        self.assertTrue('id' in equipment_list['guiding_cameras'][0])
        self.assertEqual('My brand My new guiding camera',
                         equipment_list['guiding_cameras'][0]['label'])
        self.assertEqual('NEW',
                         equipment_list['guiding_cameras'][0]['version'])

        self.assertTrue('id' in equipment_list['imaging_telescopes'][1])
        self.assertEqual('My make My imaging telescope',
                         equipment_list['imaging_telescopes'][1]['label'])
        self.assertEqual('LEGACY',
                         equipment_list['imaging_telescopes'][1]['version'])

        self.assertTrue('id' in equipment_list['imaging_cameras'][1])
        self.assertEqual('My make My imaging camera',
                         equipment_list['imaging_cameras'][1]['label'])
        self.assertEqual('LEGACY',
                         equipment_list['imaging_cameras'][1]['version'])

        self.assertTrue('id' in equipment_list['mounts'][1])
        self.assertEqual('My make My mount',
                         equipment_list['mounts'][1]['label'])
        self.assertEqual('LEGACY', equipment_list['mounts'][1]['version'])

        self.assertTrue('id' in equipment_list['filters'][1])
        self.assertEqual('My make My filter',
                         equipment_list['filters'][1]['label'])
        self.assertEqual('LEGACY', equipment_list['filters'][1]['version'])

        self.assertTrue('id' in equipment_list['accessories'][1])
        self.assertEqual('My make My accessory',
                         equipment_list['accessories'][1]['label'])
        self.assertEqual('LEGACY', equipment_list['accessories'][1]['version'])

        self.assertTrue('id' in equipment_list['accessories'][2])
        self.assertEqual('My make My focal reducer',
                         equipment_list['accessories'][2]['label'])
        self.assertEqual('LEGACY', equipment_list['accessories'][2]['version'])

        self.assertTrue('id' in equipment_list['software'][1])
        self.assertEqual('My make My software',
                         equipment_list['software'][1]['label'])
        self.assertEqual('LEGACY', equipment_list['software'][1]['version'])

        self.assertTrue('id' in equipment_list['guiding_telescopes'][1])
        self.assertEqual('My make My guiding telescope',
                         equipment_list['guiding_telescopes'][1]['label'])
        self.assertEqual('LEGACY',
                         equipment_list['guiding_telescopes'][1]['version'])

        self.assertTrue('id' in equipment_list['guiding_cameras'][1])
        self.assertEqual('My make My guiding camera',
                         equipment_list['guiding_cameras'][1]['label'])
        self.assertEqual('LEGACY',
                         equipment_list['guiding_cameras'][1]['version'])
Ejemplo n.º 8
0
    def test_get_equipment_list_when_only_new_equipment(self):
        image = Generators.image()

        brand = EquipmentGenerators.brand(name='My brand')

        image.imaging_telescopes_2.add(
            EquipmentGenerators.telescope(brand=brand,
                                          name='My new imaging telescope'))
        image.imaging_cameras_2.add(
            EquipmentGenerators.camera(brand=brand,
                                       name='My new imaging camera'))
        image.mounts_2.add(
            EquipmentGenerators.mount(brand=brand, name='My new mount'))
        image.filters_2.add(
            EquipmentGenerators.filter(brand=brand, name='My new filter'))
        image.accessories_2.add(
            EquipmentGenerators.accessory(brand=brand,
                                          name='My new accessory'))
        image.software_2.add(
            EquipmentGenerators.software(brand=brand, name='My new software'))
        image.guiding_telescopes_2.add(
            EquipmentGenerators.telescope(brand=brand,
                                          name='My new guiding telescope'))
        image.guiding_cameras_2.add(
            EquipmentGenerators.camera(brand=brand,
                                       name='My new guiding camera'))

        equipment_list = ImageService(image).get_equipment_list()

        self.assertEqual(1, len(equipment_list['imaging_telescopes']))
        self.assertEqual(1, len(equipment_list['imaging_cameras']))
        self.assertEqual(1, len(equipment_list['mounts']))
        self.assertEqual(1, len(equipment_list['filters']))
        self.assertEqual(1, len(equipment_list['accessories']))
        self.assertEqual(1, len(equipment_list['software']))
        self.assertEqual(1, len(equipment_list['guiding_telescopes']))
        self.assertEqual(1, len(equipment_list['guiding_cameras']))

        self.assertTrue('id' in equipment_list['imaging_telescopes'][0])
        self.assertEqual('My brand My new imaging telescope',
                         equipment_list['imaging_telescopes'][0]['label'])
        self.assertEqual('NEW',
                         equipment_list['imaging_telescopes'][0]['version'])

        self.assertTrue('id' in equipment_list['imaging_cameras'][0])
        self.assertEqual('My brand My new imaging camera',
                         equipment_list['imaging_cameras'][0]['label'])
        self.assertEqual('NEW',
                         equipment_list['imaging_cameras'][0]['version'])

        self.assertTrue('id' in equipment_list['mounts'][0])
        self.assertEqual('My brand My new mount',
                         equipment_list['mounts'][0]['label'])
        self.assertEqual('NEW', equipment_list['mounts'][0]['version'])

        self.assertTrue('id' in equipment_list['filters'][0])
        self.assertEqual('My brand My new filter',
                         equipment_list['filters'][0]['label'])
        self.assertEqual('NEW', equipment_list['filters'][0]['version'])

        self.assertTrue('id' in equipment_list['accessories'][0])
        self.assertEqual('My brand My new accessory',
                         equipment_list['accessories'][0]['label'])
        self.assertEqual('NEW', equipment_list['accessories'][0]['version'])

        self.assertTrue('id' in equipment_list['software'][0])
        self.assertEqual('My brand My new software',
                         equipment_list['software'][0]['label'])
        self.assertEqual('NEW', equipment_list['software'][0]['version'])

        self.assertTrue('id' in equipment_list['guiding_telescopes'][0])
        self.assertEqual('My brand My new guiding telescope',
                         equipment_list['guiding_telescopes'][0]['label'])
        self.assertEqual('NEW',
                         equipment_list['guiding_telescopes'][0]['version'])

        self.assertTrue('id' in equipment_list['guiding_cameras'][0])
        self.assertEqual('My brand My new guiding camera',
                         equipment_list['guiding_cameras'][0]['label'])
        self.assertEqual('NEW',
                         equipment_list['guiding_cameras'][0]['version'])