def test_invalid_url(self):
        info = Mock()
        info.context = Mock()
        info.context.user = self.user.user
        result = (
            schema.get_mutation_type()
            .fields["editFeedbackRequest"]
            .resolver(
                self=Mock(),
                info=info,
                feedback_request_id=self.existing_request.id,
                media_url="not a real url",
                feedback_prompt="feedback_prompt",
                email_when_grouped=False,
                genre=GenreChoice.HIPHOP.name,
            )
        )

        self.assertEqual(
            result,
            EditFeedbackRequest(
                success=False, error=INVALID_MEDIA_URL_MESSAGE, invalid_media_url=True,
            ),
        )

        self.assertEqual(
            FeedbackRequest.objects.filter(
                user=self.user,
                media_url="https://soundcloud.com/ruairidx/grey",
                media_type=MediaTypeChoice.SOUNDCLOUD.name,
                feedback_prompt="feedback_prompt",
                genre=GenreChoice.ELECTRONIC.name,
            ).count(),
            1,
        )
    def test_logged_out(self):
        info = Mock()
        result = (
            schema.get_mutation_type()
            .fields["editFeedbackRequest"]
            .resolver(
                self=Mock(),
                info=info,
                feedback_request_id=self.existing_request.id,
                media_url="https://soundcloud.com/ruairidx/bruno",
                feedback_prompt="feedback_prompt",
                email_when_grouped=False,
                genre=GenreChoice.HIPHOP.name,
            )
        )

        self.assertEqual(
            result,
            EditFeedbackRequest(
                success=False, error="Not logged in.", invalid_media_url=False,
            ),
        )

        self.assertEqual(
            FeedbackRequest.objects.filter(
                user=self.user,
                media_url="https://soundcloud.com/ruairidx/bruno",
                genre=GenreChoice.HIPHOP.name,
            ).count(),
            0,
        )
    def test_valid_url(self):
        info = Mock()
        info.context = Mock()
        info.context.user = self.user.user
        result = (
            schema.get_mutation_type()
            .fields["editFeedbackRequest"]
            .resolver(
                self=Mock(),
                info=info,
                feedback_request_id=self.existing_request.id,
                media_url="https://www.dropbox.com/s/nonsense/file.wav",
                feedback_prompt="feedback_prompt",
                email_when_grouped=False,
                genre=GenreChoice.HIPHOP.name,
            )
        )

        self.assertEqual(
            result,
            EditFeedbackRequest(success=True, error=None, invalid_media_url=False,),
        )

        self.assertEqual(
            FeedbackRequest.objects.filter(
                user=self.user,
                media_url="https://www.dropbox.com/s/nonsense/file.wav",
                media_type=MediaTypeChoice.DROPBOX.name,
                feedback_prompt="feedback_prompt",
                email_when_grouped=False,
                genre=GenreChoice.HIPHOP.name,
            ).count(),
            1,
        )
Beispiel #4
0
class Mutation(graphene.ObjectType):
    register_user = RegisterUser.Field()
    update_email = UpdateEmail.Field()
    update_send_reminder_emails = UpdateSendReminderEmails.Field()

    create_feedback_request = CreateFeedbackRequest.Field()
    delete_feedback_request = DeleteFeedbackRequest.Field()
    edit_feedback_request = EditFeedbackRequest.Field()
    submit_feedback_response = SubmitFeedbackResponse.Field()
    rate_feedback_response = RateFeedbackResponse.Field()
    add_feedback_response_reply = AddFeedbackResponseReply.Field()
    mark_replies_as_read = MarkRepliesAsRead.Field()

    token_auth = ObtainJSONWebTokenCaseInsensitive.Field()
    def test_assigned_request(self):
        feedback_group = FeedbackGroup(name="name")
        feedback_group.save()
        self.existing_request.feedback_group = feedback_group
        self.existing_request.save()

        info = Mock()
        info.context = Mock()
        info.context.user = self.user.user
        result = (
            schema.get_mutation_type()
            .fields["editFeedbackRequest"]
            .resolver(
                self=Mock(),
                info=info,
                feedback_request_id=self.existing_request.id,
                media_url="https://www.dropbox.com/s/nonsense/file.wav",
                feedback_prompt="feedback_prompt",
                email_when_grouped=False,
                genre=GenreChoice.HIPHOP.name,
            )
        )

        self.assertEqual(
            result,
            EditFeedbackRequest(
                success=False,
                error="This request has already been assigned to a feedback group and cannot be edited.",
                invalid_media_url=False,
            ),
        )

        self.assertEqual(
            FeedbackRequest.objects.filter(
                user=self.user,
                media_url="https://soundcloud.com/ruairidx/grey",
                media_type=MediaTypeChoice.SOUNDCLOUD.name,
                feedback_prompt="feedback_prompt",
                email_when_grouped=True,
                genre=GenreChoice.ELECTRONIC.name,
            ).count(),
            1,
        )
    def test_unauthorised(self):
        self.new_user = FeedbackGroupsUser.create(
            email="*****@*****.**", password="******",
        )
        self.new_user.save()
        info = Mock()
        info.context = Mock()
        info.context.user = self.new_user.user
        result = (
            schema.get_mutation_type()
            .fields["editFeedbackRequest"]
            .resolver(
                self=Mock(),
                info=info,
                feedback_request_id=self.existing_request.id,
                media_url="https://www.dropbox.com/s/nonsense/file.wav",
                feedback_prompt="feedback_prompt",
                email_when_grouped=False,
                genre=GenreChoice.HIPHOP.name,
            )
        )

        self.assertEqual(
            result,
            EditFeedbackRequest(
                success=False,
                error="You are not the owner of this feedback request.",
                invalid_media_url=False,
            ),
        )

        self.assertEqual(
            FeedbackRequest.objects.filter(
                user=self.user,
                media_url="https://soundcloud.com/ruairidx/grey",
                media_type=MediaTypeChoice.SOUNDCLOUD.name,
                feedback_prompt="feedback_prompt",
                email_when_grouped=True,
                genre=GenreChoice.ELECTRONIC.name,
            ).count(),
            1,
        )