Ejemplo n.º 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)
Ejemplo n.º 2
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'])
Ejemplo n.º 3
0
    def test_listing_no_country(self):
        listing = EquipmentGenerators.equipment_item_listing()

        telescope = Generators.telescope()
        telescope.equipment_item_listings.add(listing)

        self.assertEquals(1, equipment_item_listings(telescope, 'us').count())
Ejemplo n.º 4
0
    def test_listing_country_is_none(self):
        listing = EquipmentGenerators.equipment_item_listing()

        telescope = Generators.telescope()
        telescope.equipment_item_listings.add(listing)

        self.assertEquals(0, equipment_item_listings(telescope, None).count())
Ejemplo n.º 5
0
    def test_list_returns_only_own_DIYs(self):
        user = Generators.user()
        first = EquipmentGenerators.accessory(created_by=user)
        first.brand = None
        first.save()

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

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

        response = client.get(reverse('astrobin_apps_equipment:accessory-list'), format='json')
        self.assertEquals(1, response.data['count'])
        self.assertEquals(first.name, response.data['results'][0]['name'])
    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_list_with_items(self):
        client = APIClient()

        telescope = EquipmentGenerators.telescope()

        response = client.get(reverse('astrobin_apps_equipment:telescope-list'), format='json')
        self.assertEquals(1, response.data['count'])
        self.assertEquals(telescope.name, response.data['results'][0]['name'])
    def test_with_gear_and_two_unique_listings_on_same_gear_in_right_country(self):
        listing1 = EquipmentGenerators.equipment_item_listing()
        listing1.retailer.countries = "us"
        listing1.retailer.save()

        listing2 = EquipmentGenerators.equipment_item_listing()
        listing2.retailer.countries = "us"
        listing2.retailer.save()

        telescope = Generators.telescope()
        telescope.equipment_item_listings.add(listing1)
        telescope.equipment_item_listings.add(listing2)

        image = Generators.image()
        image.imaging_telescopes.add(telescope)

        self.assertEquals(2, unique_equipment_item_listings(image, 'us').count())
Ejemplo n.º 9
0
    def test_list_with_items(self):
        client = APIClient()

        accessory = EquipmentGenerators.accessory()

        response = client.get(reverse('astrobin_apps_equipment:accessory-list'), format='json')
        self.assertEquals(1, response.data['count'])
        self.assertEquals(accessory.name, response.data['results'][0]['name'])
Ejemplo n.º 10
0
    def test_listing_correct_country(self):
        listing = EquipmentGenerators.equipment_item_listing()
        listing.retailer.countries = "us"
        listing.retailer.save()

        telescope = Generators.telescope()
        telescope.equipment_item_listings.add(listing)

        self.assertEquals(1, equipment_item_listings(telescope, 'us').count())
    def test_listing_in_wrong_country(self):
        listing = EquipmentGenerators.equipment_brand_listing()
        listing.retailer.countries = "it,ch,fi"
        listing.retailer.save()

        telescope = Generators.telescope()
        telescope.equipment_brand_listings.add(listing)

        self.assertEquals(0, equipment_brand_listings(telescope, 'us').count())
Ejemplo n.º 12
0
    def test_post_not_allowed(self):
        client = APIClient()

        response = client.post(reverse('astrobin_apps_equipment:accessory-list'), {
            'brand': EquipmentGenerators.brand().pk,
            'name': 'Accessory Foo',
        }, 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:accessory-list'), {
            'brand': EquipmentGenerators.brand().pk,
            'name': 'Accessory Foo',
        }, format='json')
        self.assertEquals(403, response.status_code)
    def setUp(self):
        self.image = Generators.image()

        telescope = Generators.telescope()
        equipment_brand_listing = EquipmentGenerators.equipment_brand_listing()
        telescope.equipment_brand_listings.add(equipment_brand_listing)

        self.image.user.userprofile.telescopes.add(telescope)
        self.image.imaging_telescopes.add(telescope)
    def test_with_gear_and_listing_in_no_country(self):
        listing = EquipmentGenerators.equipment_item_listing()

        telescope = Generators.telescope()
        telescope.equipment_item_listings.add(listing)

        image = Generators.image()
        image.imaging_telescopes.add(telescope)

        self.assertEquals(1, unique_equipment_item_listings(image, 'us').count())
Ejemplo n.º 15
0
    def setUp(self):
        self.image = Generators.image()
        Generators.premium_subscription(self.image.user, "AstroBin Lite")

        telescope = Generators.telescope()
        equipment_brand_listing = EquipmentGenerators.equipment_brand_listing()
        telescope.equipment_brand_listings.add(equipment_brand_listing)

        self.image.user.userprofile.telescopes.add(telescope)
        self.image.imaging_telescopes.add(telescope)
