-
Notifications
You must be signed in to change notification settings - Fork 96
PLAT-165: Migrate test_s3.py #1118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+197
−17
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5d65db3
First pass at migrating test_s3
ethho eb9d469
Merge branch 'dev-tests' into dev-tests-test-s3
ethho d9a592c
Merge branch 'dev-tests-test-s3' into dev-tests-plat-165
ethho 874c9cb
test_s3 uses bucket setup fixtures
ethho 5568954
Format with black
ethho 217945b
Merge branch 'dev-tests-plat-145' into dev-tests-plat-165
ethho f993076
Change scope of raises block
ethho 3cd99f1
Move schema_ext to conftest
ethho a28e1ba
Merge branch 'dev-tests-plat-145' into dev-tests-plat-165
ethho 46fdb3c
Merge remote-tracking branch 'upstream/dev-tests' into dev-tests-plat…
ethho 3b5047b
Add @A-Baji suggestions
ethho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| """ | ||
| A schema for testing external attributes | ||
| """ | ||
|
|
||
| import tempfile | ||
| import inspect | ||
| import datajoint as dj | ||
| from . import PREFIX, CONN_INFO, S3_CONN_INFO | ||
| import numpy as np | ||
|
|
||
|
|
||
| class Simple(dj.Manual): | ||
| definition = """ | ||
| simple : int | ||
| --- | ||
| item : blob@local | ||
| """ | ||
|
|
||
|
|
||
| class SimpleRemote(dj.Manual): | ||
| definition = """ | ||
| simple : int | ||
| --- | ||
| item : blob@share | ||
| """ | ||
|
|
||
|
|
||
| class Seed(dj.Lookup): | ||
| definition = """ | ||
| seed : int | ||
| """ | ||
| contents = zip(range(4)) | ||
|
|
||
|
|
||
| class Dimension(dj.Lookup): | ||
| definition = """ | ||
| dim : int | ||
| --- | ||
| dimensions : blob | ||
| """ | ||
| contents = ([0, [100, 50]], [1, [3, 4, 8, 6]]) | ||
|
|
||
|
|
||
| class Image(dj.Computed): | ||
| definition = """ | ||
| # table for storing | ||
| -> Seed | ||
| -> Dimension | ||
| ---- | ||
| img : blob@share # objects are stored as specified by dj.config['stores']['share'] | ||
| neg : blob@local # objects are stored as specified by dj.config['stores']['local'] | ||
| """ | ||
|
|
||
| def make(self, key): | ||
| np.random.seed(key["seed"]) | ||
| img = np.random.rand(*(Dimension() & key).fetch1("dimensions")) | ||
| self.insert1(dict(key, img=img, neg=-img.astype(np.float32))) | ||
|
|
||
|
|
||
| class Attach(dj.Manual): | ||
| definition = """ | ||
| # table for storing attachments | ||
| attach : int | ||
| ---- | ||
| img : attach@share # attachments are stored as specified by: dj.config['stores']['raw'] | ||
| txt : attach # attachments are stored directly in the database | ||
| """ | ||
|
|
||
|
|
||
| class Filepath(dj.Manual): | ||
| definition = """ | ||
| # table for file management | ||
| fnum : int # test comment containing : | ||
| --- | ||
| img : filepath@repo # managed files | ||
| """ | ||
|
|
||
|
|
||
| class FilepathS3(dj.Manual): | ||
| definition = """ | ||
| # table for file management | ||
| fnum : int | ||
| --- | ||
| img : filepath@repo-s3 # managed files | ||
| """ | ||
|
|
||
|
|
||
| LOCALS_EXTERNAL = {k: v for k, v in locals().items() if inspect.isclass(v)} | ||
| __all__ = list(LOCALS_EXTERNAL) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import pytest | ||
| import urllib3 | ||
| import certifi | ||
| from .schema_external import SimpleRemote | ||
| from datajoint.errors import DataJointError | ||
| from datajoint.hash import uuid_from_buffer | ||
| from datajoint.blob import pack | ||
| from . import S3_CONN_INFO | ||
| from minio import Minio | ||
|
|
||
|
|
||
| class TestS3: | ||
| def test_connection(self, http_client, minio_client): | ||
| assert minio_client.bucket_exists(S3_CONN_INFO["bucket"]) | ||
|
|
||
| def test_connection_secure(self, minio_client): | ||
| assert minio_client.bucket_exists(S3_CONN_INFO["bucket"]) | ||
|
|
||
| def test_remove_object_exception(self, schema_ext): | ||
| # https://github.com/datajoint/datajoint-python/issues/952 | ||
|
|
||
| # Insert some test data and remove it so that the external table is populated | ||
| test = [1, [1, 2, 3]] | ||
| SimpleRemote.insert1(test) | ||
| SimpleRemote.delete() | ||
|
|
||
| # Save the old external table minio client | ||
| old_client = schema_ext.external["share"].s3.client | ||
|
|
||
| # Apply our new minio client which has a user that does not exist | ||
| schema_ext.external["share"].s3.client = Minio( | ||
| S3_CONN_INFO["endpoint"], | ||
| access_key="jeffjeff", | ||
| secret_key="jeffjeff", | ||
| secure=False, | ||
| ) | ||
|
|
||
| # This method returns a list of errors | ||
| error_list = schema_ext.external["share"].delete( | ||
| delete_external_files=True, errors_as_string=False | ||
| ) | ||
|
|
||
| # Teardown | ||
| schema_ext.external["share"].s3.client = old_client | ||
| schema_ext.external["share"].delete(delete_external_files=True) | ||
|
|
||
| with pytest.raises(DataJointError): | ||
| # Raise the error we want if the error matches the expected uuid | ||
| if str(error_list[0][0]) == str(uuid_from_buffer(pack(test[1]))): | ||
| raise error_list[0][2] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.