def test_lite_2020(self):
        user = Generators.user()
        self.client.login(username=user.username, password="******")
        Generators.premium_subscription(user, "AstroBin Lite 2020+")

        response = self.client.get(
            reverse('image_detail', kwargs={'id': self.image.get_id()}))
        self.assertNotContains(response,
                               "dropdown retailer-affiliate-products-lite")
        self.assertContains(response, "retailer-affiliate-cart-link")

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

        response = self.client.get(
            reverse('image_detail', kwargs={'id': self.image.get_id()}))
        self.assertNotContains(response,
                               "dropdown retailer-affiliate-products-lite")
        self.assertContains(response, "retailer-affiliate-cart-link")
コード例 #2
0
    def test_never_activated_accounts_one_found(self):
        u = Generators.user()
        u.is_active = False
        u.date_joined = timezone.now() - timedelta(15)
        u.save()

        accounts = utils.never_activated_accounts()

        self.assertEqual(1, accounts.count())
        self.assertEqual(u, accounts.first())
コード例 #3
0
    def test_delete_original_when_one_revision_and_original_is_final(self):
        image = Generators.image(image_file='original.jpg')
        PlateSolvingGenerators.solution(image,
                                        image_file='original_solution.jpg')

        revision = Generators.imageRevision(image=image,
                                            image_file='revision.jpg')
        revision_solution = PlateSolvingGenerators.solution(
            revision, image_file='revision_solution.jpg')

        ImageService(image).delete_original()

        self.assertEquals('revision.jpg', image.image_file)
        self.assertTrue(image.is_final)
        self.assertEquals('revision_solution.jpg',
                          revision_solution.image_file)
        self.assertEquals(image.pk, revision_solution.object_id)
        self.assertEquals(1, Image.objects.all().count())
        self.assertEquals(1, Solution.objects.all().count())
コード例 #4
0
 def test_get_mentioned_users_with_notification_enabled_users_with_notifications_enabled(self):
     user = Generators.user()
     notice_type = NoticeType.objects.create(
         label='new_forum_post_mention',
         display='',
         description='',
         default=2)
     NoticeSetting.for_user(user, notice_type, 1)
     self.assertEqual(
         [user],
         MentionsService.get_mentioned_users_with_notification_enabled([user.username], 'new_forum_post_mention'))
コード例 #5
0
    def equipment_item_listing(**kwargs):
        brand = kwargs.get('brand', EquipmentGenerators.equipment_brand())
        retailer = kwargs.get('retailer',
                              EquipmentGenerators.equipment_retailer())

        return EquipmentItemListing.objects.create(
            name=kwargs.get('name', Generators.randomString()),
            retailer=retailer,
            url=kwargs.get('url',
                           "%s/shop/%s" % (retailer.website, slugify(brand))),
        )
コード例 #6
0
ファイル: test_user.py プロジェクト: astrobin/astrobin
    def test_all_images_in_staging_warning_when_image_is_wip_and_display_wip_images_on_public_gallery(
            self):
        image = Generators.image(is_wip=True)
        image.user.userprofile.display_wip_images_on_public_gallery = True
        image.user.userprofile.save()
        self.client.login(username=image.user.username, password='******')

        response = self.client.get(
            reverse('user_page', args=(image.user.username, )))

        self.assertNotContains(response, "Can't find your images?")
コード例 #7
0
    def test_delete_original_when_no_revisions(self):
        image= Generators.image()
        PlateSolvingGenerators.solution(image)

        self.assertEqual(1, Image.objects.all().count())
        self.assertEqual(1, Solution.objects.all().count())

        ImageService(image).delete_original()

        self.assertEqual(0, Image.objects.all().count())
        self.assertEqual(0, Solution.objects.all().count())
