Esempio n. 1
0
def test_delete_test_run(connectionString, exampleJunitString):
    engine = create_engine(connectionString)
    engine.connect()
    session = __scopedSession(engine)
    database = JunitDatabase(engine, session)
    database.createSchema()

    testRuns = loadJunitTestRuns(exampleJunitString)
    database.insertTestRuns(testRuns, {"label1": "value1"})

    testRuns = session.query(JunitTestRun).all()
    testRunIds = []
    for testRun in testRuns:
        testRunIds.append(testRun.id)
    assert 2 in testRunIds
    assert session.query(Label).filter(Label.testRun == 2).count() > 0

    database.deleteTestRun(2)

    testRuns = session.query(JunitTestRun).all()
    testRunIds = []
    for testRun in testRuns:
        testRunIds.append(testRun.id)
    assert 2 not in testRunIds
    assert session.query(Label).filter(Label.testRun == 2).count() == 0
Esempio n. 2
0
def test_create_schema(connectionString):
    engine = create_engine(connectionString)
    engine.connect()
    session = __scopedSession(engine)
    database = JunitDatabase(engine, session)
    database.createSchema()
    engine.dispose()

    expectedTables = ["test_run"]
    engine = create_engine(connectionString)
    inspector = inspect(engine)
    for tableName in expectedTables:
        assert tableName in inspector.get_table_names()
    engine.dispose()
Esempio n. 3
0
def create_app(config={}):
    app = connexion.App(__name__, specification_dir='./')
    from junitsimplestorage.database import JunitDatabase
    import junitsimplestorage.rest as rest
    import junitsimplestorage.gui as gui

    finalConfig = getAppConfig()
    finalConfig.update(config)
    app.app.config.update(finalConfig)
    db = SQLAlchemy(app.app)
    junitDatabase = JunitDatabase(db.engine, db.session)
    junitDatabase.createSchema()
    rest.junitDatabase = junitDatabase
    gui.junitDatabase = junitDatabase
    app.add_api('swagger.yml')
    app.app.register_blueprint(gui.bp)

    return app.app
Esempio n. 4
0
def test_max_time(connectionString, exampleJunitString):
    engine = create_engine(connectionString)
    engine.connect()
    session = __scopedSession(engine)
    database = JunitDatabase(engine, session)
    database.createSchema()

    testRuns = loadJunitTestRuns(exampleJunitString)
    database.insertTestRuns(testRuns)

    maxTime = database.maxTime()
    assert maxTime != None
Esempio n. 5
0
def test_number_of_test_runs(connectionString, exampleJunitString):
    engine = create_engine(connectionString)
    engine.connect()
    session = __scopedSession(engine)
    database = JunitDatabase(engine, session)
    database.createSchema()

    testRuns = loadJunitTestRuns(exampleJunitString)
    numberOfTestRuns = len(testRuns)
    database.insertTestRuns(testRuns)

    assert database.numberOfTestRuns() == numberOfTestRuns
Esempio n. 6
0
def test_query_by_timestamp(connectionString, exampleJunitString):
    engine = create_engine(connectionString)
    engine.connect()
    session = __scopedSession(engine)
    database = JunitDatabase(engine, session)
    database.createSchema()

    testRuns = loadJunitTestRuns(exampleJunitString)
    database.insertTestRuns(testRuns)

    testRuns = database.queryTestRuns({
        "minTimeDate": "2019-11-01 10:00:00",
        "maxTimeDate": "2019-11-30 20:15:05"
    })
    assert len(testRuns) == 4
Esempio n. 7
0
def test_query_by_name(connectionString, exampleJunitString):
    engine = create_engine(connectionString)
    engine.connect()
    session = __scopedSession(engine)
    database = JunitDatabase(engine, session)
    database.createSchema()

    testRuns = loadJunitTestRuns(exampleJunitString)
    database.insertTestRuns(testRuns)

    testRuns = database.queryTestRuns(
        {"name": ["test_something1", "test_something3"]})
    assert len(testRuns) == 2

    engine.dispose()
