Esempio 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.DocNut(NullModel(), key=key), api.DocNut(NullModel(),
                                                                  key=key)
        assert nut0.store != nut1.store
        assert nut0.store.r != nut1.store.r
        assert nut0.store.key == nut1.store.key
        assert nut0.add_document("0", "a b c") is None
        assert len(nut1.similar_by_id("0")) == 1
        assert nut0.status()["_end"] == 1
        assert nut1.status()["_end"] == 1
Esempio 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.DocNut(NullModel(), key=key), api.DocNut(NullModel(),
                                                                  key=key)
        assert nut0.store != nut1.store
        assert nut0.store.r != nut1.store.r
        assert nut0.store.key == nut1.store.key
        assert nut0.add_document("0", "a b c") is None
        _, code = nut1.add_document("0", "x y z")
        assert code == 409
        assert nut0.status()["_end"] == 1
        assert nut1.status()["_end"] == 1
Esempio n. 3
0
def test_add_to_force_resize():
    with MockRedis():
        nut = api.DocNut(NullModel())
        size = nut.store.ids.shape[0]
        for i in range(size + 1):
            assert nut.add_document(str(i), "filler") is None
        assert size < nut.store.ids.shape[0]
Esempio n. 4
0
def test_add_max_length_id():
    with MockRedis():
        nut = api.DocNut(NullModel())
        id_ = "0" * 42
        assert nut.add_document(id_, "a b c") is None
        assert len(nut.similar_by_id(id_)) == 1
        assert nut.status()["_end"] == 1
Esempio n. 5
0
def test_add_too_long_id():
    with MockRedis():
        nut = api.DocNut(NullModel())
        id_ = "0" * 128
        _, code = nut.add_document(id_, "a b c")
        assert code == 400
        assert nut.status()["_end"] == 0
Esempio n. 6
0
def test_add_duplicate_document():
    with MockRedis():
        nut = api.DocNut(NullModel())
        assert nut.add_document("0", "a b c") is None
        assert len(nut.similar_by_id("0")) == 1
        assert nut.status()["_end"] == 1
        _, code = nut.add_document("0", "x y z")
        assert code == 409
        assert nut.status()["_end"] == 1
Esempio n. 7
0
def create_app(model):
    app = connexion.FlaskApp(__name__)

    # setup operationIds
    nut = api.DocNut(model)
    api.similarById = nut.similar_by_id
    api.similarByContent = nut.similar_by_content
    api.addDocument = nut.add_document
    api.addDocuments = nut.add_documents
    api.status = nut.status

    app.add_api('doc_nut.yaml')

    return app
Esempio n. 8
0
def test_get_too_long_id():
    with MockRedis():
        nut = api.DocNut(NullModel())
        id_ = "0" * 128
        _, code = nut.similar_by_id(id_)
        assert code == 404
Esempio n. 9
0
def test_add_single_document():
    with MockRedis():
        nut = api.DocNut(NullModel())
        assert nut.add_document("0", "a b c") is None
        assert len(nut.similar_by_id("0")) == 1
        assert nut.status()["_end"] == 1
Esempio n. 10
0
def test_get_unknown_document():
    with MockRedis():
        nut = api.DocNut(NullModel())
        _, code = nut.similar_by_id("0")
        assert code == 404
Esempio n. 11
0
def test_compare0():
    with MockRedis():
        nut = api.DocNut(NullModel())
        assert nut.add_document("0", "a b c") is None
        assert len(nut.similar_by_content("a b c")) == 1