コード例 #1
0
 def test_get_crop_box_iotd_tiny_image(self):
     image = Generators.image(is_wip=True)
     image.w = 100
     image.h = 100
     image.square_cropping = '0,0,50,50'
     self.assertEqual(
         ImageService(image).get_crop_box('iotd'), '0,6,100,44')
コード例 #2
0
 def test_display_download_menu_null(self):
     image = Generators.image(download_limitations=None)
     self.assertTrue(ImageService(image).display_download_menu(image.user))
     self.assertFalse(
         ImageService(image).display_download_menu(Generators.user()))
     self.assertFalse(
         ImageService(image).display_download_menu(AnonymousUser))
コード例 #3
0
    def test_get_corrupted_images_when_non_final_revision_is_corrupted(self):
        user = Generators.user()
        image = Generators.image(user=user, is_final=False)
        Generators.imageRevision(image=image, is_final=False, corrupted=True)
        Generators.imageRevision(image=image, is_final=True, label='C')

        self.assertFalse(image in UserService(user).get_corrupted_images())
コード例 #4
0
    def test_can_like_image_anon(self, is_authenticated):
        user = Generators.user()
        image = Generators.image()

        is_authenticated.return_value = False

        self.assertFalse(UserService(user).can_like(image))
コード例 #5
0
    def test_get_review_queue_future_iotd(self):
        uploader = Generators.user()
        submitter = Generators.user(groups=['iotd_submitters'])
        submitter2 = Generators.user(groups=['iotd_submitters'])
        reviewer1 = Generators.user(groups=['iotd_reviewers'])
        reviewer2 = Generators.user(groups=['iotd_reviewers'])
        reviewer3 = Generators.user(groups=['iotd_reviewers'])
        judge = Generators.user(groups=['iotd_judges'])

        Generators.premium_subscription(uploader, "AstroBin Ultimate 2020+")

        image = Generators.image(user=uploader)
        image.designated_iotd_submitters.add(submitter, submitter2)
        image.designated_iotd_reviewers.add(reviewer3)

        IotdSubmission.objects.create(submitter=submitter, image=image)

        IotdSubmission.objects.create(submitter=submitter2, image=image)

        IotdVote.objects.create(reviewer=reviewer1, image=image)

        IotdVote.objects.create(reviewer=reviewer2, image=image)

        Iotd.objects.create(date=date.today() + timedelta(days=1),
                            judge=judge,
                            image=image)

        self.assertEquals(1, len(IotdService().get_review_queue(reviewer3)))
コード例 #6
0
    def test_can_unlike_anon(self, is_authenticated):
        image = Generators.image()
        like = Generators.like(image)

        is_authenticated.return_value = False

        self.assertFalse(UserService(like.user).can_unlike(image))
コード例 #7
0
    def test_with_gear_but_no_listings(self):
        telescope = Generators.telescope()

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

        self.assertEqual(0, unique_equipment_item_listings(image, 'us').count())
コード例 #8
0
    def test_get_judgement_queue_current_iotd(self):
        uploader = Generators.user()
        submitter = Generators.user(groups=['iotd_submitters'])
        submitter2 = Generators.user(groups=['iotd_submitters'])
        reviewer = Generators.user(groups=['iotd_reviewers'])
        reviewer2 = Generators.user(groups=['iotd_reviewers'])
        judge = Generators.user(groups=['iotd_judges'])

        Generators.premium_subscription(uploader, "AstroBin Ultimate 2020+")

        image = Generators.image(user=uploader)
        image.designated_iotd_submitters.add(submitter, submitter2)
        image.designated_iotd_reviewers.add(reviewer, reviewer2)

        IotdSubmission.objects.create(submitter=submitter, image=image)

        IotdSubmission.objects.create(submitter=submitter2, image=image)

        IotdVote.objects.create(reviewer=reviewer, image=image)

        IotdVote.objects.create(reviewer=reviewer2, image=image)

        Iotd.objects.create(judge=judge, image=image, date=date.today())

        self.assertEquals(0, len(IotdService().get_judgement_queue()))
コード例 #9
0
    def test_mark_as_pending_due_to_insufficient_previously_approved_comments_with_one_pending(
            self, get_scores):
        # Index:             NOT OK
        # Membership:        NOT OK
        # Approved comments: NOT OK

        get_scores.return_value = {'user_scores_index': 0}

        image = Generators.image()
        author = Generators.user()

        for i in range(0, 2):
            comment = NestedCommentsGenerators.comment(
                author=author,
                content_type=ContentType.objects.get_for_model(Image),
                oject_id=image.id,
            )
            comment.pending_moderation = None
            comment.save()

        NestedCommentsGenerators.comment(
            author=author,
            content_type=ContentType.objects.get_for_model(Image),
            oject_id=image.id,
        )

        comment = NestedCommentsGenerators.comment(
            author=author,
            content_type=ContentType.objects.get_for_model(Image),
            oject_id=image.id,
        )

        self.assertTrue(comment.pending_moderation)