コード例 #8
0
    def test_user_page_subscription_lite_2020(self):
        image = Generators.image()
        image.user = self.user
        image.save()

        us = Generators.premium_subscription(self.user, "AstroBin Lite 2020+")

        self.client.login(username='******', password='******')

        response = self.client.get(reverse('user_page', args=('user',)))

        self.assertContains(response, "<h4>Subscription</h4>", html=True)
        self.assertContains(response, "<strong data-test='subscription-type'>AstroBin Lite</strong>", html=True)
        self.assertContains(
            response,
            "<strong data-test='expiration-date'>" +
            "<abbr class='timestamp' data-epoch='%s000'>...</abbr>" % us.expires.strftime('%s') +
            "</strong>",
            html=True)
        self.assertContains(response, "<strong data-test='images-used'>0 / 123</strong>", html=True)
コード例 #9
0
    def test_never_activated_accounts_to_be_deleted_two_found(self):
        first = Generators.user()
        first.is_active = False
        first.date_joined = timezone.now() - timedelta(22)
        first.save()

        first.userprofile.never_activated_account_reminder_sent = timezone.now()
        first.userprofile.save()

        second = Generators.user()
        second.is_active = False
        second.date_joined = timezone.now() - timedelta(22)
        second.save()

        second.userprofile.never_activated_account_reminder_sent = timezone.now()
        second.userprofile.save()

        accounts = utils.never_activated_accounts_to_be_deleted()

        self.assertEquals(2, accounts.count())
コード例 #10
0
    def test_imagerevision_post_save_not_created_no_notifications(
            self, add_story, push_notification):
        revision = Generators.imageRevision()

        push_notification.reset_mock()
        add_story.reset_mock()

        imagerevision_post_save(None, revision, False)

        self.assertFalse(push_notification.called)
        self.assertFalse(add_story.called)
コード例 #11
0
    def test_send_notifications_top_level(self, add_story, push_notification,
                                          get_scores):
        get_scores.return_value = {'user_scores_index': 2}

        image = Generators.image()
        commenter = Generators.user()

        comment = NestedCommentsGenerators.comment(author=commenter,
                                                   target=image)

        push_notification.assert_called_with(mock.ANY, 'new_comment', mock.ANY)

        with self.assertRaises(AssertionError):
            push_notification.assert_called_with(mock.ANY, 'new_comment_reply',
                                                 mock.ANY)

        add_story.assert_called_with(comment.author,
                                     verb='VERB_COMMENTED_IMAGE',
                                     action_object=comment,
                                     target=comment.content_object)
コード例 #12
0
    def test_find_recently_used_no_usages(self):
        user = Generators.user()

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

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

        self.assertEquals(0, len(response.data))
コード例 #13
0
    def test_get_users_in_group_sample_one_user(self):
        group = Group.objects.create(name='test_group')
        user = Generators.user()
        user.groups.add(group)

        self.assertEqual(
            1, len(UserService.get_users_in_group_sample(group.name, 10)))
        self.assertEqual(
            1, len(UserService.get_users_in_group_sample(group.name, 50)))
        self.assertEqual(
            1, len(UserService.get_users_in_group_sample(group.name, 100)))
コード例 #14
0
    def test_needs_premium_subscription_to_platesolve_solving_already_attempted(
            self, is_free, is_platesolving_attempted, is_platesolvable):
        image = Generators.image()
        image.subject_type = SubjectType.DEEP_SKY
        image.save()

        is_free.return_value = False
        is_platesolving_attempted.return_value = False
        is_platesolvable.return_value = True

        self.assertFalse(ImageService(image).needs_premium_subscription_to_platesolve())
コード例 #15
0
    def test_rejection_api_login_required(self):
        client = APIClient()

        image = Generators.image()
        comment = NestedCommentsGenerators.comment(target=image,
                                                   pending_moderation=True)

        response = client.post(
            reverse('nested_comments:nestedcomments-report-abuse',
                    args=(comment.pk, )))
        self.assertEqual(401, response.status_code)
コード例 #16
0
    def test_find_recently_used_not_supported(self):
        user = Generators.user()

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

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

        self.assertEquals(400, response.status_code)
コード例 #17
0
    def test_get_top_picks_is_future_iotd(self):
        image = Generators.image()
        Generators.image()
        Generators.premium_subscription(image.user, 'AstroBin Ultimate 2020+')

        IotdGenerators.submission(image=image)
        IotdGenerators.vote(image=image)
        IotdGenerators.vote(image=image)
        IotdGenerators.iotd(image=image, date=date.today() + timedelta(days=1))

        image.published = datetime.now() - timedelta(
            settings.IOTD_REVIEW_WINDOW_DAYS) - timedelta(hours=1)
        image.save()

        IotdService().update_top_pick_archive()

        top_picks = IotdService().get_top_picks()

        self.assertEquals(1, top_picks.count())
        self.assertEquals(image, top_picks.first().image)
