예제 #1
0
 def test_save__active(self, parent_save):
     testdata.user("*****@*****.**")
     self.form.save(request=self.request,
                    extra_email_context=self.extra_email_context,
                    from_email="*****@*****.**")
     parent_save.assert_called_once_with(
         request=self.request,
         extra_email_context=self.extra_email_context,
         from_email="*****@*****.**")
예제 #2
0
    def test_delete_channels(self):
        user = testdata.user()
        channel1 = models.Channel.objects.create(**self.channel_metadata)
        channel1.editors.add(user)

        channel2 = models.Channel.objects.create(**self.channel_metadata)
        channel2.editors.add(user)

        self.client.force_authenticate(user=user)
        response = self.client.post(
            self.sync_url,
            [
                generate_delete_event(channel1.id, CHANNEL),
                generate_delete_event(channel2.id, CHANNEL),
            ],
            format="json",
        )
        self.assertEqual(response.status_code, 200, response.content)
        try:
            models.Channel.objects.get(id=channel1.id)
            self.fail("Channel 1 was not deleted")
        except models.Channel.DoesNotExist:
            pass

        try:
            models.Channel.objects.get(id=channel2.id)
            self.fail("Channel 2 was not deleted")
        except models.Channel.DoesNotExist:
            pass
예제 #3
0
    def test_cannot_delete_some_channels(self):
        user = testdata.user()
        channel1 = models.Channel.objects.create(**self.channel_metadata)
        channel1.editors.add(user)
        channel2 = models.Channel.objects.create(**self.channel_metadata)

        self.client.force_authenticate(user=user)
        with self.settings(TEST_ENV=False):
            # Override test env here to check what will happen in production
            response = self.client.post(
                self.sync_url,
                [
                    generate_delete_event(channel1.id, CHANNEL),
                    generate_delete_event(channel2.id, CHANNEL),
                ],
                format="json",
            )
        # Returns a 200 as, as far as the frontend is concerned
        # the operation is done.
        self.assertEqual(response.status_code, 200, response.content)
        try:
            models.Channel.objects.get(id=channel1.id)
            self.fail("Channel 1 was not deleted")
        except models.Channel.DoesNotExist:
            pass

        try:
            models.Channel.objects.get(id=channel2.id)
        except models.Channel.DoesNotExist:
            self.fail("Channel 2 was deleted")
예제 #4
0
파일: test_users.py 프로젝트: pcenov/studio
    def test_activate__alternate_casing(self):
        user2 = testdata.user(email="*****@*****.**")
        user2.set_password("tester")
        user2.save()

        self.view.validate_key.return_value = self.user.email
        self.assertFalse(self.view.activate(**self.kwargs))
예제 #5
0
    def test_viewer_cannot_update_some_channels(self):
        user = testdata.user()
        channel1 = models.Channel.objects.create(**self.channel_metadata)
        channel1.editors.add(user)
        channel2 = models.Channel.objects.create(**self.channel_metadata)
        channel2.viewers.add(user)
        new_name = "This is not the old name"

        self.client.force_authenticate(user=user)
        with self.settings(TEST_ENV=False):
            # Override test env here to check what will happen in production
            response = self.client.post(
                self.sync_url,
                [
                    generate_update_event(channel1.id, CHANNEL,
                                          {"name": new_name}),
                    generate_update_event(channel2.id, CHANNEL,
                                          {"name": new_name}),
                ],
                format="json",
            )
        self.assertEqual(response.status_code, 207, response.content)
        self.assertEqual(
            models.Channel.objects.get(id=channel1.id).name, new_name)
        self.assertNotEqual(
            models.Channel.objects.get(id=channel2.id).name, new_name)
예제 #6
0
파일: test_users.py 프로젝트: pcenov/studio
 def setUp(self):
     super(UserActivationViewTestCase, self).setUp()
     self.view = UserActivationView()
     self.view.validate_key = mock.Mock()
     self.user = testdata.user(email="*****@*****.**")
     self.user.is_active = False
     self.user.save()
     self.kwargs = dict(activation_key="activation_key")
예제 #7
0
 def test_create_editor_and_viewer(self):
     editor = testdata.user(email="*****@*****.**")
     viewer = testdata.user(email="*****@*****.**")
     self.client.force_authenticate(user=self.user)
     response = self.client.post(
         self.sync_url,
         [
             generate_create_event([editor.id, self.channel.id], EDITOR_M2M,
                                   {}),
             generate_create_event([viewer.id, self.channel.id], VIEWER_M2M,
                                   {}),
         ],
         format="json",
     )
     self.assertEqual(response.status_code, 200, response.content)
     self.assertTrue(self.channel.editors.filter(id=editor.id).exists())
     self.assertTrue(self.channel.viewers.filter(id=viewer.id).exists())
