This repository has been archived by the owner on Dec 31, 2024. It is now read-only.
forked from Koppeltaal/Koppeltaal-Python-Connector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
164 lines (134 loc) · 4.56 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# -*- coding: utf-8 -*-
"""
:copyright: (c) 2015 - 2017 Stichting Koppeltaal
:license: AGPL, see `LICENSE.md` for more details.
"""
import os
import datetime
import uuid
import pytest
import selenium.webdriver
import six
import koppeltaal.interfaces
import koppeltaal.connector
import koppeltaal.models
import koppeltaal.testing
import koppeltaal.utils
unicode = six.text_type
def pytest_addoption(parser):
'''Add server identifier to be passed in. Looks for corresponding part in
~/.koppeltaal.cfg
'''
parser.addoption(
'--server',
help=("""\
Koppeltaal server identifier. URL and credentials should be
defined in the part identified by that name in ~/.koppeltaal.cfg.
For example:
[edge]
url = https://edgekoppeltaal.vhscloud.nl
domain = PythonAdapterTesting
username = [username]
password = [password]
"""))
parser.addoption('--baseurl')
parser.addoption('--domain')
parser.addoption('--username')
parser.addoption('--password')
@pytest.fixture(scope='session')
def connector(request):
server = request.config.option.server
if server:
credentials = koppeltaal.utils.get_credentials_from_file(server)
else:
credentials = koppeltaal.utils.Credentials(
os.environ.get('ADAPTER_SERVER'),
os.environ.get('ADAPTER_USERNAME'),
os.environ.get('ADAPTER_PASSWORD'),
os.environ.get('ADAPTER_DOMAIN'),
{'oauth_secret': os.environ.get('ADAPTER_OAUTH_SECRET')})
integration = koppeltaal.connector.Integration(
'Koppeltaal Python Adapter Tests',
'https://example.com/fhir/Koppeltaal',
software='Koppeltaal Python Adapter Tests Runner',
version=koppeltaal.interfaces.VERSION)
return koppeltaal.connector.Connector(credentials, integration)
@pytest.fixture
def transport(monkeypatch, connector):
transport = koppeltaal.testing.MockTransport('koppeltaal.tests')
monkeypatch.setattr(connector, 'transport', transport)
monkeypatch.setattr(connector.integration, 'model_id', lambda m: u'1')
monkeypatch.setattr(koppeltaal.utils, 'messageid', lambda: u'1234-5678')
return transport
@pytest.fixture
def patient(request, connector):
patient = koppeltaal.models.Patient(
name=[
koppeltaal.models.Name(
family=[u"Doe"],
given=[u"John"],
text=u'John Doe')],
age=42,
gender="M",
active=True)
return patient
@pytest.fixture
def practitioner():
return koppeltaal.models.Practitioner(
name=koppeltaal.models.Name(
given=[u'John'],
family=[u'Q.', u'Practitioner'],
text=u'John Q Practitioner'))
@pytest.fixture
def related_person(patient):
related_person = koppeltaal.models.RelatedPerson(
patient=patient,
relationship='PRN',
name=koppeltaal.models.Name(
family=[u"Doe"],
given=[u"John"],
text=u'John Doe'),
gender="M",
address=koppeltaal.models.Address(city='Rotterdam'))
return related_person
@pytest.fixture
def activity_definition(connector):
# Highly depending on what's activated on the server.
definition = connector.activity('KTSTESTGAME')
assert definition is not None, 'Test activity not found.'
return definition
@pytest.fixture
def careplan(patient, practitioner, activity_definition):
participants = [koppeltaal.models.Participant(
member=practitioner,
role='Caregiver')]
return koppeltaal.models.CarePlan(
activities=[koppeltaal.models.Activity(
identifier=unicode(uuid.uuid4()),
definition=activity_definition.identifier,
kind=activity_definition.kind,
participants=participants,
planned=datetime.datetime.now(),
status='Available')],
patient=patient,
participants=participants,
status='active')
@pytest.fixture
def careplan_from_fixture(request, transport):
transport.expect(
'GET',
'/FHIR/Koppeltaal/Other/_search?code=ActivityDefinition',
respond_with='fixtures/activities_game.json')
return request.getfixturevalue('careplan')
@pytest.fixture
def careplan_response(connector, careplan):
return connector.send('CreateOrUpdateCarePlan', careplan, careplan.patient)
@pytest.fixture(scope='session')
def driver(request):
driver = selenium.webdriver.Firefox()
request.addfinalizer(driver.quit)
return driver
@pytest.fixture
def browser(driver, request):
request.addfinalizer(driver.delete_all_cookies)
return driver