コード例 #18
0
    def test_imagerevision_post_save_skip_notifications(self, add_story, push_notification):
        revision = Generators.imageRevision()
        revision.skip_notifications = True

        push_notification.reset_mock()
        add_story.reset_mock()

        imagerevision_post_save(None, revision, True)

        self.assertFalse(push_notification.called)
        self.assertFalse(add_story.called)
コード例 #19
0
    def test_without_compensation_request(self):
        user = User.objects.create_user(username="******", password="******")
        premium = Generators.premium_subscription(
            user, "AstroBin Premium (autorenew)")
        ultimate = Generators.premium_subscription(user,
                                                   "AstroBin Ultimate 2020+")

        premium.expires = date.today() + timedelta(days=30)
        premium.unsubscribe()

        ultimate.expires = date.today()

        self.assertTrue(is_ultimate_2020(user))
        self.assertFalse(is_premium(user))

        reactivate_previous_subscription_when_ultimate_compensation_expires.apply(
        )

        self.assertTrue(is_ultimate_2020(user))
        self.assertFalse(is_premium(user))
コード例 #20
0
    def test_with_gear_and_two_unique_listings_on_different_gear_from_same_retailer_in_right_country(self):
        listing1 = EquipmentGenerators.equipment_item_listing()
        listing1.retailer.countries = "us"
        listing1.retailer.save()

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

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

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

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

        self.assertEquals(2, unique_equipment_item_listings(image, 'us').count())
コード例 #21
0
    def test_submission_model_image_cannot_be_past_iotd(self):
        Generators.premium_subscription(self.user, "AstroBin Ultimate 2020+")

        submission = IotdSubmission.objects.create(
            submitter=self.submitter_1,
            image=self.image)
        self.assertEqual(submission.submitter, self.submitter_1)
        self.assertEqual(submission.image, self.image)

        vote = IotdVote.objects.create(
            reviewer=self.reviewer_1,
            image=self.image)
        iotd = Iotd.objects.create(
            judge=self.judge_1,
            image=self.image,
            date=datetime.now().date() - timedelta(1))
        with self.assertRaisesRegex(ValidationError, "already been an IOTD"):
            IotdSubmission.objects.create(
                submitter=self.submitter_2,
                image=self.image)
コード例 #22
0
    def test_imagerevision_post_save_uploading(self, add_story,
                                               push_notification):
        revision = Generators.imageRevision()
        revision.uploader_in_progress = True

        push_notification.reset_mock()
        add_story.reset_mock()

        imagerevision_post_save(None, revision, True)

        self.assertFalse(push_notification.called)
        self.assertFalse(add_story.called)
コード例 #23
0
    def test_get_users_in_group_sample_many_users(self):
        group = Group.objects.create(name='test_group')
        for i in range(100):
            user = Generators.user()
            user.groups.add(group)

        self.assertEqual(
            10, len(UserService.get_users_in_group_sample(group.name, 10)))
        self.assertEqual(
            50, len(UserService.get_users_in_group_sample(group.name, 50)))
        self.assertEqual(
            100, len(UserService.get_users_in_group_sample(group.name, 100)))
コード例 #24
0
    def test_get_or_create_advanced_settings_image_does_not_inherit_file(self):
        image = Generators.image()

        solution = PlateSolvingGenerators.solution(image)
        advanced_settings, created = SolutionService.get_or_create_advanced_settings(
            image)
        advanced_settings.sample_raw_frame_file = File(
            open('astrobin/fixtures/test.fits'), "test.fits")
        advanced_settings.scaled_font_size = "L"

        solution.advanced_settings = advanced_settings
        solution.content_object = image
        solution.save()
        advanced_settings.save()

        advanced_settings, created = SolutionService.get_or_create_advanced_settings(
            Generators.image(user=image.user))

        self.assertIsNone(advanced_settings.sample_raw_frame_file.name)
        self.assertEquals(advanced_settings.scaled_font_size, "L")
        self.assertFalse(created)