예제 #8
0
    def test_filter_edit_queryset__orphan_tree(self):
        contentnode = create_contentnode(settings.ORPHANAGE_ROOT_ID)

        user = testdata.user()
        queryset = ContentNode.filter_edit_queryset(self.base_queryset,
                                                    user=user)
        self.assertQuerysetDoesNotContain(queryset,
                                          pk=settings.ORPHANAGE_ROOT_ID)
        self.assertQuerysetContains(queryset, pk=contentnode.id)
예제 #9
0
파일: test_users.py 프로젝트: pcenov/studio
 def setUp(self):
     super(LoginTestCase, self).setUp()
     self.request = mock.Mock()
     self.request.method = "POST"
     self.user = testdata.user(email="*****@*****.**")
     self.request.body = json.dumps(
         dict(
             username="******",
             password="******",
         ))
예제 #10
0
    def test_filter_view_queryset__private_channel__pending_editor(self):
        channel = testdata.channel()

        user = testdata.user()
        queryset = Channel.filter_view_queryset(self.base_queryset, user=user)
        self.assertQuerysetDoesNotContain(queryset, pk=channel.id)

        Invitation.objects.create(email=user.email, channel=channel)
        queryset = Channel.filter_view_queryset(self.base_queryset, user=user)
        self.assertQuerysetContains(queryset, pk=channel.id)
예제 #11
0
    def test_filter_edit_queryset__uploaded_by(self):
        user = testdata.user()
        node_file = File.objects.create(uploaded_by=user)

        queryset = File.filter_edit_queryset(self.base_queryset,
                                             user=self.forbidden_user)
        self.assertQuerysetDoesNotContain(queryset, pk=node_file.id)

        queryset = File.filter_edit_queryset(self.base_queryset, user=user)
        self.assertQuerysetContains(queryset, pk=node_file.id)
예제 #12
0
 def test_create_channel(self):
     user = testdata.user()
     self.client.force_authenticate(user=user)
     channel = self.channel_metadata
     response = self.client.post(reverse("channel-list"), channel, format="json",)
     self.assertEqual(response.status_code, 201, response.content)
     try:
         models.Channel.objects.get(id=channel["id"])
     except models.Channel.DoesNotExist:
         self.fail("Channel was not created")
예제 #13
0
 def test_fetch_channel_for_admin(self):
     channel = models.Channel.objects.create(**self.channel_metadata)
     user = testdata.user()
     user.is_admin = True
     user.save()
     self.client.force_authenticate(user=user)
     response = self.client.get(
         reverse("channel-detail", kwargs={"pk": channel.id}), format="json",
     )
     self.assertEqual(response.status_code, 200, response.content)
예제 #14
0
    def test_filter_view_queryset__private_channel(self):
        channel = testdata.channel()

        queryset = Channel.filter_view_queryset(self.base_queryset,
                                                user=self.forbidden_user)
        self.assertQuerysetDoesNotContain(queryset, pk=channel.id)

        user = testdata.user()
        channel.viewers.add(user)
        queryset = Channel.filter_view_queryset(self.base_queryset, user=user)
        self.assertQuerysetContains(queryset, pk=channel.id)
예제 #15
0
 def test_fetch_admin_channels_invalid_filter(self):
     models.Channel.objects.create(**self.channel_metadata)
     user = testdata.user()
     user.is_admin = True
     user.is_staff = True
     user.save()
     self.client.force_authenticate(user=user)
     response = self.client.get(
         reverse("admin-channels-list") + "?public=true&page_size=25&edit=true", format="json",
     )
     self.assertEqual(response.status_code, 200, response.content)
예제 #16
0
    def test_filter_view_queryset__private_channel(self):
        channel = testdata.channel()
        assessment_file = create_assessment_item_file(channel.main_tree_id)

        queryset = File.filter_view_queryset(self.base_queryset,
                                             user=self.forbidden_user)
        self.assertQuerysetDoesNotContain(queryset, pk=assessment_file.id)

        user = testdata.user()
        channel.viewers.add(user)
        queryset = File.filter_view_queryset(self.base_queryset, user=user)
        self.assertQuerysetContains(queryset, pk=assessment_file.id)
