Example #1
0
    def test_server_start_run(self):
        fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])

        server = HTTPServer(("localhost", 8094), SimpleHandler)
        thread = run_server(server, True)

        url = "http://localhost:8094/localfile/__file__"
        cont = get_url_content_timeout(url)
        assert len(cont) > 0
        if sys.platform.startswith("win"):
            assert "class SimpleHandler(BaseHTTPRequestHandler):" in cont

        url = "http://localhost:8094/localfile/test_simpleserver.py?execute=False&path=%s" % path
        fLOG(url)
        cont = get_url_content_timeout(url)
        if "class TestSimpleServer (unittest.TestCase):" not in cont:
            raise Exception("expects to find 'class TestSimpleServer (unittest.TestCase):' in \n{0}".format(cont))

        cloud = os.path.join(path, "data")
        url = "http://localhost:8094/localfile/tag-cloud.html?path=%s" % cloud
        fLOG(url)
        cont = get_url_content_timeout(url)
        assert 'd3.json("data.json"' in cont

        url = "http://localhost:8094/localfile/tag-cloud.html?path=%s&keep=True" % cloud
        fLOG(url)
        cont = get_url_content_timeout(url)
        assert 'd3.json("data.json"' in cont
        assert len(SimpleHandler.queue_pathes) > 0

        thread.shutdown()
        assert not thread.is_alive()
Example #2
0
    def test_custom_server_location(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        fold = os.path.abspath(os.path.split(__file__)[0])
        dbfile = os.path.join(fold, "out_custom_server2.db3")
        if os.path.exists(dbfile):
            os.remove(dbfile)

        db = Database(dbfile, LOG=fLOG)
        df = pandas.DataFrame([{"name": "xavier", "module": "pyrsslocal"}])
        db.connect()
        db.import_dataframe(df, "example")
        db.close()

        server = CustomDBServer(('localhost', 8099), dbfile, CustomDBServerHandler,
                                root=os.path.join(fold, "data"))
        thread = CustomDBServer.run_server(server, dbfile=dbfile, thread=True,
                                           extra_path=os.path.join(fold, "data"))

        url = "http://localhost:8099/index.html"
        cont = get_url_content_timeout(url)
        assert len(cont) > 0
        assert "unittest" in cont

        thread.shutdown()
        assert not thread.is_alive()
        assert os.path.exists(dbfile)
Example #3
0
    def test_server_start_run(self):
        """
        if this test fails, the unit test is stuck, you need to stop the program yourself
        """
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        path = os.path.abspath(os.path.split(__file__)[0])
        dbfile = os.path.join(path, "data", "database_rss.db3")

        server = RSSServer(('localhost', 8093), dbfile, fLOG=fLOG)
        thread = RSSServer.run_server(server, dbfile, thread=True, fLOG=fLOG)

        fLOG("fetching first url")
        url = "http://localhost:8093/"
        cont = get_url_content_timeout(url)
        if "Traceback" in cont:
            fLOG(cont)
        assert "Traceback" not in cont
        assert len(cont) > 0
        assert "RSS" in cont
        assert "XD blog" in cont

        url = "http://localhost:8093/rss_status.html"
        cont = get_url_content_timeout(url)
        if "Traceback" in cont:
            fLOG(cont)
        assert "Traceback" not in cont
        assert len(cont) > 0
        assert "RSS" in cont
        if "interesting" not in cont:
            raise Exception(cont)

        url = "http://localhost:8093/rss_search.html?searchterm=pypi&usetag=usetag"
        cont = get_url_content_timeout(url)
        if "Traceback" in cont:
            fLOG(cont)
        assert "Traceback" not in cont
        assert len(cont) > 0
        assert "RSS" in cont
        if "PyPI" not in cont:
            fLOG(cont)
            assert False
        # if "added" not in cont:
        #    fLOG(cont)
        #    assert False
        assert "Mozilla Continues" not in cont

        fLOG("fetching first url")
        url = "http://localhost:8093/rss_search.html?searchterm=military"
        cont = get_url_content_timeout(url)
        if "Traceback" in cont:
            fLOG(cont)
        assert "Traceback" not in cont
        assert len(cont) > 0
        assert "RSS" in cont
        assert "interesting" not in cont
        assert "Military" in cont
        assert "Mozilla Continues" not in cont

        thread.shutdown()
        assert not thread.is_alive()