Ejemplo n.º 1
0
    def test_create_post_invalid(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {}

        self.assertEqual(models.Domain.objects.count(), 0)

        response = admin.domain_admin_create(request)
        self.assertEqual(response.status_code, 200)

        self.assertEqual(models.Domain.objects.count(), 0)
Ejemplo n.º 2
0
    def test_edit_post_invalid_owner(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {"domain": self.domain.domain, "enabled": False, "owner": 0}

        response = admin.domain_admin_edit(request, self.domain.pk)
        self.assertEqual(response.status_code, 200)
        self.domain.refresh_from_db()
        self.assertEqual(self.domain.enabled, True)
        self.assertEqual(self.domain.owner, None)
        self.assertEqual(models.Domain.objects.count(), 1)
Ejemplo n.º 3
0
    def test_create_post_invalid(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {}

        self.assertEqual(models.Domain.objects.count(), 0)

        response = admin.domain_admin_create(request)
        self.assertEqual(response.status_code, 200)

        self.assertEqual(models.Domain.objects.count(), 0)
Ejemplo n.º 4
0
    def test_edit_post(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {"domain": self.domain.domain, "enabled": False}

        response = admin.domain_admin_edit(request, self.domain.pk)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"], urlresolvers.reverse("admin:domains:index"))

        self.domain.refresh_from_db()
        self.assertEqual(self.domain.enabled, False)
        self.assertEqual(models.Domain.objects.count(), 1)
Ejemplo n.º 5
0
    def test_edit_post(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {"domain": self.domain.domain, "enabled": False}

        response = admin.domain_admin_edit(request, self.domain.pk)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"],
                         urlresolvers.reverse("admin:domains:index"))

        self.domain.refresh_from_db()
        self.assertEqual(self.domain.enabled, False)
        self.assertEqual(models.Domain.objects.count(), 1)
Ejemplo n.º 6
0
    def test_post_invalid(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {"succeeded": None}
        request_obj = factories.RequestFactory(requester=self.user)

        response = admin.request_admin_edit(request, request_obj.pk)
        self.assertEqual(response.status_code, 200)

        request_obj.refresh_from_db()
        self.assertEqual(request_obj.succeeded, None)
        self.assertEqual(request_obj.authorizer, None)
        self.assertEqual(request_obj.date_decided, None)
Ejemplo n.º 7
0
    def test_edit_post_blank(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {}
        self.domain.owner = self.user
        self.domain.save()

        response = admin.domain_admin_edit(request, self.domain.pk)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"],
                         urls.reverse("admin:domains:index"))
        self.assertEqual(models.Domain.objects.count(), 1)

        self.domain.refresh_from_db()
        self.assertEqual(self.domain.owner, self.user)
Ejemplo n.º 8
0
    def test_create_post(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {"domain": "example.com"}

        self.assertEqual(models.Domain.objects.count(), 0)

        response = admin.domain_admin_create(request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"], urlresolvers.reverse("admin:domains:index"))

        domain = models.Domain.objects.get()
        self.assertEqual(domain.owner, None)
        self.assertEqual(domain.enabled, True)
        self.assertEqual(domain.domain, "example.com")
Ejemplo n.º 9
0
    def test_edit_post_invalid_owner(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {
            "domain": self.domain.domain,
            "enabled": False,
            "owner": 0
        }

        response = admin.domain_admin_edit(request, self.domain.pk)
        self.assertEqual(response.status_code, 200)
        self.domain.refresh_from_db()
        self.assertEqual(self.domain.enabled, True)
        self.assertEqual(self.domain.owner, None)
        self.assertEqual(models.Domain.objects.count(), 1)
Ejemplo n.º 10
0
    def test_create_post(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {"domain": "example.com"}

        self.assertEqual(models.Domain.objects.count(), 0)

        response = admin.domain_admin_create(request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"],
                         urlresolvers.reverse("admin:domains:index"))

        domain = models.Domain.objects.get()
        self.assertEqual(domain.owner, None)
        self.assertEqual(domain.enabled, True)
        self.assertEqual(domain.domain, "example.com")
Ejemplo n.º 11
0
    def test_create_page_post(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {"title": "Test Page", "slug": "test-page"}

        page = models.HelpBasePage.objects.filter(parent__isnull=True).get()
        response = views.create_page(request, "helppage", page.pk)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(models.HelpPage.objects.count(), 0)

        request.POST["body"] = "body"
        response = views.create_page(request, "helppage", page.pk)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"], reverse("admin:index", kwargs={"page_pk": page.pk}))

        new_page = models.HelpBasePage.objects.get(slug="test-page", parent_id=page.pk)
        self.assertEqual(new_page.specific_class, models.HelpPage)
Ejemplo n.º 12
0
    def test_edit_page_post(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {"title": "Test Page", "slug": "test-page"}
        page = models.HelpBasePage.objects.filter(parent__isnull=False).get()

        response = views.edit_page(request, page_pk=page.pk)
        self.assertEqual(response.status_code, 200)

        request.POST["app"] = "tickets.urls"
        response = views.edit_page(request, page_pk=page.pk)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"], reverse("admin:index", kwargs={"page_pk": page.pk}))

        page.refresh_from_db()
        self.assertEqual(page.title, "Test Page")
        self.assertEqual(page.slug, "test-page")
Ejemplo n.º 13
0
    def test_edit_page_post(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {"title": "Test Page", "slug": "test-page"}
        page = models.HelpBasePage.objects.filter(parent__isnull=False).get()

        response = views.edit_page(request, page_pk=page.pk)
        self.assertEqual(response.status_code, 200)

        request.POST["app"] = "tickets.urls"
        response = views.edit_page(request, page_pk=page.pk)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"],
                         reverse("admin:index", kwargs={"page_pk": page.pk}))

        page.refresh_from_db()
        self.assertEqual(page.title, "Test Page")
        self.assertEqual(page.slug, "test-page")
Ejemplo n.º 14
0
    def test_create_page_post(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {"title": "Test Page", "slug": "test-page"}

        page = models.HelpBasePage.objects.filter(parent__isnull=True).get()
        response = views.create_page(request, "helppage", page.pk)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(models.HelpPage.objects.count(), 0)

        request.POST["body"] = "body"
        response = views.create_page(request, "helppage", page.pk)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"],
                         reverse("admin:index", kwargs={"page_pk": page.pk}))

        new_page = models.HelpBasePage.objects.get(slug="test-page",
                                                   parent_id=page.pk)
        self.assertEqual(new_page.specific_class, models.HelpPage)
Ejemplo n.º 15
0
    def test_post(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {}
        post = BlogPostFactory(author=self.user)
        other_post = BlogPostFactory(author=self.user)

        response = views.blog_admin_delete(request, post.pk)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(models.BlogPost.objects.count(), 2)

        request.POST = {"yes_delete": True}

        response = views.blog_admin_delete(request, post.pk)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"], urlresolvers.reverse("admin:blog:index"))

        self.assertEqual(models.BlogPost.objects.count(), 1)
        self.assertEqual(models.BlogPost.objects.get(), other_post)
Ejemplo n.º 16
0
    def test_post(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {}
        post = BlogPostFactory(author=self.user)
        other_post = BlogPostFactory(author=self.user)

        response = views.blog_admin_delete(request, post.pk)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(models.BlogPost.objects.count(), 2)

        request.POST = {"yes_delete": True}

        response = views.blog_admin_delete(request, post.pk)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"], urlresolvers.reverse("admin:blog:index"))

        self.assertEqual(models.BlogPost.objects.count(), 1)
        self.assertEqual(models.BlogPost.objects.get(), other_post)
Ejemplo n.º 17
0
    def test_post(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {"body": "hi"}
        question = QuestionFactory(status=0)
        self.assertEqual(question.response_set.count(), 0)

        # status is required
        response = views.question_admin_response(request, question.pk)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(question.response_set.count(), 0)
        question.refresh_from_db()
        self.assertEqual(question.status, 0)

        # new response, but not status change
        request.POST = {"body": "reply", "status": 0}
        response = views.question_admin_response(request, question.pk)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"],
                         urlresolvers.reverse("admin:tickets:index"))
        self.assertEqual(question.response_set.count(), 1)
        self.assertEqual(question.response_set.get().body, "reply")
        question.refresh_from_db()
        self.assertEqual(question.status, 0)

        # new response, but not status change
        request.POST = {"status": 1}
        response = views.question_admin_response(request, question.pk)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(question.response_set.count(), 1)
        question.refresh_from_db()
        self.assertEqual(question.status, 0)

        # new response, status change
        request.POST = {"body": "reply2", "status": 1}
        response = views.question_admin_response(request, question.pk)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"],
                         urlresolvers.reverse("admin:tickets:index"))
        self.assertEqual(question.response_set.count(), 2)
        question.refresh_from_db()
        self.assertEqual(question.status, 1)
Ejemplo n.º 18
0
    def test_post(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {}
        post = BlogPostFactory(author=self.user, draft=True, subject="no", body="no")

        response = views.blog_admin_edit(request, post.pk)
        self.assertEqual(response.status_code, 200)

        request.POST = {"subject": "Test", "body": "Hello"}

        response = views.blog_admin_edit(request, post.pk)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"], urlresolvers.reverse("admin:blog:index"))

        self.assertEqual(models.BlogPost.objects.count(), 1)
        post = models.BlogPost.objects.get()
        self.assertEqual(post.subject, "Test")
        self.assertEqual(post.body, "Hello")
        self.assertEqual(post.draft, False)
Ejemplo n.º 19
0
    def test_post(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {}

        response = views.blog_admin_create(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(models.BlogPost.objects.count(), 0)

        request.POST = {"subject": "Test", "body": "Hello"}

        response = views.blog_admin_create(request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"], urlresolvers.reverse("admin:blog:index"))

        self.assertEqual(models.BlogPost.objects.count(), 1)
        post = models.BlogPost.objects.get()
        self.assertEqual(post.subject, "Test")
        self.assertEqual(post.body, "Hello")
        self.assertEqual(post.draft, True)
Ejemplo n.º 20
0
    def test_post(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {}
        post = BlogPostFactory(author=self.user, draft=True, subject="no", body="no")

        response = views.blog_admin_edit(request, post.pk)
        self.assertEqual(response.status_code, 200)

        request.POST = {"subject": "Test", "body": "Hello"}

        response = views.blog_admin_edit(request, post.pk)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"], urlresolvers.reverse("admin:blog:index"))

        self.assertEqual(models.BlogPost.objects.count(), 1)
        post = models.BlogPost.objects.get()
        self.assertEqual(post.subject, "Test")
        self.assertEqual(post.body, "Hello")
        self.assertEqual(post.draft, False)
Ejemplo n.º 21
0
    def test_post(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {}

        response = views.blog_admin_create(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(models.BlogPost.objects.count(), 0)

        request.POST = {"subject": "Test", "body": "Hello"}

        response = views.blog_admin_create(request)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"], urlresolvers.reverse("admin:blog:index"))

        self.assertEqual(models.BlogPost.objects.count(), 1)
        post = models.BlogPost.objects.get()
        self.assertEqual(post.subject, "Test")
        self.assertEqual(post.body, "Hello")
        self.assertEqual(post.draft, True)
Ejemplo n.º 22
0
    def test_post_rejected(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {"succeeded": False}
        request_obj = factories.RequestFactory(requester=self.user)
        # also pre-create profile
        pool_amount = request_obj.requester.inboxenprofile.pool_amount

        response = admin.request_admin_edit(request, request_obj.pk)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"],
                         urlresolvers.reverse("admin:requests:index"))

        request_obj.refresh_from_db()
        self.assertEqual(request_obj.succeeded, False)
        self.assertEqual(request_obj.authorizer, self.user)
        self.assertNotEqual(request_obj.date_decided, None)

        self.user.inboxenprofile.refresh_from_db()
        self.assertEqual(self.user.inboxenprofile.pool_amount, pool_amount)
Ejemplo n.º 23
0
    def test_delete_page_post(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {}

        page = models.HelpBasePage.objects.filter(parent__isnull=False).get()

        response = views.delete_page(request, page_pk=page.pk)
        self.assertEqual(response.status_code, 200)

        # page still exists
        page.refresh_from_db()

        request.POST["yes_delete"] = True
        response = views.delete_page(request, page_pk=page.pk)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"], reverse("admin:index", kwargs={"page_pk": page.parent_id}))

        # page was deleted
        with self.assertRaises(models.HelpBasePage.DoesNotExist):
            page.refresh_from_db()
Ejemplo n.º 24
0
    def test_delete_page_post(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {}

        page = models.HelpBasePage.objects.filter(parent__isnull=False).get()

        response = views.delete_page(request, page_pk=page.pk)
        self.assertEqual(response.status_code, 200)

        # page still exists
        page.refresh_from_db()

        request.POST["yes_delete"] = True
        response = views.delete_page(request, page_pk=page.pk)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(
            response["Location"],
            reverse("admin:index", kwargs={"page_pk": page.parent_id}))

        # page was deleted
        with self.assertRaises(models.HelpBasePage.DoesNotExist):
            page.refresh_from_db()