예제 #17
0
    def test_filter_view_queryset__public_channel(self):
        channel = self.public_channel
        node_file = create_file(channel.main_tree_id)

        queryset = File.filter_view_queryset(self.base_queryset,
                                             user=self.forbidden_user)
        self.assertQuerysetContains(queryset, pk=node_file.id)

        user = testdata.user()
        channel.viewers.add(user)
        queryset = File.filter_view_queryset(self.base_queryset, user=user)
        self.assertQuerysetContains(queryset, pk=node_file.id)
예제 #18
0
    def test_filter_view_queryset__public_channel__deleted(self):
        channel = self.public_channel
        channel.deleted = True
        channel.save()

        queryset = Channel.filter_view_queryset(self.base_queryset,
                                                user=self.forbidden_user)
        self.assertQuerysetDoesNotContain(queryset, pk=channel.id)

        user = testdata.user()
        channel.viewers.add(user)
        queryset = Channel.filter_view_queryset(self.base_queryset, user=user)
        self.assertQuerysetContains(queryset, pk=channel.id)
예제 #19
0
    def test_filter_view_queryset__public_channel(self):
        channel = self.public_channel
        assessment_item = create_assessment_item(channel.main_tree_id)

        queryset = AssessmentItem.filter_view_queryset(
            self.base_queryset, user=self.forbidden_user)
        self.assertQuerysetContains(queryset, pk=assessment_item.id)

        user = testdata.user()
        channel.viewers.add(user)
        queryset = AssessmentItem.filter_view_queryset(self.base_queryset,
                                                       user=user)
        self.assertQuerysetContains(queryset, pk=assessment_item.id)
예제 #20
0
    def test_update_channel(self):
        user = testdata.user()
        channel = models.Channel.objects.create(**self.channel_metadata)
        channel.editors.add(user)
        new_name = "This is not the old name"

        self.client.force_authenticate(user=user)
        response = self.client.patch(
            reverse("channel-detail", kwargs={"pk": channel.id}),
            {"name": new_name},
            format="json",
        )
        self.assertEqual(response.status_code, 200, response.content)
        self.assertEqual(models.Channel.objects.get(id=channel.id).name, new_name)
예제 #21
0
    def test_update_channel(self):
        user = testdata.user()
        channel = models.Channel.objects.create(**self.channel_metadata)
        channel.editors.add(user)
        new_name = "This is not the old name"

        self.client.force_authenticate(user=user)
        response = self.client.post(
            self.sync_url,
            [generate_update_event(channel.id, CHANNEL, {"name": new_name})],
            format="json",
        )
        self.assertEqual(response.status_code, 200, response.content)
        self.assertEqual(models.Channel.objects.get(id=channel.id).name, new_name)
예제 #22
0
    def test_delete_channel(self):
        user = testdata.user()
        channel = models.Channel.objects.create(**self.channel_metadata)
        channel.editors.add(user)

        self.client.force_authenticate(user=user)
        response = self.client.delete(
            reverse("channel-detail", kwargs={"pk": channel.id}))
        self.assertEqual(response.status_code, 204, response.content)
        try:
            models.Channel.objects.get(id=channel.id)
            self.fail("Channel was not deleted")
        except models.Channel.DoesNotExist:
            pass
예제 #23
0
 def test_create_channel(self):
     user = testdata.user()
     self.client.force_authenticate(user=user)
     channel = self.channel_metadata
     response = self.client.post(
         self.sync_url,
         [generate_create_event(channel["id"], CHANNEL, channel)],
         format="json",
     )
     self.assertEqual(response.status_code, 200, response.content)
     try:
         models.Channel.objects.get(id=channel["id"])
     except models.Channel.DoesNotExist:
         self.fail("Channel was not created")
예제 #24
0
    def test_viewer_can_bookmark_channel(self):
        user = testdata.user()
        channel = models.Channel.objects.create(**self.channel_metadata)
        channel.viewers.add(user)

        self.client.force_authenticate(user=user)
        with self.settings(TEST_ENV=False):
            # Override test env here to check what will happen in production
            response = self.client.post(
                self.sync_url,
                [generate_update_event(channel.id, CHANNEL, {"bookmark": True})],
                format="json",
            )
        self.assertEqual(response.status_code, 200, response.content)
        self.assertTrue(user.bookmarked_channels.filter(id=channel.id).exists())
예제 #25
0
    def test_filter_edit_queryset__public_channel(self):
        channel = self.public_channel

        queryset = Channel.filter_edit_queryset(self.base_queryset,
                                                user=self.forbidden_user)
        self.assertQuerysetDoesNotContain(queryset, pk=channel.id)

        user = testdata.user()
        channel.viewers.add(user)
        queryset = Channel.filter_edit_queryset(self.base_queryset, user=user)
        self.assertQuerysetDoesNotContain(queryset, pk=channel.id)

        channel.editors.add(user)
        queryset = Channel.filter_edit_queryset(self.base_queryset, user=user)
        self.assertQuerysetContains(queryset, pk=channel.id)
