|
| 1 | +import os |
| 2 | +from fastapi.testclient import TestClient |
| 3 | +from app.config import settings |
| 4 | +from app.models.pyobjectid import PyObjectId |
| 5 | + |
| 6 | +user = { |
| 7 | + |
| 8 | + "password": "not_a_password", |
| 9 | + "first_name": "Foo", |
| 10 | + "last_name": "Bar", |
| 11 | +} |
| 12 | + |
| 13 | +extractor_info = { |
| 14 | + "@context": "http://clowder.ncsa.illinois.edu/contexts/extractors.jsonld", |
| 15 | + "name": "ncsa.wordcount", |
| 16 | + "version": "2.0", |
| 17 | + "description": "WordCount extractor. Counts the number of characters, words and lines in the text file that was uploaded.", |
| 18 | + "contributors": [], |
| 19 | + "contexts": [ |
| 20 | + { |
| 21 | + "lines": "http://clowder.ncsa.illinois.edu/metadata/ncsa.wordcount#lines", |
| 22 | + "words": "http://clowder.ncsa.illinois.edu/metadata/ncsa.wordcount#words", |
| 23 | + "characters": "http://clowder.ncsa.illinois.edu/metadata/ncsa.wordcount#characters", |
| 24 | + } |
| 25 | + ], |
| 26 | + "repository": [ |
| 27 | + { |
| 28 | + "repType": "git", |
| 29 | + "repUrl": "https://opensource.ncsa.illinois.edu/stash/scm/cats/pyclowder.git", |
| 30 | + } |
| 31 | + ], |
| 32 | + "process": {"file": ["text/*", "application/json"]}, |
| 33 | + "external_services": [], |
| 34 | + "dependencies": [], |
| 35 | + "bibtex": [], |
| 36 | +} |
| 37 | + |
| 38 | +# extractor_info_file = os.path.join(os.getcwd(), 'extractor_info.json') |
| 39 | + |
| 40 | + |
| 41 | +def test_register(client: TestClient, headers: dict): |
| 42 | + response = client.post( |
| 43 | + f"{settings.API_V2_STR}/listeners", json=extractor_info, headers=headers |
| 44 | + ) |
| 45 | + assert response.json().get("id") is not None |
| 46 | + assert response.status_code == 200 |
| 47 | + |
| 48 | + |
| 49 | +def test_get_one(client: TestClient, headers: dict): |
| 50 | + response = client.post( |
| 51 | + f"{settings.API_V2_STR}/listeners", json=extractor_info, headers=headers |
| 52 | + ) |
| 53 | + assert response.status_code == 200 |
| 54 | + assert response.json().get("id") is not None |
| 55 | + extractor_id = response.json().get("id") |
| 56 | + response = client.get( |
| 57 | + f"{settings.API_V2_STR}/listeners/{extractor_id}", headers=headers |
| 58 | + ) |
| 59 | + assert response.status_code == 200 |
| 60 | + assert response.json().get("id") is not None |
| 61 | + |
| 62 | + |
| 63 | +def test_delete(client: TestClient, headers: dict): |
| 64 | + response = client.post( |
| 65 | + f"{settings.API_V2_STR}/listeners", json=extractor_info, headers=headers |
| 66 | + ) |
| 67 | + assert response.status_code == 200 |
| 68 | + assert response.json().get("id") is not None |
| 69 | + extractor_id = response.json().get("id") |
| 70 | + response = client.delete( |
| 71 | + f"{settings.API_V2_STR}/listeners/{extractor_id}", headers=headers |
| 72 | + ) |
| 73 | + assert response.status_code == 200 |
0 commit comments