Skip to content

Commit

Permalink
OPAL-455v3 (#106)
Browse files Browse the repository at this point in the history
* change files

* fixed version

* changes to test_pantry

* remove comments

* fixed imports

---------

Co-authored-by: pat <quoc-anh,nguyen@us.af.mil>
  • Loading branch information
pn-usaf and pat committed Jul 26, 2024
1 parent b928e3a commit 81fa4d6
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 81 deletions.
2 changes: 1 addition & 1 deletion weave/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .pantry_factory import create_pantry
from .mongo_loader import MongoLoader

__version__ = "1.10.0"
__version__ = "1.10.1"

__all__ = [
"Basket",
Expand Down
78 changes: 78 additions & 0 deletions weave/tests/test_pantry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import re
import shutil
import sys
import tempfile
import uuid as uuid_lib
import warnings
Expand All @@ -16,6 +17,7 @@
from fsspec.implementations.local import LocalFileSystem

from weave.basket import Basket
from weave .config import get_mongo_db
from weave.index.create_index import create_index_from_fs
from weave.index.index_pandas import IndexPandas
from weave.pantry import Pantry
Expand Down Expand Up @@ -763,3 +765,79 @@ def test_s3fs_no_connection_error():
file_system=s3f,
pantry_path="fake-pantry",
)


# Skip tests if pymongo is not installed.
@pytest.mark.skipif(
"pymongo" not in sys.modules or not os.environ.get("MONGODB_HOST", False),
reason="Pymongo required for this test",
)
def test_upload_basket_mongo(test_pantry):
"""Testing pantry.upload_basket(), expected to update the collections.
"""
fs = test_pantry.file_system
pantry_path = test_pantry.pantry_path
mongo_client = get_mongo_db()

pantry = Pantry(IndexPandas,
pantry_path=pantry_path,
mongo_client=mongo_client,
file_system=fs)

with tempfile.NamedTemporaryFile(delete=False) as temp_file:
uuid = pantry.upload_basket(
upload_items=[{'path':temp_file.name,'stub':False}],
basket_type="test-1",
metadata = {'Data Type':'text'}
).values.tolist()[0][0]

temp_file.close()
os.unlink(temp_file.name)

collections = ("supplement", "metadata", "manifest")
mongo_db = mongo_client[pantry.pantry_path]
query = {'uuid': uuid}

for e in collections:
assert uuid == mongo_db[e].find_one(query,{'_id':0,'uuid':1})['uuid']
mongo_db[e].delete_one(query)


#Skip tests if pymongo is not installed.
@pytest.mark.skipif(
"pymongo" not in sys.modules or not os.environ.get("MONGODB_HOST", False),
reason="Pymongo required for this test",
)
def test_delete_basket_mongo(test_pantry):
"""Testing pantry.delete_basket(), expected to update the collections.
"""
fs = test_pantry.file_system
pantry_path = test_pantry.pantry_path
mongo_client = get_mongo_db()

pantry = Pantry(IndexPandas,
pantry_path=pantry_path,
mongo_client=mongo_client,
file_system=fs)

with tempfile.NamedTemporaryFile(delete=False) as temp_file:
uuid = pantry.upload_basket(
upload_items=[{'path':temp_file.name,'stub':False}],
basket_type="test-1",
metadata = {'Data Type':'text'}
).values.tolist()[0][0]

temp_file.close()
os.unlink(temp_file.name)

query = {'uuid': uuid}
collections = ("supplement", "metadata", "manifest")
mongo_db = mongo_client[pantry.pantry_path]

for e in collections:
assert uuid == mongo_db[e].find_one(query,{'_id':0,'uuid':1})['uuid']

pantry.delete_basket(uuid)

for e in collections:
assert mongo_db[e].find_one(query) is None
80 changes: 0 additions & 80 deletions weave/tests/test_uploader.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""Pytests for the uploader functionality."""

import json
import os
import sys
import tempfile
import time
import uuid
from datetime import datetime
Expand All @@ -16,7 +13,6 @@

import weave
from weave import Pantry, IndexPandas, IndexSQLite
from weave.config import get_mongo_db
from weave.tests.pytest_resources import PantryForTest, file_path_in_list
from weave.tests.pytest_resources import get_file_systems
from weave.upload import (
Expand Down Expand Up @@ -1456,79 +1452,3 @@ def test_upload_from_s3fs(test_basket):
s3.rm(minio_path,recursive=True)
if local_fs.exists(pantry_2.index.db_path):
local_fs.rm(pantry_2.index.db_path)


# Skip tests if pymongo is not installed.
@pytest.mark.skipif(
"pymongo" not in sys.modules or not os.environ.get("MONGODB_HOST", False),
reason="Pymongo required for this test",
)
def test_upload_basket_mongo(test_basket):
"""Testing pantry.upload_basket(), expected to update the collections.
"""
fs = test_basket.file_system
pantry_path = test_basket.pantry_path
mongo_client = get_mongo_db()

pantry = Pantry(IndexPandas,
pantry_path=pantry_path,
mongo_client=mongo_client,
file_system=fs)

with tempfile.NamedTemporaryFile(delete=False) as temp_file:
uuid = pantry.upload_basket(
upload_items=[{'path':temp_file.name,'stub':False}],
basket_type="test-1",
metadata = {'Data Type':'text'}
).values.tolist()[0][0]

temp_file.close()
os.unlink(temp_file.name)

collections = ("supplement", "metadata", "manifest")
mongo_db = mongo_client[pantry.pantry_path]
query = {'uuid': uuid}

for e in collections:
assert uuid == mongo_db[e].find_one(query,{'_id':0,'uuid':1})['uuid']
mongo_db[e].delete_one(query)


# Skip tests if pymongo is not installed.
@pytest.mark.skipif(
"pymongo" not in sys.modules or not os.environ.get("MONGODB_HOST", False),
reason="Pymongo required for this test",
)
def test_delete_basket_mongo(test_basket):
"""Testing pantry.delete_basket(), expected to update the collections.
"""
fs = test_basket.file_system
pantry_path = test_basket.pantry_path
mongo_client = get_mongo_db()

pantry = Pantry(IndexPandas,
pantry_path=pantry_path,
mongo_client=mongo_client,
file_system=fs)

with tempfile.NamedTemporaryFile(delete=False) as temp_file:
uuid = pantry.upload_basket(
upload_items=[{'path':temp_file.name,'stub':False}],
basket_type="test-1",
metadata = {'Data Type':'text'}
).values.tolist()[0][0]

temp_file.close()
os.unlink(temp_file.name)

query = {'uuid': uuid}
collections = ("supplement", "metadata", "manifest")
mongo_db = mongo_client[pantry.pantry_path]

for e in collections:
assert uuid == mongo_db[e].find_one(query,{'_id':0,'uuid':1})['uuid']

pantry.delete_basket(uuid)

for e in collections:
assert mongo_db[e].find_one(query) is None

0 comments on commit 81fa4d6

Please sign in to comment.