Esempio n. 8
0
def test_query_by_timestamp(connectionString, exampleJunitString):
    engine = create_engine(connectionString)
    engine.connect()
    session = __scopedSession(engine)
    database = JunitDatabase(engine, session)
    database.createSchema()

    testRuns = loadJunitTestRuns(exampleJunitString)
    database.insertTestRuns(testRuns)

    testRuns = database.queryTestRuns({
        "timeIsLower": 2.5,
        "timeIsHigher": 1.0
    })
    assert len(testRuns) == 1
    assert testRuns[0].name == "test_something2"
Esempio n. 9
0
def test_query_by_timestamp(connectionString, exampleJunitString):
    engine = create_engine(connectionString)
    engine.connect()
    session = __scopedSession(engine)
    database = JunitDatabase(engine, session)
    database.createSchema()

    testRuns = loadJunitTestRuns(exampleJunitString)
    database.insertTestRuns(testRuns)

    minTimeDate = datetime.datetime.now() - datetime.timedelta.days(1)
    maxTimeDate = datetime.datetime.now() + datetime.timedelta.days(1)
    testRuns = database.queryTestRuns({
        "minImportTime": minTimeDate,
        "maxImportTime": maxTimeDate
    })
    assert len(testRuns) > 0
Esempio n. 10
0
def test_save_test_runs(connectionString, exampleJunitString):
    engine = create_engine(connectionString)
    engine.connect()
    session = __scopedSession(engine)
    database = JunitDatabase(engine, session)
    database.createSchema()

    testRuns = loadJunitTestRuns(exampleJunitString)
    database.insertTestRuns(testRuns)
    engine.dispose()

    engine = create_engine(connectionString)
    Session = sessionmaker(bind=engine)
    session = Session()
    numberOfTestRuns = session.query(JunitTestRun).count()
    assert numberOfTestRuns > 0
    engine.dispose()
Esempio n. 11
0
def test_save_test_runs_with_labels(connectionString, exampleJunitString):
    engine = create_engine(connectionString)
    engine.connect()
    session = __scopedSession(engine)
    database = JunitDatabase(engine, session)
    database.createSchema()

    labels = {"key1": "value1", "key2": "value2"}
    testRuns = loadJunitTestRuns(exampleJunitString)
    database.insertTestRuns(testRuns, labels)
    engine.dispose()

    engine = create_engine(connectionString)
    engine.connect()
    engine = database.getEngine()
    Session = sessionmaker(bind=engine)
    session = Session()
    numberOfTestRuns = session.query(JunitTestRun).count()
    assert numberOfTestRuns > 0
    numberOfLabels = session.query(Label).count()
    assert numberOfLabels > 0
    engine.dispose()
Esempio n. 12
0
def test_query_by_labels(connectionString, exampleJunitString):
    engine = create_engine(connectionString, echo=True)
    engine.connect()
    session = __scopedSession(engine)
    database = JunitDatabase(engine, session)
    database.createSchema()

    testRuns = loadJunitTestRuns(exampleJunitString)
    numberOfTestRuns = len(testRuns)
    database.insertTestRuns(testRuns)
    testRuns = loadJunitTestRuns(exampleJunitString)
    database.insertTestRuns(testRuns, {"label1": "value1"})
    testRuns = loadJunitTestRuns(exampleJunitString)
    database.insertTestRuns(testRuns, {"label1": "value1", "label2": "value2"})

    testRuns = database.queryTestRuns({"labels": {
        "label1": "value1",
    }})
    assert len(testRuns) == 2 * numberOfTestRuns

    testRuns = database.queryTestRuns(
        {"labels": {
            "label1": "value1",
            "label2": "value2",
        }})
    assert len(testRuns) == numberOfTestRuns