Example #1
0
def test_adding_an_intercept():
    intercepts = Intercepts()
    intercept = Intercept("my-query")
    result = intercepts.add(intercept)
    intercept_list = intercepts.all()
    assert result is True
    assert intercept_list == [intercept.to_json()]
Example #2
0
def test_adding_an_intercept_with_an_existing_id():
    intercepts = Intercepts()
    intercept = Intercept("my-query")
    result = intercepts.add(intercept)

    new_intercept = Intercept("some-other-query", id=intercept.id)
    result = intercepts.add(new_intercept)
    assert result is False

    intercept_list = intercepts.all()
    assert intercept_list == [intercept.to_json()]
Example #3
0
def start() -> None:
    version_check.check_pyopenssl_version()

    AsyncIOMainLoop().install()
    loop = asyncio.get_event_loop()

    intercepts = Intercepts()
    proxy = Proxy(loop, UpdatesHandler.broadcast)

    web_options, server = configuration()
    master = Master(web_options, loop, proxy, server)

    web_application = Application(master, intercepts)
    http_server = tornado.httpserver.HTTPServer(web_application)
    http_server.listen(5000, "127.0.0.1")

    tornado_loop = tornado.ioloop.IOLoop.instance()
    tornado_loop.add_callback(master.start)
    tornado.ioloop.PeriodicCallback(lambda: master.tick(timeout=0), 5).start()

    try:
        print("Starting proxy server")
        tornado_loop.start()
    except (KeyboardInterrupt, RuntimeError):
        pass
Example #4
0
def test_deleting_an_intercept():
    intercepts = Intercepts()
    intercept = Intercept("my-query")
    intercepts.add(intercept)
    result = intercepts.delete(intercept.id)
    intercept_list = intercepts.all()
    assert result is True
    assert intercept_list == []
Example #5
0
def test_updating_a_non_existing_intercept():
    intercepts = Intercepts()
    intercept = Intercept("my-query")
    intercepts.add(intercept)

    updated = Intercept("update-query", id="some-other-id")
    result = intercepts.update(updated)

    intercept_list = intercepts.all()
    assert result is False
    assert intercept_list == [intercept.to_json()]
Example #6
0
def test_updating_an_intercept():
    intercepts = Intercepts()
    intercept = Intercept("my-query")
    intercepts.add(intercept)

    updated = Intercept("update-query", id=intercept.id)
    result = intercepts.update(updated)

    intercept_list = intercepts.all()
    assert result is True
    assert intercept_list == [updated.to_json()]
Example #7
0
def app():
    intercepts = Intercepts()
    return Application(intercepts=intercepts)
Example #8
0
def test_finding_a_non_existing_intercept():
    intercepts = Intercepts()
    assert intercepts.find_by_id("non-existing-id") is None
Example #9
0
def test_finding_an_intercept():
    intercepts = Intercepts()
    intercept = Intercept("my-query")
    result = intercepts.add(intercept)
    assert intercepts.find_by_id(intercept.id) == intercept
Example #10
0
def test_intercepts_all_returns_empty_list():
    intercepts = Intercepts()
    intercept_list = intercepts.all()
    assert intercept_list == []
Example #11
0
def test_deleting_non_existing_intercept():
    intercepts = Intercepts()
    result = intercepts.delete("non-existing-id")
    intercept_list = intercepts.all()
    assert result is False
    assert intercept_list == []