示例#1
0
def add_ndt_test(request: Request,
                 test: schemas.NdtTestOoni,
                 test_base: schemas.TestBase = schemas.TestBase(),
                 db: Session = Depends(get_db)):
    try:
        ip = request.client.host
        db_test_base = queries.create_test_base(db, test_base, ip)
        queries.create_specific_test(db, test, models.NdtTestOoni,
                                     db_test_base.id)
    except Exception as e:
        message = "Error adding results to ndt tests table"
        logging.error(message, exc_info=e)
        return JSONResponse(status_code=404, content={"message": message})
示例#2
0
def add_protocol_test(request: Request,
                      test: List[schemas.ProtocolTest],
                      test_base: schemas.TestBase = schemas.TestBase(),
                      db: Session = Depends(get_db)):
    try:
        ip = request.client.host
        db_test_base = queries.create_test_base(db, test_base, ip)
        db_test_base_id = db_test_base.id
        for protocol_test in test:
            queries.create_specific_test(db, protocol_test,
                                         models.ProtocolTest, db_test_base_id)
    except Exception as e:
        message = "Error adding results to protocol tests table"
        logging.error(message, exc_info=e)
        return JSONResponse(status_code=404, content={"message": message})
示例#3
0
def add_web_test_ooni(
    request: Request,
    web_test_ooni: schemas.WebTestOoni,
    tcp_connect_web_tests_ooni: List[schemas.TcpConnectWebTestOoni] = [],
    test_base: schemas.TestBase = schemas.TestBase(),
    db: Session = Depends(get_db)):
    try:
        ip = request.client.host
        db_test_base = queries.create_test_base(db, test_base, ip)
        db_web_test_ooni_id = queries.create_specific_test(
            db, web_test_ooni, models.WebTestOoni, db_test_base.id).id
        for tcp_connect in tcp_connect_web_tests_ooni:
            queries.create_specific_test(db, tcp_connect,
                                         models.TcpConnectWebTestOoni,
                                         db_web_test_ooni_id)
    except Exception as e:
        message = "Error adding results to web tests"
        logging.error(message, exc_info=e)
        return JSONResponse(status_code=404, content={"message": message})
示例#4
0
def add_devices_tests(request: Request,
                      test: List[schemas.DevicesTest],
                      test_base: schemas.TestBase = schemas.TestBase(),
                      db: Session = Depends(get_db)):
    try:
        ip = request.client.host
        db_test_base_id = None
        manuf_devices = []
        for devices_test in test:
            if db_test_base_id is None:
                db_test_base_id = queries.create_test_base(db, test_base,
                                                           ip).id
            manuf_device = queries.get_manuf(db, devices_test)
            queries.create_specific_test(db, devices_test, models.DevicesTest,
                                         db_test_base_id)
            manuf_devices.append(manuf_device)
        return manuf_devices
    except Exception as e:
        message = "Error adding results to devices tests table"
        logging.error(message, exc_info=e)
        return JSONResponse(status_code=404, content={"message": message})