コード例 #25
0
    def test_get_objects_in_field_2(self):
        basic = \
            'M 43, Mairan\'s Nebula, NGC 1982, Upper Sword, NGC 1981, Lower Sword, NGC 1980, the Running Man Nebula, ' \
            'NGC 1977, M 42, Orion Nebula, Great Orion Nebula, NGC 1976, NGC 1975, NGC 1973, The star 45Ori, ' \
            'The star ιOri, The star θ2Ori, The star θ1Ori, The star 42Ori'
        advanced = \
            'GridLabel,2100.97,889.69,2133.97,899.69,−7°30′\n' \
            'GridLabel,1752.10,661.34,1785.10,671.34,−6°45′\n' \
            'GridLabel,1403.90,433.37,1420.90,443.37,−6°\n' \
            'GridLabel,1055.90,205.27,1088.90,215.27,−5°15′\n' \
            'GridLabel,707.92,-23.04,740.92,-13.04,−4°30′\n' \
            'GridLabel,359.61,-251.42,392.61,-241.42,−3°45′\n' \
            'GridLabel,2014.56,-503.48,2047.56,-493.48,5h24m\n' \
            'GridLabel,1708.58,-41.88,1741.58,-31.88,5h28m\n' \
            'GridLabel,1403.90,419.37,1436.90,429.37,5h32m\n' \
            'GridLabel,1100.39,880.64,1133.39,890.64,5h36m\n' \
            'GridLabel,797.83,1342.59,830.83,1352.59,5h40m\n' \
            'Label,1047.55,803.40,1090.55,814.40,44 iot Ori\n' \
            'Label,1050.55,780.40,1090.55,793.40,Hatysa\n' \
            'Label,840.08,653.15,912.08,664.15,43 the02 Ori\n' \
            'Label,835.68,597.86,907.68,608.86,41 the01 Ori\n' \
            'Label,577.89,515.42,612.89,526.42,45 Ori\n' \
            'Label,618.81,462.10,663.81,473.10,42 c Ori\n' \
            'Label,883.02,616.32,955.02,627.32,41 the01 Ori\n' \
            'Label,783.97,590.40,808.97,602.40,M43\n' \
            'Label,668.97,618.90,790.97,630.90,De Mairan\'s nebula\n' \
            'Label,1412.06,1150.52,1471.06,1162.52,NGC1999\n' \
            'Label,1116.54,791.05,1175.54,803.05,NGC1980\n' \
            'Label,590.69,425.52,648.69,437.52,NGC1977\n' \
            'Label,552.36,377.02,610.36,389.02,NGC1973\n' \
            'Label,473.70,416.32,531.70,428.32,NGC1975\n' \
            'Label,447.67,310.97,505.67,322.97,NGC1981\n' \
            'Label,1330.13,255.41,1357.13,263.41,VdB42\n' \
            'Label,684.14,18.22,711.14,26.22,VdB44\n' \
            'Label,946.28,588.09,979.28,596.09,Sh2-281\n' \
            'Label,550.18,457.48,583.18,465.48,Sh2-279\n'

        image = Generators.image()
        solution = PlateSolvingGenerators.solution(image)
        solution.objects_in_field = basic
        solution.advanced_annotations = advanced

        self.assertEqual([
            '41 the01 Ori', '42 c Ori', '43 the02 Ori', '44 iot Ori', '45 Ori',
            'De Mairan\'s nebula', 'Great Orion Nebula', 'Hatysa',
            'Lower Sword', 'M 42', 'M 43', 'Mairan\'s Nebula', 'NGC 1973',
            'NGC 1975', 'NGC 1976', 'NGC 1977', 'NGC 1980', 'NGC 1981',
            'NGC 1982', 'NGC 1999', 'Orion Nebula', 'Sh2-279', 'Sh2-281',
            'The star 42Ori', 'The star 45Ori', 'The star θ1Ori',
            'The star θ2Ori', 'The star ιOri', 'Upper Sword', 'VdB42', 'VdB44',
            'the Running Man Nebula'
        ],
                         SolutionService(solution).get_objects_in_field())
