Exemplo n.º 1
0
def test_parallel_add_single_document():
    # mock os.getenv("SEED")
    os.getenv = lambda key, default=None: "42"
    with TestSpace() as key:
        nut0, nut1 = api.Nut(key=key), api.Nut(key=key)
        assert nut0.store != nut1.store
        assert nut0.store.r != nut1.store.r
        assert nut0.store.key == nut1.store.key
        assert nut0.addDocument("0", "a b c") is None
        assert len(nut1.similarById("0")) == 1
        assert nut0.status()["_end"] == 1
        assert nut1.status()["_end"] == 1
Exemplo n.º 2
0
def test_parallel_add_duplicate_document():
    # mock os.getenv("SEED")
    os.getenv = lambda key, default=None: "42"
    with TestSpace() as key:
        nut0, nut1 = api.Nut(key=key), api.Nut(key=key)
        assert nut0.store != nut1.store
        assert nut0.store.r != nut1.store.r
        assert nut0.store.key == nut1.store.key
        assert nut0.addDocument("0", "a b c") is None
        _, code = nut1.addDocument("0", "x y z")
        assert code == 409
        assert nut0.status()["_end"] == 1
        assert nut1.status()["_end"] == 1
Exemplo n.º 3
0
def test_add_max_length_id():
    with MockRedis():
        nut = api.Nut()
        id_ = "0" * 42
        assert nut.addDocument(id_, "a b c") is None
        assert len(nut.similarById(id_)) == 1
        assert nut.status()["_end"] == 1
Exemplo n.º 4
0
def test_add_too_long_id():
    with MockRedis():
        nut = api.Nut()
        id_ = "0" * 128
        _, code = nut.addDocument(id_, "a b c")
        assert code == 400
        assert nut.status()["_end"] == 0
Exemplo n.º 5
0
def test_add_duplicate_document():
    with MockRedis():
        nut = api.Nut()
        assert nut.addDocument("0", "a b c") is None
        assert len(nut.similarById("0")) == 1
        assert nut.status()["_end"] == 1
        _, code = nut.addDocument("0", "x y z")
        assert code == 409
        assert nut.status()["_end"] == 1
Exemplo n.º 6
0
def test_compare0():
    with MockRedis():
        nut = api.Nut()
        assert nut.addDocument("0", "a b c") is None
        assert len(nut.similarByContent("a b c")) == 1
Exemplo n.º 7
0
def test_get_too_long_id():
    with MockRedis():
        nut = api.Nut()
        id_ = "0" * 128
        _, code = nut.similarById(id_)
        assert code == 404
Exemplo n.º 8
0
def test_add_single_document():
    with MockRedis():
        nut = api.Nut()
        assert nut.addDocument("0", "a b c") is None
        assert len(nut.similarById("0")) == 1
        assert nut.status()["_end"] == 1
Exemplo n.º 9
0
def test_get_unknown_document():
    with MockRedis():
        nut = api.Nut()
        _, code = nut.similarById("0")
        assert code == 404
Exemplo n.º 10
0
import os

import connexion

import nutai.api as api

app = connexion.FlaskApp(__name__)

# setup operationIds
nut = api.Nut()
api.similarById = nut.similarById
api.similarByContent = nut.similarByContent
api.addDocument = nut.addDocument
api.addDocuments = nut.addDocuments
api.status = nut.status

app.add_api('nutai.yaml')

app.run(port=os.getenv('PORT'))