def test_tags(self):

        tags = Tag.objects.all()
        if FAST_TESTS:
            tags = tags[:1]

        for t in tags:

            # Anon user (not logged in)
            tracker_count_start = TagTracker.objects.all().count()
            response = self.client.get(reverse('orb_tags', args=[t.slug]))
            self.assertEqual(response.status_code, 200)
            tracker_count_end = TagTracker.objects.all().count()
            self.assertEqual(tracker_count_start + 1, tracker_count_end)

            # Standard user
            with login_client(self,
                              username='******',
                              password='******'):
                tracker_count_start = TagTracker.objects.all().count()
                response = self.client.get(reverse('orb_tags', args=[t.slug]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = TagTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)

            # api user
            with login_client(self, username='******', password='******'):
                tracker_count_start = TagTracker.objects.all().count()
                response = self.client.get(reverse('orb_tags', args=[t.slug]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = TagTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)

            # superuser
            with login_client(self, username='******', password='******'):
                tracker_count_start = TagTracker.objects.all().count()
                response = self.client.get(reverse('orb_tags', args=[t.slug]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = TagTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)

            # staffuser
            with login_client(self, username='******', password='******'):
                tracker_count_start = TagTracker.objects.all().count()
                response = self.client.get(reverse('orb_tags', args=[t.slug]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = TagTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)

            # orgowner
            with login_client(self, username='******', password='******'):
                tracker_count_start = TagTracker.objects.all().count()
                response = self.client.get(reverse('orb_tags', args=[t.slug]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = TagTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)
Exemplo n.º 2
0
 def test_session_authorized(self):
     with login_client(self, username='******', password='******'):
         data = {'q': 'medical'}
         tracker_count_start = SearchTracker.objects.all().count()
         resp = self.client.get(self.url, format='json', data=data)
         self.assertHttpOK(resp)
         self.assertValidJSON(resp.content)
         tracker_count_end = SearchTracker.objects.all().count()
         self.assertEqual(tracker_count_start + 1, tracker_count_end)
Exemplo n.º 3
0
 def test_session_authorized(self):
     with login_client(self, username='******', password='******'):
         data = {'q': 'medical'}
         tracker_count_start = SearchTracker.objects.all().count()
         resp = self.client.get(self.url, format='json', data=data)
         self.assertHttpOK(resp)
         self.assertValidJSON(resp.content)
         tracker_count_end = SearchTracker.objects.all().count()
         self.assertEqual(tracker_count_start + 1, tracker_count_end)
Exemplo n.º 4
0
def test_non_owner_cannot_edit_course(importer_profile, client, course):
    with login_client(client, username="******", password="******"):
        response = client.get(reverse("courses_edit", kwargs={"pk": course.pk}))
        assert response.status_code == 200

        response = client.post(
            reverse("courses_edit", kwargs={"pk": course.pk}),
            json.dumps({"sections": "[]", "title": "Hello"}),
            content_type="application/json",
        )
        assert response.status_code == 403
def test_non_owner_cannot_edit_course(importer_profile, client, course):
    with login_client(client, username="******", password="******"):
        response = client.get(reverse("courses_edit", kwargs={"pk": course.pk}))
        assert response.status_code == 200

        response = client.post(
            reverse("courses_edit", kwargs={"pk": course.pk}),
            json.dumps({"sections": "[]", "title": "Hello"}),
            content_type="application/json",
        )
        assert response.status_code == 403
    def test_resources_rejected(self):

        rejected_resources = Resource.objects.filter(status=Resource.REJECTED)

        if FAST_TESTS:
            rejected_resources = rejected_resources[:1]

        for r in rejected_resources:

            # Anon user (not logged in)
            response = self.client.get(reverse('orb_resource', args=[r.slug]))
            self.assertEqual(response.status_code, 404)

            response = self.client.get(
                reverse('orb_resource_permalink', args=[r.id]))
            self.assertEqual(response.status_code, 404)

            # Standard user
            with login_client(self,
                              username='******',
                              password='******'):
                self.user = User.objects.get(username='******')
                response = self.client.get(
                    reverse('orb_resource', args=[r.slug]))
                if r.create_user == self.user or r.update_user == self.user:
                    self.assertEqual(response.status_code, 200)
                else:
                    self.assertEqual(response.status_code, 404)

                response = self.client.get(
                    reverse('orb_resource_permalink', args=[r.id]))
                if r.create_user == self.user or r.update_user == self.user:
                    self.assertEqual(response.status_code, 200)
                else:
                    self.assertEqual(response.status_code, 404)

            # api user
            with login_client(self, username='******', password='******'):
                self.user = User.objects.get(username='******')
                response = self.client.get(
                    reverse('orb_resource', args=[r.slug]))
                if r.create_user == self.user or r.update_user == self.user:
                    self.assertEqual(response.status_code, 200)
                else:
                    self.assertEqual(response.status_code, 404)

                response = self.client.get(
                    reverse('orb_resource_permalink', args=[r.id]))
                if r.create_user == self.user or r.update_user == self.user:
                    self.assertEqual(response.status_code, 200)
                else:
                    self.assertEqual(response.status_code, 404)

            # superuser
            with login_client(self, username='******', password='******'):
                response = self.client.get(
                    reverse('orb_resource', args=[r.slug]))
                self.assertEqual(response.status_code, 200)

                response = self.client.get(
                    reverse('orb_resource_permalink', args=[r.id]))
                self.assertEqual(response.status_code, 200)

            # staffuser
            with login_client(self, username='******', password='******'):
                response = self.client.get(
                    reverse('orb_resource', args=[r.slug]))
                self.assertEqual(response.status_code, 200)

                response = self.client.get(
                    reverse('orb_resource_permalink', args=[r.id]))
                self.assertEqual(response.status_code, 200)

            # orgowner
            with login_client(self, username='******', password='******'):
                self.user = User.objects.get(username='******')
                response = self.client.get(
                    reverse('orb_resource', args=[r.slug]))
                if r.create_user == self.user or r.update_user == self.user:
                    self.assertEqual(response.status_code, 200)
                else:
                    self.assertEqual(response.status_code, 404)

                response = self.client.get(
                    reverse('orb_resource_permalink', args=[r.id]))
                if r.create_user == self.user or r.update_user == self.user:
                    self.assertEqual(response.status_code, 200)
                else:
                    self.assertEqual(response.status_code, 404)

        def test_tag_link(self):
            tag_links = Tag.objects.all().exclude(external_url=None).exclude(
                external_url='')
    def test_resources_pending(self):
        pending_resources = Resource.objects.filter(status=Resource.PENDING)

        if FAST_TESTS:
            pending_resources = pending_resources[:1]

        for r in pending_resources:

            # Anon user (not logged in)
            tracker_count_start = ResourceTracker.objects.all().count()
            response = self.client.get(reverse('orb_resource', args=[r.slug]))
            self.assertEqual(response.status_code, 404)
            tracker_count_end = ResourceTracker.objects.all().count()
            self.assertEqual(tracker_count_start, tracker_count_end)

            tracker_count_start = ResourceTracker.objects.all().count()
            response = self.client.get(
                reverse('orb_resource_permalink', args=[r.id]))
            self.assertEqual(response.status_code, 404)
            tracker_count_end = ResourceTracker.objects.all().count()
            self.assertEqual(tracker_count_start, tracker_count_end)

            # Standard user
            with login_client(self,
                              username='******',
                              password='******'):
                self.user = User.objects.get(username='******')
                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource', args=[r.slug]))
                if r.create_user == self.user or r.update_user == self.user:
                    self.assertEqual(response.status_code, 200)
                    tracker_count_end = ResourceTracker.objects.all().count()
                    self.assertEqual(tracker_count_start + 1,
                                     tracker_count_end)
                else:
                    self.assertEqual(response.status_code, 404)
                    tracker_count_end = ResourceTracker.objects.all().count()
                    self.assertEqual(tracker_count_start, tracker_count_end)

                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource_permalink', args=[r.id]))
                if r.create_user == self.user or r.update_user == self.user:
                    self.assertEqual(response.status_code, 200)
                    tracker_count_end = ResourceTracker.objects.all().count()
                    self.assertEqual(tracker_count_start + 1,
                                     tracker_count_end)
                else:
                    self.assertEqual(response.status_code, 404)
                    tracker_count_end = ResourceTracker.objects.all().count()
                    self.assertEqual(tracker_count_start, tracker_count_end)

            # api user
            with login_client(self, username='******', password='******'):
                self.user = User.objects.get(username='******')
                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource', args=[r.slug]))
                if r.create_user == self.user or r.update_user == self.user:
                    self.assertEqual(response.status_code, 200)
                    tracker_count_end = ResourceTracker.objects.all().count()
                    self.assertEqual(tracker_count_start + 1,
                                     tracker_count_end)
                else:
                    self.assertEqual(response.status_code, 404)
                    tracker_count_end = ResourceTracker.objects.all().count()
                    self.assertEqual(tracker_count_start, tracker_count_end)

                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource_permalink', args=[r.id]))
                if r.create_user == self.user or r.update_user == self.user:
                    self.assertEqual(response.status_code, 200)
                    tracker_count_end = ResourceTracker.objects.all().count()
                    self.assertEqual(tracker_count_start + 1,
                                     tracker_count_end)
                else:
                    self.assertEqual(response.status_code, 404)
                    tracker_count_end = ResourceTracker.objects.all().count()
                    self.assertEqual(tracker_count_start, tracker_count_end)

            # superuser
            with login_client(self, username='******', password='******'):
                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource', args=[r.slug]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = ResourceTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)

                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource_permalink', args=[r.id]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = ResourceTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)

            # staffuser
            with login_client(self, username='******', password='******'):
                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource', args=[r.slug]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = ResourceTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)

                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource_permalink', args=[r.id]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = ResourceTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)

            # orgowner
            with login_client(self, username='******', password='******'):
                self.user = User.objects.get(username='******')
                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource', args=[r.slug]))
                if r.create_user == self.user or r.update_user == self.user:
                    self.assertEqual(response.status_code, 200)
                    tracker_count_end = ResourceTracker.objects.all().count()
                    self.assertEqual(tracker_count_start + 1,
                                     tracker_count_end)
                else:
                    self.assertEqual(response.status_code, 404)
                    tracker_count_end = ResourceTracker.objects.all().count()
                    self.assertEqual(tracker_count_start, tracker_count_end)

                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource_permalink', args=[r.id]))
                if r.create_user == self.user or r.update_user == self.user:
                    self.assertEqual(response.status_code, 200)
                    tracker_count_end = ResourceTracker.objects.all().count()
                    self.assertEqual(tracker_count_start + 1,
                                     tracker_count_end)
                else:
                    self.assertEqual(response.status_code, 404)
                    tracker_count_end = ResourceTracker.objects.all().count()
                    self.assertEqual(tracker_count_start, tracker_count_end)
    def test_resources_approved(self):

        approved_resources = Resource.objects.filter(status=Resource.APPROVED)
        if FAST_TESTS:
            approved_resources = approved_resources[:1]

        for r in approved_resources:

            # Anon user (not logged in)
            tracker_count_start = ResourceTracker.objects.all().count()
            response = self.client.get(reverse('orb_resource', args=[r.slug]))
            self.assertEqual(response.status_code, 200)
            tracker_count_end = ResourceTracker.objects.all().count()
            self.assertEqual(tracker_count_start + 1, tracker_count_end)

            tracker_count_start = ResourceTracker.objects.all().count()
            response = self.client.get(
                reverse('orb_resource_permalink', args=[r.id]))
            self.assertEqual(response.status_code, 200)
            tracker_count_end = ResourceTracker.objects.all().count()
            self.assertEqual(tracker_count_start + 1, tracker_count_end)

            # Standard user
            with login_client(self,
                              username='******',
                              password='******'):
                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource', args=[r.slug]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = ResourceTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)

                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource_permalink', args=[r.id]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = ResourceTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)

            # api user
            with login_client(self, username='******', password='******'):
                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource', args=[r.slug]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = ResourceTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)

                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource_permalink', args=[r.id]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = ResourceTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)

            # superuser
            with login_client(self, username='******', password='******'):
                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource', args=[r.slug]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = ResourceTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)

                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource_permalink', args=[r.id]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = ResourceTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)

            # staffuser
            with login_client(self, username='******', password='******'):
                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource', args=[r.slug]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = ResourceTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)

                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource_permalink', args=[r.id]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = ResourceTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)

            # orgowner
            with login_client(self, username='******', password='******'):
                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource', args=[r.slug]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = ResourceTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)

                tracker_count_start = ResourceTracker.objects.all().count()
                response = self.client.get(
                    reverse('orb_resource_permalink', args=[r.id]))
                self.assertEqual(response.status_code, 200)
                tracker_count_end = ResourceTracker.objects.all().count()
                self.assertEqual(tracker_count_start + 1, tracker_count_end)