コード例 #26
0
    def test_never_activated_accounts_to_be_deleted_none_found_already_activated(self):
        u = Generators.user()
        u.is_active = True
        u.date_joined = timezone.now() - timedelta(22)
        u.save()

        u.userprofile.never_activated_account_reminder_sent = timezone.now()
        u.userprofile.save()

        accounts = utils.never_activated_accounts_to_be_deleted()

        self.assertEquals(0, accounts.count())
コード例 #27
0
    def sensor(**kwargs):
        random_name = Generators.randomString()

        return Sensor.objects.create(
            created_by=kwargs.get('created_by', Generators.user()),
            brand=kwargs.get('brand', EquipmentGenerators.brand()),
            name=kwargs.get('name', 'Test sensor %s' % random_name),
            website=kwargs.get('website', 'https://www.test-sensor-%s.com/' %
                               random_name),
            quantum_efficiency=kwargs.get('quantum_efficiency', 90),
            pixel_size=kwargs.get('pixel_size', 1.5),
            pixel_width=kwargs.get('pixel_width', 1024),
            pixel_height=kwargs.get('pixel_height', 1024),
            sensor_width=kwargs.get('sensor_width', 1024),
            sensor_height=kwargs.get('sensor_height', 1024),
            full_well_capacity=kwargs.get('full_well_capacity', 30),
            read_noise=kwargs.get('read_noise', 5),
            frame_rate=kwargs.get('frame_rate', 60),
            adc=kwargs.get('adc', 12),
            color_or_mono=kwargs.get('color_or_mono', 'M'),
        )
コード例 #28
0
    def test_send_notifications_shadowban(self, add_story, push_notification,
                                          get_scores):
        get_scores.return_value = {'user_scores_index': 2}

        image = Generators.image()
        shadowbanned_user = Generators.user()

        image.user.userprofile.shadow_bans.add(shadowbanned_user.userprofile)

        comment = NestedCommentsGenerators.comment(author=shadowbanned_user,
                                                   target=image)

        with self.assertRaises(AssertionError):
            push_notification.assert_called_with(mock.ANY, 'new_comment',
                                                 mock.ANY)

        with self.assertRaises(AssertionError):
            add_story.assert_called_with(comment.author,
                                         verb='VERB_COMMENTED_IMAGE',
                                         action_object=comment,
                                         target=comment.content_object)
コード例 #29
0
    def test_next_prev(self):
        prev = Generators.image(user=self.user)
        prev.save()

        current = Generators.image(user=self.user)
        current.save()

        next = Generators.image(user=self.user)
        next.save()

        response = self.client.get(reverse('image_detail', args=(prev.get_id(),)))
        self.assertContains(response, "image-prev-none")
        self.assertContains(response, "image-next-%s" % current.get_id())

        response = self.client.get(reverse('image_detail', args=(current.get_id(),)))
        self.assertContains(response, "image-prev-%s" % prev.get_id())
        self.assertContains(response, "image-next-%s" % next.get_id())

        response = self.client.get(reverse('image_detail', args=(next.get_id(),)))
        self.assertContains(response, "image-prev-%s" % current.get_id())
        self.assertContains(response, "image-next-none")
コード例 #30
0
ファイル: test_forum.py プロジェクト: pierfra-r/astrobin
    def test_save_new_on_moderation_notifications(self, push_notification,
                                                  get_mentions):
        mentioned = Generators.user()

        get_mentions.return_value = [mentioned]

        post = Generators.forum_post(on_moderation=True)

        with self.assertRaises(AssertionError):
            push_notification.assert_called_with([mentioned], post.user,
                                                 'new_forum_post_mention',
                                                 mock.ANY)

        with self.assertRaises(AssertionError):
            push_notification.assert_called_with(mock.ANY, post.user,
                                                 'new_forum_reply', mock.ANY)

        with self.assertRaises(AssertionError):
            push_notification.assert_called_with([post.user], None,
                                                 'forum_post_approved',
                                                 mock.ANY)