コード例 #10
0
    def test_send_notifications_reply(self, add_story, push_notification,
                                      get_scores):
        get_scores.return_value = {'user_scores_index': 2}

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

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

        push_notification.assert_called_with(mock.ANY, 'new_comment', mock.ANY)
        add_story.assert_called_with(comment.author,
                                     verb='VERB_COMMENTED_IMAGE',
                                     action_object=comment,
                                     target=comment.content_object)

        push_notification.reset_mock()
        add_story.resetMock()

        comment = NestedCommentsGenerators.comment(author=commenter2,
                                                   target=image,
                                                   parent=comment)

        calls = [
            mock.call(mock.ANY, 'new_comment', mock.ANY),
            mock.call(mock.ANY, 'new_comment_reply', mock.ANY),
        ]
        push_notification.assert_has_calls(calls, any_order=True)

        add_story.assert_called_with(comment.author,
                                     verb='VERB_COMMENTED_IMAGE',
                                     action_object=comment,
                                     target=comment.content_object)
コード例 #11
0
    def test_all_images_in_staging_warning_when_image_is_wip(self):
        image = Generators.image(is_wip=True)
        self.client.login(username=image.user.username, password='******')

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

        self.assertContains(response, "Can't find your images?")
コード例 #12
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, commenter,
                                             'new_comment', mock.ANY)

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

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

        add_story.assert_called_with(comment.author,
                                     verb='VERB_COMMENTED_IMAGE',
                                     action_object=comment,
                                     target=comment.content_object)
コード例 #13
0
    def test_send_notifications_top_level_with_mention_and_notification(
            self, add_story, push_notification_from_signals, push_notification,
            get_scores):
        get_scores.return_value = {'user_scores_index': 2}

        image = Generators.image()
        commenter = Generators.user()
        NoticeSetting.for_user(
            image.user, NoticeType.objects.get(label='new_comment_mention'), 1)

        comment = NestedCommentsGenerators.comment(
            author=commenter,
            target=image,
            text='[quote="%s"]Foo[/quote]' % image.user.username)

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

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

        push_notification_from_signals.assert_called_with(
            [image.user], commenter, 'new_comment_mention', mock.ANY)

        add_story.assert_called_with(comment.author,
                                     verb='VERB_COMMENTED_IMAGE',
                                     action_object=comment,
                                     target=comment.content_object)
コード例 #14
0
    def test_send_notifications_top_level_with_mention_but_no_notification(
            self, add_story, push_notification_from_signals, 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,
            text='[quote="%s"]Foo[/quote]' % image.user.username)

        push_notification.assert_called_with([image.user], commenter,
                                             'new_comment', mock.ANY)

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

        # This is called anyway but will have no effect since there is not NoticeSetting for this user. The goal of this
        # test is to check that the 'new_comment' notification is sent.
        push_notification_from_signals.assert_called_with(
            mock.ANY, commenter, 'new_comment_mention', mock.ANY)

        add_story.assert_called_with(comment.author,
                                     verb='VERB_COMMENTED_IMAGE',
                                     action_object=comment,
                                     target=comment.content_object)
コード例 #15
0
    def test_can_like_image_ok(self, get_scores, is_free):
        user = Generators.user()
        image = Generators.image()

        is_free.return_value = False

        self.assertTrue(UserService(user).can_like(image))
コード例 #16
0
    def test_get_judgement_queue_too_long_ago(self):
        uploader = Generators.user()
        submitter = Generators.user(groups=['iotd_submitters'])
        submitter2 = Generators.user(groups=['iotd_submitters'])
        reviewer = Generators.user(groups=['iotd_reviewers'])
        reviewer2 = Generators.user(groups=['iotd_reviewers'])

        Generators.premium_subscription(uploader, "AstroBin Ultimate 2020+")

        image = Generators.image(user=uploader)
        image.designated_iotd_submitters.add(submitter, submitter2)
        image.designated_iotd_reviewers.add(reviewer, reviewer2)

        IotdSubmission.objects.create(submitter=submitter, image=image)

        IotdSubmission.objects.create(submitter=submitter2, image=image)

        vote = IotdVote.objects.create(reviewer=reviewer, image=image)

        vote2 = IotdVote.objects.create(reviewer=reviewer2, image=image)

        vote.date = datetime.now() - timedelta(
            days=settings.IOTD_JUDGEMENT_WINDOW_DAYS + 1)
        vote.save()

        vote2.date = datetime.now() - timedelta(
            days=settings.IOTD_JUDGEMENT_WINDOW_DAYS + 1)
        vote2.save()

        self.assertEquals(0, len(IotdService().get_judgement_queue()))