예제 #26
0
    def test_filter_view_queryset__private_channel(self):
        channel = testdata.channel()
        contentnode = create_contentnode(channel.main_tree_id)

        queryset = ContentNode.filter_view_queryset(self.base_queryset,
                                                    user=self.forbidden_user)
        self.assertQuerysetDoesNotContain(queryset,
                                          pk=settings.ORPHANAGE_ROOT_ID)
        self.assertQuerysetDoesNotContain(queryset, pk=contentnode.id)

        user = testdata.user()
        channel.viewers.add(user)
        queryset = ContentNode.filter_view_queryset(self.base_queryset,
                                                    user=user)
        self.assertQuerysetDoesNotContain(queryset,
                                          pk=settings.ORPHANAGE_ROOT_ID)
        self.assertQuerysetContains(queryset, pk=contentnode.id)
예제 #27
0
 def test_update_channel_thumbnail_encoding(self):
     user = testdata.user()
     channel = models.Channel.objects.create(**self.channel_metadata)
     channel.editors.add(user)
     new_encoding = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQA"
     self.client.force_authenticate(user=user)
     response = self.client.post(
         self.sync_url,
         [generate_update_event(channel.id, CHANNEL, {
             "thumbnail_encoding.base64": new_encoding,
             "thumbnail_encoding.orientation": 1,
             "thumbnail_encoding.scale": 0.73602189113443,
             "thumbnail_encoding.startX": -96.66631072431669,
             "thumbnail_encoding.startY": -335.58116356397636,
         })],
         format="json",
     )
     self.assertEqual(response.status_code, 200, response.content)
     self.assertEqual(models.Channel.objects.get(id=channel.id).thumbnail_encoding["base64"], new_encoding)
예제 #28
0
    def test_update_channel_defaults(self):
        user = testdata.user()
        channel = models.Channel.objects.create(**self.channel_metadata)
        channel.editors.add(user)
        author = "This is not the old author"

        self.client.force_authenticate(user=user)
        response = self.client.post(
            self.sync_url,
            [
                generate_update_event(channel.id, CHANNEL,
                                      {"content_defaults.author": author})
            ],
            format="json",
        )
        self.assertEqual(response.status_code, 200, response.content)
        self.assertEqual(
            models.Channel.objects.get(
                id=channel.id).content_defaults["author"], author)

        aggregator = "This is not the old aggregator"

        self.client.force_authenticate(user=user)
        response = self.client.post(
            self.sync_url,
            [
                generate_update_event(
                    channel.id, CHANNEL,
                    {"content_defaults.aggregator": aggregator})
            ],
            format="json",
        )
        self.assertEqual(response.status_code, 200, response.content)
        self.assertEqual(
            models.Channel.objects.get(
                id=channel.id).content_defaults["author"], author)
        self.assertEqual(
            models.Channel.objects.get(
                id=channel.id).content_defaults["aggregator"],
            aggregator,
        )
예제 #29
0
파일: test_users.py 프로젝트: pcenov/studio
    def test_login__case_sensitivity__multiple(self):
        with mock.patch(
                "contentcuration.views.users.djangologin") as djangologin:
            self.user.email = "*****@*****.**"
            self.user.is_active = False
            self.user.save()

            user2 = testdata.user(email="*****@*****.**")
            user2.set_password("tester")
            user2.save()

            self.request.body = json.dumps(
                dict(
                    username="******",
                    password="******",
                ))

            redirect = login(self.request)
            djangologin.assert_called()
            self.assertIsInstance(redirect, HttpResponseRedirectBase)
            self.assertIn("channels", redirect['Location'])
예제 #30
0
    def test_save__inactive__no_password(self, email_user, render_to_string):
        user = testdata.user("*****@*****.**")
        user.is_active = False
        user.password = ''
        user.save()

        render_to_string.side_effect = ["Subject", "Message"]
        self.form.save(request=self.request,
                       extra_email_context=self.extra_email_context,
                       from_email="*****@*****.**")
        self.form.get_activation_key.assert_not_called()
        context = {
            'site': "LE",
            'user': user,
            'domain': "test.learningequality.org",
        }
        render_to_string.assert_any_call(
            'registration/password_reset_subject.txt', context)
        render_to_string.assert_any_call(
            'registration/registration_needed_email.txt', context)
        email_user.assert_called_once_with("Subject", "Message",
                                           settings.DEFAULT_FROM_EMAIL)