Ejemplo n.º 1
0
class SimpleTest(TestCase):
    """ most of these tests are just about getting
    the absolute bare minimum of test coverage in place,
    hitting pages and just making sure they return the
    appropriate 200/302 status instead of generating a
    server error. *Real* tests can come later.
    """
    def setUp(self):
        self.u = UserFactory()
        self.u.set_password("bar")
        self.u.save()
        self.c = Client()

    def tearDown(self):
        self.u.delete()

    def test_index(self):
        response = self.c.get('/')
        self.assertEquals(response.status_code, 302)

        self.c.login(username=self.u.username, password="******")
        response = self.c.get('/')
        self.assertEquals(response.status_code, 200)

    def test_smoke(self):
        response = self.c.get('/smoketest/')
        self.assertEquals(response.status_code, 200)

    def test_dashboard(self):
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/dashboard/")
        self.assertEquals(response.status_code, 200)

    def test_received_invalid(self):
        response = self.c.post("/received/")
        assert response.content == "expecting a title"

    def test_received(self):
        response = self.c.post("/received/",
                               {'title': 'some title. not a uuid'})
        assert response.content == "ok"

    def test_received_with_operation(self):
        o = OperationFactory()
        response = self.c.post("/received/",
                               {'title': str(o.uuid)})
        assert response.content == "ok"

    def test_recent_operations(self):
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/recent_operations/")
        self.assertEquals(response.status_code, 200)

    def test_upload_form(self):
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/upload/")
        self.assertEquals(response.status_code, 200)

        response = self.c.get("/scan_directory/")
        self.assertEquals(response.status_code, 200)

    def test_upload_form_for_collection(self):
        c = CollectionFactory()
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/upload/")
        self.assertEquals(response.status_code, 200)
        response = self.c.get("/upload/?collection=%d" % c.id)
        self.assertEquals(response.status_code, 200)

        response = self.c.get("/scan_directory/")
        self.assertEquals(response.status_code, 200)
        response = self.c.get("/scan_directory/?collection=%d" % c.id)
        self.assertEquals(response.status_code, 200)

    def test_upload_errors(self):
        # if we try to post without logging in, should get redirected
        response = self.c.post("/upload/post/")
        self.assertEquals(response.status_code, 302)

        self.c.login(username=self.u.username, password="******")
        # GET should not work
        response = self.c.get("/upload/post/")
        self.assertEquals(response.status_code, 302)

        # invalid form
        response = self.c.post("/upload/post/")
        self.assertEquals(response.status_code, 302)

    def test_subject_autocomplete(self):
        response = self.c.get("/api/subjectautocomplete/", dict(q="test"))
        self.assertEquals(response.status_code, 200)

    def test_uuid_search(self):
        f = FileFactory()
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/uuid_search/", dict(uuid=f.video.uuid))
        self.assertEquals(response.status_code, 200)

    def test_uuid_search_empty(self):
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/uuid_search/", dict(uuid=""))
        self.assertEquals(response.status_code, 200)

    def test_search(self):
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/search/", dict(q="test"))
        self.assertEquals(response.status_code, 200)

    def test_search_empty(self):
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/search/", dict(q=""))
        self.assertEquals(response.status_code, 200)

    def test_file_filter(self):
        f = FileFactory()
        self.c.login(username=self.u.username, password="******")
        response = self.c.get(
            "/file/filter/",
            dict(
                include_collection=f.video.collection.id,
            ))
        self.assertEquals(response.status_code, 200)

    def test_video_index(self):
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/video/")
        self.assertEquals(response.status_code, 200)

    def test_video_index_nan(self):
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/video/?page=foo")
        self.assertEquals(response.status_code, 200)

    def test_video_index_offtheend(self):
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/video/?page=200")
        self.assertEquals(response.status_code, 200)

    def test_video_index_with_params(self):
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/video/?creator=c&description=d&"
                              "language=l&subject=s&licence=l")
        self.assertEquals(response.status_code, 200)

    def test_file_index(self):
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/file/")
        self.assertEquals(response.status_code, 200)

    def test_file_index_nan(self):
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/file/?page=foo")
        self.assertEquals(response.status_code, 200)

    def test_file_index_offtheend(self):
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/file/?page=200")
        self.assertEquals(response.status_code, 200)

    def test_file_index_with_params(self):
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/file/?foo=bar")
        self.assertEquals(response.status_code, 200)

    def test_user_page(self):
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/user/%s/" % self.u.username)
        self.assertEquals(response.status_code, 200)

    def test_collection_videos(self):
        f = FileFactory()
        self.c.login(username=self.u.username, password="******")
        response = self.c.get(
            "/collection/%d/videos/" % f.video.collection.id)
        self.assertEquals(response.status_code, 200)

    def test_collection_videos_pagination_nan(self):
        f = FileFactory()
        self.c.login(username=self.u.username, password="******")
        response = self.c.get(
            "/collection/%d/videos/?page=foo" % f.video.collection.id)
        self.assertEquals(response.status_code, 200)

    def test_collection_videos_pagination_offtheend(self):
        f = FileFactory()
        self.c.login(username=self.u.username, password="******")
        response = self.c.get(
            "/collection/%d/videos/?page=200" % f.video.collection.id)
        self.assertEquals(response.status_code, 200)

    def test_collection_operations(self):
        f = FileFactory()
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/collection/%d/operations/"
                              % f.video.collection.id)
        self.assertEquals(response.status_code, 200)

    def test_collection_page(self):
        f = FileFactory()
        self.c.login(username=self.u.username, password="******")
        response = self.c.get(
            "/collection/%d/" % f.video.collection.id)
        self.assertEquals(response.status_code, 200)

    def test_slow_operations(self):
        self.c.login(username=self.u.username, password="******")
        response = self.c.get("/slow_operations/")
        self.assertEquals(response.status_code, 200)

    def test_tagautocomplete(self):
        response = self.c.get("/api/tagautocomplete/?q=foo")
        self.assertEquals(response.status_code, 200)

    def test_subjectautocomplete(self):
        VideoFactory(title="thread")
        response = self.c.get("/api/subjectautocomplete/?q=thread")
        self.assertEquals(response.status_code, 200)

    def test_operation_info(self):
        o = OperationFactory()
        response = self.c.get("/operation/%s/info/" % o.uuid)
        self.assertEqual(response.status_code, 200)

    def test_posterdone(self):
        o = OperationFactory()
        response = self.c.post("/posterdone/", dict(title=str(o.uuid)))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, "ok")

    def test_posterdone_empty(self):
        response = self.c.post("/posterdone/")
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, "expecting a title")

    def test_posterdone_nonexistant(self):
        response = self.c.post("/posterdone/", dict(title="some-bad-uuid"))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, "ok")

    def test_done(self):
        o = OperationFactory()
        response = self.c.post("/done/", dict(title=str(o.uuid)))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, "ok")

    def test_done_no_title(self):
        response = self.c.post("/done/")
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, "expecting a title")

    def test_done_nonexistant(self):
        response = self.c.post("/done/", dict(title="some-bad-uuid"))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content,
                         "could not find an operation with that UUID")