This repository has been archived by the owner on Dec 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from arkhn/jblemoine_create_tests
Add travis and pytest
- Loading branch information
Showing
10 changed files
with
243 additions
and
70 deletions.
There are no files selected for viewing
This file contains 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,9 @@ | ||
language: python | ||
python: | ||
- "3.6" | ||
# command to install dependencies | ||
install: | ||
- pip install -r requirements.txt | ||
# command to run tests | ||
script: | ||
- pytest |
This file contains 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 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,2 @@ | ||
black | ||
pytest |
Empty file.
This file contains 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,27 @@ | ||
import pytest | ||
import os | ||
import json | ||
|
||
from process import clean_json | ||
from process import json_to_yml | ||
|
||
CLEAN_DATA_FOLDER = 'tests/data/clean' | ||
CORRUPTED_DATA_FOLDER = 'tests/data/corrupted' | ||
FILES = ['patient.json'] | ||
|
||
|
||
@pytest.fixture(scope="module", | ||
params=[os.path.join(CORRUPTED_DATA_FOLDER, filename) for filename in FILES]) | ||
def cleaned_json(request): | ||
return clean_json(request.param) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def cleaned_yml(cleaned_json): | ||
return json_to_yml(json.loads(cleaned_json)) | ||
|
||
|
||
@pytest.fixture(scope="module", | ||
params=[os.path.join(CLEAN_DATA_FOLDER, filename) for filename in FILES]) | ||
def expected_json(request): | ||
return json.load(open(request.param)) |
This file contains 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,40 @@ | ||
{ | ||
"resourceType" : "Patient", | ||
"identifier<list::Identifier>": null, | ||
"active<boolean>": null, | ||
"name<list::HumanName>": null, | ||
"telecom<list::ContactPoint>": null, | ||
"gender<code=male|female|other|unknown>": null, | ||
"birthDate<date>": null, | ||
"deceasedBoolean<boolean>": null, | ||
"deceasedDateTime<dateTime>": null, | ||
"address<list::Address>": null, | ||
"maritalStatus<CodeableConcept>": null, | ||
"multipleBirthBoolean<boolean>": null, | ||
"multipleBirthInteger<integer>": null, | ||
"photo<list::Attachment>": null, | ||
"contact<list>": [{ | ||
"relationship<list::CodeableConcept>": null, | ||
"name<HumanName>": null, | ||
"telecom<list::ContactPoint>": null, | ||
"address<Address>": null, | ||
"gender<code=male|female|other|unknown>": null, | ||
"organization<Reference(Organization)>": null, | ||
"period<Period>": null | ||
}], | ||
"animal" : { | ||
"species<CodeableConcept>": null, | ||
"breed<CodeableConcept>": null, | ||
"genderStatus<CodeableConcept>": null | ||
}, | ||
"communication<list>": [{ | ||
"language<CodeableConcept>": null, | ||
"preferred<boolean>": null | ||
}], | ||
"generalPractitioner<list::Reference(Organization|Practitioner)>": null, | ||
"managingOrganization<Reference(Organization)>": null, | ||
"link<list>": [{ | ||
"other<Reference(Patient|RelatedPerson)>": null, | ||
"type<code=replaced-by|replaces|refer|seealso>": null | ||
}] | ||
} |
This file contains 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,44 @@ | ||
{doco | ||
"resourceType" : "Patient", | ||
// from Resource: id, meta, implicitRules, and language | ||
// from DomainResource: text, contained, extension, and modifierExtension | ||
"identifier" : [{ Identifier }], // An identifier for this patient | ||
"active" : <boolean>, // Whether this patient's record is in active use | ||
"name" : [{ HumanName }], // A name associated with the patient | ||
"telecom" : [{ ContactPoint }], // A contact detail for the individual | ||
"gender" : "<code>", // male | female | other | unknown | ||
"birthDate" : "<date>", // The date of birth for the individual | ||
// deceased[x]: Indicates if the individual is deceased or not. One of these 2: | ||
"deceasedBoolean" : <boolean>, | ||
"deceasedDateTime" : "<dateTime>", | ||
"address" : [{ Address }], // Addresses for the individual | ||
"maritalStatus" : { CodeableConcept }, // Marital (civil) status of a patient | ||
// multipleBirth[x]: Whether patient is part of a multiple birth. One of these 2: | ||
"multipleBirthBoolean" : <boolean>, | ||
"multipleBirthInteger" : <integer>, | ||
"photo" : [{ Attachment }], // Image of the patient | ||
"contact" : [{ // A contact party (e.g. guardian, partner, friend) for the patient | ||
"relationship" : [{ CodeableConcept }], // The kind of relationship | ||
"name" : { HumanName }, // A name associated with the contact person | ||
"telecom" : [{ ContactPoint }], // A contact detail for the person | ||
"address" : { Address }, // Address for the contact person | ||
"gender" : "<code>", // male | female | other | unknown | ||
"organization" : { Reference(Organization) }, // C? Organization that is associated with the contact | ||
"period" : { Period } // The period during which this contact person or organization is valid to be contacted relating to this patient | ||
}], | ||
"animal" : { // This patient is known to be an animal (non-human) | ||
"species" : { CodeableConcept }, // R! E.g. Dog, Cow | ||
"breed" : { CodeableConcept }, // E.g. Poodle, Angus | ||
"genderStatus" : { CodeableConcept } // E.g. Neutered, Intact | ||
}, | ||
"communication" : [{ // A list of Languages which may be used to communicate with the patient about his or her health | ||
"language" : { CodeableConcept }, // R! The language which can be used to communicate with the patient about his or her health | ||
"preferred" : <boolean> // Language preference indicator | ||
}], | ||
"generalPractitioner" : [{ Reference(Organization|Practitioner) }], // Patient's nominated primary care provider | ||
"managingOrganization" : { Reference(Organization) }, // Organization that is the custodian of the patient record | ||
"link" : [{ // Link to another patient resource that concerns the same actual person | ||
"other" : { Reference(Patient|RelatedPerson) }, // R! The other patient or related person resource that the link refers to | ||
"type" : "<code>" // R! replaced-by | replaces | refer | seealso - type of link | ||
}] | ||
} |
This file contains 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,19 @@ | ||
import json | ||
|
||
|
||
def test_clean_json(cleaned_json, expected_json): | ||
|
||
# assert cleaned json is a valid json file | ||
cleaned_dict = json.loads(cleaned_json) | ||
|
||
# assert cleaned json is equal to expected output | ||
assert cleaned_dict == expected_json | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains 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,11 @@ | ||
from process import json_to_yml | ||
|
||
def test_json_to_yml(cleaned_json): | ||
|
||
# I don't know how to assess a yaml has the expected format | ||
# more info: https://github.com/arkhn/fhir-store/issues/3 | ||
pass | ||
|
||
|
||
|
||
|
This file contains 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,21 @@ | ||
import os | ||
from process import write | ||
|
||
DOMAIN = 'domain_test' | ||
SUBDOMAIN = 'subdomain_test' | ||
RESOURCE = 'resource_test' | ||
|
||
|
||
def test_write(cleaned_json, cleaned_yml): | ||
|
||
write(domain=DOMAIN, subdomain=SUBDOMAIN, resource=RESOURCE, format='json', file_data=cleaned_json) | ||
write(domain=DOMAIN, subdomain=SUBDOMAIN, resource=RESOURCE, format='yml', file_data=cleaned_yml) | ||
|
||
json_path = os.path.join(os.path.join('json', DOMAIN, SUBDOMAIN, RESOURCE + '.json')) | ||
yml_path = os.path.join(os.path.join('yml', DOMAIN, SUBDOMAIN, RESOURCE + '.yml')) | ||
|
||
# assert file have been written properly | ||
with open(json_path, 'r') as content_file: | ||
assert content_file.read() == cleaned_json | ||
with open(yml_path, 'r') as content_file: | ||
assert content_file.read() == cleaned_yml |