Skip to content

Commit

Permalink
Aj 1531 python import test (#460)
Browse files Browse the repository at this point in the history
* beginning of python test
* serve files from nginx
  • Loading branch information
calypsomatic authored Jan 19, 2024
1 parent a8b99a0 commit fea38cf
Show file tree
Hide file tree
Showing 6 changed files with 1,216 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-python-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:

- name: Mock Sam via command-line docker run
run: |
docker run -v ${{ github.workspace }}/service/src/test/resources/nginx.conf:/etc/nginx/nginx.conf:ro -p 9889:80 -d nginx:1.23.3
docker run -v ${{ github.workspace }}/service/src/test/resources/nginx.conf:/etc/nginx/nginx.conf:ro -v ${{ github.workspace }}/service/src/test/resources:/usr/share/nginx/html -p 9889:80 -d nginx:1.23.3
- name: Set up JDK
uses: actions/setup-java@v3
Expand Down
11 changes: 11 additions & 0 deletions docs/WDS Running Python tests locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ To run tests, WDS uses pytest. Ensure that is installed by running:
pip install pytest
```

Some tests also require a server from which to fetch test files. For these to work, you'll have to set up the nginx docker container to serve them:
```bash
# start the server as a docker container in detached mode
docker run -v `pwd`/service/src/test/resources/nginx.conf:/etc/nginx/nginx.conf -v `pwd`/service/src/test/resources:/usr/share/nginx/html -p 9889:80 -d nginx:1.23.3
```


## Build wds_client locally

Once you confirm that you have python and openapitools, you will need to build and create a local version of the wds_client package (make sure you are in the right branch that has the changes you want to test). Note that you will need to re-generate the client for each code change you make. To do that, run the following command (from the root of your repo or adjust path accordingly). If this command is generating errors, it is likely because the openapi is set to the wrong version. Note that package version is hard coded since it is not important to track locally - adjust as you se fit if you want to the version to change when you install the package locally.
Expand Down Expand Up @@ -65,4 +72,8 @@ Once you have the wds_client package importing locally with no issues, you are r
pytest service/src/test/python/test.py
```

Note: Make sure your local WDS database does not have data in it before running these tests, as its presence may cause the tests to fail.

To debug tests, you may want to try out python's [pdb debugger](https://realpython.com/python-debugging-pdb/).

In case you get frustrated with python, go [here](https://xkcd.com/1987/) for a quick laugh.
35 changes: 35 additions & 0 deletions service/src/test/python/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from datetime import date, datetime
import random
import csv
import time

# generate records for testing
def generate_record():
Expand Down Expand Up @@ -96,8 +97,12 @@ class WdsTests(TestCase):
generalInfo_client = wds_client.GeneralWDSInformationApi(api_client)
schema_client = wds_client.SchemaApi(api_client)
instance_client = wds_client.InstancesApi(api_client)
import_client = wds_client.ImportApi(api_client)
job_client = wds_client.JobApi(api_client)
current_workspaceId = instance_client.list_wds_instances(version)[0]

local_server_host = 'http://localhost:9889'

testType1_simple ="s_record_1"
testType1_complex ="c_record_1"
testType1_relation ="r_record_1"
Expand Down Expand Up @@ -236,3 +241,33 @@ def test_upload_download_tsv(self):
response = self.schema_client.delete_record_type(self.current_workspaceId, self.version, self.cvsUpload_test);
workspace_ent_type = self.schema_client.describe_all_record_types(self.current_workspaceId, self.version)
self.assertTrue(len(workspace_ent_type) == 0)

# SCENARIO 6
# import snapshot from TDR with appropriate permissions
def test_import_snapshot(self):
import_request = { "type": "TDRMANIFEST", "url": self.local_server_host + "/tdrmanifest/v2f_for_python.json"}
job_response = self.import_client.import_v1(self.current_workspaceId, import_request)
job_status_response = self.job_client.job_status_v1(job_response.job_id)
job_status = job_status_response.status
while job_status in ['RUNNING', 'QUEUED']:
time.sleep(10) #sleep ten seconds then try again
job_status_response = self.job_client.job_status_v1(job_response.job_id)
job_status = job_status_response.status
assert job_status == 'SUCCEEDED'


# should create tables from manifest, spot-check
ent_types = self.schema_client.describe_record_type(self.current_workspaceId, self.version, "all_data_types")
assert ent_types.count == 5
search_request = { "offset": 0, "limit": 2}
records = self.records_client.query_records(self.current_workspaceId, self.version, "all_data_types", search_request)
testRecord = records.records[0]
assert testRecord.id == "12:101976753:T:C"
assert len(testRecord.attributes) == 23
assert testRecord.attributes['datarepo_row_id'] == "0E369A2D-25E5-4D65-955B-334F894C2883"
# clean up
all_record_types = self.schema_client.describe_all_record_types(self.current_workspaceId, self.version)
for record_type in all_record_types:
self.schema_client.delete_record_type(self.current_workspaceId, self.version, record_type.name)
workspace_ent_type = self.schema_client.describe_all_record_types(self.current_workspaceId, self.version)
assert len(workspace_ent_type) == 0
4 changes: 4 additions & 0 deletions service/src/test/resources/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,9 @@ http {
types { } default_type "application/json";
return 200 "ya29.c.b9Aaedm1EjjI5oy921IM1GnIg2YOadOCjMA7yIyM__15_GdjbhJO_BfN1yCoejd11YmDddE7DEaG1-OCIHK11B_hfIcyjlCEKIOmG77-NM9Mh1IjdoO7OMffBfGMI-nbmyomfIonIBad-eJf4Kf5J7IOGmdhGGImdNlfbmKdm2B29cGGacEj_YofK5JIhllfCNd7nnYE4IBl9_n-BOeMMfIIcDJ-F5Ead7CKIcd17jE4EOEF4Ijh11liMfhCFy5EKMi299J2fhHh7G4fyCOAEOGhnoJfljhGdfndGJDfb9hGIM7-OiGCEIiHI1fnoMGIGhb_-ID1lOG1NdGgE747C_YdJIn9ly4jIo-7Mf-49jefI9cGgjEm15J1Gn_M11hjMGbfMh2hajOy179fh9jmh4nKlcjInjMIBiB4MjB_IlB7IlG_IjIb45K7GlcdjmnfndcG4nBhfnlJnK11BjfmgKdlFF_cYfhBMial7M1mhfdbn4hGMfmyjgj4JIl4Ijj4G49In7alYIIMlddIycJG_beOm_I4aY9-c419lMgjmidBMfj1IhdK7OmnOY9KjfEBIbMhheic-1f9G7KayaI_fnloGgj_hjhoKeiYjGnn_E4IYflBjjIhdd9fOmBKelhfEF7G7_hl2EFMKdOfIBBl7dMObnB5deM9hBf4nnIh1jB4nm5MhKIfleMihn1-4iaOFB1jE9bM4aMnh5GI59ioIdMeOJjehm4OI49jamnfd7GO-h9j4haffMnh9gGMelIMa9dhjfbFh1Iyj7M1n5BdnO1na5I7Em7JcnfGMM_j4JhK7EEnne4-4IGFBIjfIjGnO94jlhGOInhfjMn9-44hbMM4IahK9on-bfIGK9jnhjjBYjjcdKJJF_Y-yGmeO4j_-FiMK5nEj4ndJKnIdifdMInI9Id4EMaMOGK_oMIE_m44eOefhY4JIjlOf4dG1c5JjlhG4n5_oIIIO9y17nnO4nnnO7n7jnEFMhi5goO9M494f-7Mlf1F477I9";
}

location / {
root /usr/share/nginx/html; # Root for files
}
}
}
2 changes: 1 addition & 1 deletion service/src/test/resources/tdrmanifest/v2f.json
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@
"paths" : [ "classpath:parquet/v2f/feature_consequence.parquet" ]
} ]
},
"manifest" : "classpath:tdrmanifest/v2f/manifest.json"
"manifest" : "classpath:tdrmanifest/v2f.json"
},
"workspace" : null
}
Expand Down
Loading

0 comments on commit fea38cf

Please sign in to comment.