コード例 #17
0
 def test_get_crop_box_gallery_inverted(self):
     image = Generators.image(is_wip=True)
     image.w = image.h = 1000
     image.square_cropping = '100,100,200,200'
     self.assertEqual(
         ImageService(image).get_crop_box('gallery_inverted'),
         '100,100,200,200')
コード例 #18
0
    def test_get_review_queue_submitted_two_days_ago(self):
        uploader = Generators.user()
        submitter = Generators.user(groups=['iotd_submitters'])
        submitter2 = Generators.user(groups=['iotd_submitters'])
        reviewer = Generators.user(groups=['iotd_reviewers'])

        Generators.premium_subscription(uploader, "AstroBin Ultimate 2020+")

        image = Generators.image(user=uploader)
        image.designated_iotd_submitters.add(submitter, submitter2)
        image.designated_iotd_reviewers.add(reviewer)

        submission = IotdSubmission.objects.create(
            submitter=submitter,
            image=image,
        )

        IotdSubmission.objects.create(
            submitter=submitter2,
            image=image,
        )

        submission.date = datetime.now() - timedelta(days=2)
        submission.save()

        self.assertEquals(1, len(IotdService().get_review_queue(reviewer)))
コード例 #19
0
 def test_get_crop_box_iotd_center_example_1(self):
     image = Generators.image(is_wip=True)
     image.w = 400
     image.h = 800
     image.square_cropping = '50,50,350,350'
     self.assertEqual(
         ImageService(image).get_crop_box('iotd'), '0,124,400,276')
コード例 #20
0
    def test_get_revisions_with_description(self):
        image = Generators.image()
        Generators.imageRevision(image=image)
        Generators.imageRevision(image=image, label='C', description='Foo')

        self.assertEquals(
            ImageService(image).get_revisions_with_description().count(), 1)
コード例 #21
0
 def test_get_crop_box_iotd_center_example_2(self):
     image = Generators.image(is_wip=True)
     image.w = 2100
     image.h = 2500
     image.square_cropping = '100,400,100,2200'
     self.assertEqual(
         ImageService(image).get_crop_box('iotd'), '0,901,2100,1699')
コード例 #22
0
    def test_can_unlike_never_liked(self, is_authenticated):
        is_authenticated.return_value = True

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

        self.assertFalse(UserService(user).can_unlike(image))
コード例 #23
0
 def test_get_crop_box_iotd_edge(self):
     image = Generators.image(is_wip=True)
     image.w = 1200
     image.h = 500
     image.square_cropping = '0,20,0,20'
     self.assertEqual(
         ImageService(image).get_crop_box('iotd'), '0,0,1200,455')
コード例 #24
0
    def test_can_like_image_superuser(self):
        user = Generators.user()
        image = Generators.image()
        user.is_superuser = True
        user.save()

        self.assertTrue(UserService(user).can_like(image))
コード例 #25
0
 def test_get_next_available_revision_label_with_deleted_revision(self):
     image = Generators.image(is_wip=True)
     Generators.imageRevision(image=image)
     to_delete = Generators.imageRevision(image=image, label='C')
     to_delete.delete()
     self.assertEqual(
         ImageService(image).get_next_available_revision_label(), 'D')
コード例 #26
0
    def test_may_submit_to_iotd_tp_process_may(
            self, may_submit_to_iotd_tp_process_service):
        may_submit_to_iotd_tp_process_service.return_value = True, None

        image = Generators.image()

        self.assertTrue(may_submit_to_iotd_tp_process(image.user, image))
コード例 #27
0
    def test_needs_premium_subscription_to_platesolve_solving_already_attempted(
            self, is_platesolving_attempted, is_platesolvable):
        image = Generators.image()

        is_platesolving_attempted.return_value = True
        is_platesolvable.return_value = True

        self.assertFalse(ImageService(image).needs_premium_subscription_to_platesolve())
コード例 #28
0
    def test_get_hemisphere_negative_declination(self):
        image = Generators.image()
        solution = PlateSolvingGenerators.solution(image)

        solution.dec = -1
        solution.save()

        self.assertEqual(Image.HEMISPHERE_TYPE_SOUTHERN, ImageService(image).get_hemisphere())
コード例 #29
0
    def test_delete_original_when_one_revision_and_revision_is_final(self):
        image = Generators.image(image_file='original.jpg', is_final=False)
        Generators.imageRevision(image=image, image_file='revision.jpg', is_final=True)

        ImageService(image).delete_original()

        self.assertEqual('revision.jpg', image.image_file)
        self.assertTrue(image.is_final)
コード例 #30
0
    def test_get_hemisphere_no_declination(self):
        image = Generators.image()
        solution = PlateSolvingGenerators.solution(image)

        solution.dec = None
        solution.save()

        self.assertEqual(Image.HEMISPHERE_TYPE_UNKNOWN, ImageService(image).get_hemisphere())