Esempio n. 1
0
def test_putGetEntry():
    """
    Test adding and getting a database entry.
    """
    dbEnv = dbing.setupTestDbEnv()

    ser = "{'reputer': 'Søren', 'reputee': 'Kierkegaard', 'repute': {'rid': 'dda6555f-21c8-45ff-9633-f9b5cdc59f45', " \
          "'feature': 'clarity', 'value': 5}})"
    dat = json.dumps(ser)
    key = "søren-dda6555f-21c8-45ff-9633-f9b5cdc59f45"

    dbing.putEntry(key, dat)
    gser = dbing.getEntry(key)
    assert gser == ser

    cleanupTmpBaseDir(dbEnv.path())
    print("test/db/test_dbing: test_putGetEntry() \033[92mPASSED\033[0m")
Esempio n. 2
0
def test_reputationResourceOnGet(app):
    """
    Test GET to reputation endpoint.

        Parameters:
        app - WSGI instance
    """
    priming.setupTest()
    dbing.setupTestDbEnv()

    response = app.simulate_get('/reputation/')
    assert response.content == b'{"title":"Error","description":"A valid query is required."}'
    assert response.status == falcon.HTTP_400

    response = app.simulate_get('/reputation/søren')
    assert response.content == b'{"title":"Error","description":"Reputee could not be found."}'
    assert response.status == falcon.HTTP_400

    ser = json.dumps({
        "reputee": "søren",
        "clout": {
            "score": 5.0
        },
        "confidence": 1,
        "reach": {
            "score": 5.0,
            "confidence": 1
        },
        "clarity": {
            "score": 5.0,
            "confidence": 1
        }
    })
    dbing.putEntry("søren", ser, dbn="reputation")

    response = app.simulate_get('/reputation/søren')
    assert response.content == b'{"reputee":"s\\u00f8ren","clout":{"score":5.0},"confidence":1,"reach":{"score":5.0,' \
                               b'"confidence":1},"clarity":{"score":5.0,"confidence":1}}'
    assert response.status == falcon.HTTP_200

    helping.cleanupTmpBaseDir(dbing.gDbDirPath)

    print(
        "test/end/test_ending: test_reputationResourceOnGet() \033[92mPASSED\033[0m"
    )
Esempio n. 3
0
def test_getEntryKeys():
    """
    Test getting all database keys.
    """
    dbEnv = dbing.setupTestDbEnv()

    ser = "{'reputer': 'Søren', 'reputee': 'Kierkegaard', 'repute': {'rid': 'dda6555f-21c8-45ff-9633-f9b5cdc59f45', " \
           "'feature': 'clarity', 'value': 5}})"
    dat = json.dumps(ser)
    key1 = "søren-dda6555f-21c8-45ff-9633-f9b5cdc59f45"
    dbing.putEntry(key1, dat)

    ser = "{'reputer': 'Henrik', 'reputee': 'Ibsen', 'repute': {'rid': 'dda6555f-21c8-45ff-9633-f9b5cdc59f46', " \
           "'feature': 'clarity', 'value': 5}})"
    dat = json.dumps(ser)
    key2 = "henrik-dda6555f-21c8-45ff-9633-f9b5cdc59f46"
    dbing.putEntry(key2, dat)

    ser = "{'reputer': 'Inger', 'reputee': 'Christiansen', 'repute': {'rid': 'dda6555f-21c8-45ff-9633-f9b5cdc59f47', " \
           "'feature': 'clarity', 'value': 5}})"
    dat = json.dumps(ser)
    key3 = "inger-dda6555f-21c8-45ff-9633-f9b5cdc59f47"
    dbing.putEntry(key3, dat)

    glist = dbing.getEntryKeys()
    assert [key2, key3, key1]

    cleanupTmpBaseDir(dbEnv.path())
    print("test/db/test_dbing: test_getEntryKeys() \033[92mPASSED\033[0m")
Esempio n. 4
0
def test_deleteEntry():
    """
    Test deleting a database entry.
    """
    dbEnv = dbing.setupTestDbEnv()

    ser = "{'reputer': 'Søren', 'reputee': 'Kierkegaard', 'repute': {'rid': 'dda6555f-21c8-45ff-9633-f9b5cdc59f45', " \
          "'feature': 'clarity', 'value': 5}})"
    dat = json.dumps(ser)
    key = "s\u00f8ren-dda6555f-21c8-45ff-9633-f9b5cdc59f45"

    dbing.putEntry(key, dat, dbn="raw")
    gser = dbing.getEntry(key, dbn="raw")
    assert gser == ser

    dbing.deleteEntry(key, dbn="raw")

    with pytest.raises(dbing.DatabaseError):
        dbing.getEntry(key)

    cleanupTmpBaseDir(dbEnv.path())
    print("test/db/test_dbing: test_deleteEntry() \033[92mPASSED\033[0m")