Ejemplo n.º 16
0
    def test_list_with_items(self):
        client = APIClient()

        group = EquipmentGenerators.equipment_item_group()

        telescope1 = EquipmentGenerators.telescope()
        telescope1.group = group
        telescope1.save()

        telescope2 = EquipmentGenerators.telescope()
        telescope2.group = group
        telescope2.save()

        response = client.get(
            reverse('astrobin_apps_equipment:equipment-item-group-list'),
            format='json')
        self.assertEquals(1, response.data['count'])
        self.assertEquals(group.name, response.data['results'][0]['name'])
        self.assertEquals(2, len(response.data['results'][0]['telescope_set']))
    def test_with_gear_and_two_unique_listings_on_different_gear_from_same_retailer_in_right_country(self):
        listing1 = EquipmentGenerators.equipment_brand_listing()
        listing1.retailer.countries = "us"
        listing1.retailer.save()

        listing2 = EquipmentGenerators.equipment_brand_listing()
        listing2.retailer = listing1.retailer
        listing2.save()

        telescope = Generators.telescope()
        telescope.equipment_brand_listings.add(listing1)

        mount = Generators.mount()
        mount.equipment_brand_listings.add(listing2)

        image = Generators.image()
        image.imaging_telescopes.add(telescope)
        image.mounts.add(mount)

        self.assertEqual(2, unique_equipment_brand_listings(image, 'us').count())
Ejemplo n.º 18
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)
    def test_with_gear_and_listing_in_wrong_country(self):
        listing = EquipmentGenerators.equipment_item_listing()
        listing.retailer.countries = "ch"
        listing.retailer.save()

        telescope = Generators.telescope()
        telescope.equipment_item_listings.add(listing)

        image = Generators.image()
        image.imaging_telescopes.add(telescope)

        self.assertEquals(0, unique_equipment_item_listings(image, 'us').count())
Ejemplo n.º 20
0
    def test_with_gear_and_listing_in_right_country(self):
        listing = EquipmentGenerators.equipment_brand_listing()
        listing.retailer.countries = "us"
        listing.retailer.save()

        telescope = Generators.telescope()
        telescope.equipment_brand_listings.add(listing)

        image = Generators.image()
        image.imaging_telescopes.add(telescope)

        self.assertEqual(1,
                         gear_items_with_brand_listings(image, 'us').count())
Ejemplo n.º 21
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:accessory-list'), {
            'brand': EquipmentGenerators.brand().pk,
            'name': 'Accessory Foo',
        }, format='json')
        self.assertEquals(201, response.status_code)
        self.assertEquals(user.pk, response.data['created_by'])
    def setUp(self):
        self.image = Generators.image()
        Generators.premium_subscription(self.image.user, "AstroBin Premium")

        self.image.user.userprofile.allow_retailer_integration = False
        self.image.user.userprofile.save()

        telescope = Generators.telescope()
        equipment_brand_listing = EquipmentGenerators.equipment_brand_listing()
        telescope.equipment_brand_listings.add(equipment_brand_listing)

        self.image.user.userprofile.telescopes.add(telescope)
        self.image.imaging_telescopes.add(telescope)
Ejemplo n.º 23
0
    def test_find_recently_used_wrong_usage_type(self):
        user = Generators.user()
        telescope = EquipmentGenerators.telescope(created_by=user)
        image = Generators.image(user=user)
        image.imaging_telescopes_2.add(telescope)

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

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

        self.assertEquals(0, len(response.data))
Ejemplo n.º 24
0
    def test_find_recently_used_one_usage(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=imaging',
                              format='json')

        self.assertEquals(1, len(response.data))
Ejemplo n.º 25
0
    def test_deleting_not_allowed(self):
        client = APIClient()

        accessory = EquipmentGenerators.accessory()

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

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

        response = client.get(
            reverse('astrobin_apps_equipment:accessory-list') + 'recently-used/', format='json'
        )

        self.assertEquals(1, len(response.data))
Ejemplo n.º 27
0
    def test_post_not_allowed(self):
        client = APIClient()

        response = client.post(
            reverse('astrobin_apps_equipment:telescope-list'), {
                'brand': EquipmentGenerators.brand().pk,
                'name': 'telescope Foo',
                'type': TelescopeType.REFRACTOR_ACHROMATIC,
            }, 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:telescope-list'), {
                'brand': EquipmentGenerators.brand().pk,
                'name': 'telescope Foo',
                'type': TelescopeType.REFRACTOR_ACHROMATIC,
            }, format='json'
        )
        self.assertEquals(403, response.status_code)
    def test_with_gear_and_two_non_unique_listings_on_different_gear_in_right_country(self):
        listing = EquipmentGenerators.equipment_item_listing()
        listing.retailer.countries = "us"
        listing.retailer.save()

        telescope = Generators.telescope()
        telescope.equipment_item_listings.add(listing)

        mount = Generators.mount()
        mount.equipment_item_listings.add(listing)

        image = Generators.image()
        image.imaging_telescopes.add(telescope)
        image.mounts.add(mount)

        self.assertEquals(1, unique_equipment_item_listings(image, 'us').count())
 def test_url_with_conflicting_params(self):
     listing = EquipmentGenerators.equipment_brand_listing(
         url='https://www.example.com/search?q=foo&source=foo')
     self.assertEqual('https://www.example.com/search?q=foo&source=foo',
                      equipment_listing_url_with_tags(listing, 'bar'))
 def test_simple_url(self):
     listing = EquipmentGenerators.equipment_brand_listing(
         url='https://www.example.com')
     self.assertEqual(
         f'https://www.example.com?brand={listing.brand.name}&retailer={listing.retailer.name}&source=foo',
         equipment_listing_url_with_tags(listing, 'foo'))