Skip to content

Commit c4661dd

Browse files
ci
1 parent da82493 commit c4661dd

File tree

2 files changed

+30
-47
lines changed

2 files changed

+30
-47
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ jobs:
120120
defaults:
121121
run:
122122
working-directory: library
123-
123+
124124
env:
125125
# use minimum supported versions from https://devguide.python.org/versions/
126126
python-version: "3.9"
@@ -195,4 +195,4 @@ jobs:
195195
- name: Upload coverage to Coveralls
196196
uses: coverallsapp/github-action@v2
197197
with:
198-
base-path: library/geoengine
198+
base-path: library

tests/test_auth.py

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,42 @@ def test_uninitialized(self):
3434
'You have to call `initialize` before using other functionality')
3535

3636
def test_initialize(self):
37+
def get_session_id(session: ge.Session) -> str:
38+
return session.auth_header['Authorization'].split(' ')[1]
39+
3740
# TODO: use `enterContext(cm)` instead of `with cm:` in Python 3.11
3841
with GeoEngineTestInstance() as ge_instance:
3942
ge_instance.wait_for_ready()
4043

44+
# anonymous
45+
4146
ge.initialize(ge_instance.address())
4247

4348
self.assertEqual(type(ge.get_session()), ge.Session)
4449

50+
session_id = get_session_id(ge.get_session())
51+
52+
ge.reset(False)
53+
54+
# token as parameter
55+
56+
ge.initialize(ge_instance.address(), token=session_id)
57+
58+
self.assertEqual(get_session_id(ge.get_session()), session_id)
59+
60+
ge.reset(False)
61+
62+
# token as environment variable
63+
64+
os.environ["GEOENGINE_TOKEN"] = session_id
65+
66+
try:
67+
ge.initialize(ge_instance.address())
68+
finally:
69+
del os.environ["GEOENGINE_TOKEN"]
70+
71+
self.assertEqual(get_session_id(ge.get_session()), session_id)
72+
4573
def test_initialize_tuple(self):
4674
with UrllibMocker() as m:
4775
m.post('http://mock-instance/login',
@@ -89,51 +117,6 @@ def test_initialize_env(self):
89117
self.assertEqual(type(ge.get_session()),
90118
ge.Session)
91119

92-
def test_initialize_token(self):
93-
with UrllibMocker() as m:
94-
m.get('http://mock-instance/session',
95-
request_headers={"Authorization": "Bearer e327d9c3-a4f3-4bd7-a5e1-30b26cae8064"},
96-
json={
97-
"id": "e327d9c3-a4f3-4bd7-a5e1-30b26cae8064",
98-
"user": {
99-
"id": "328ca8d1-15d7-4f59-a989-5d5d72c98744",
100-
},
101-
"created": "2021-06-08T15:22:22.605891994Z",
102-
"validUntil": "2021-06-08T16:22:22.605892183Z",
103-
"project": None,
104-
"view": None
105-
})
106-
107-
ge.initialize("http://mock-instance", token="e327d9c3-a4f3-4bd7-a5e1-30b26cae8064")
108-
109-
self.assertEqual(type(ge.get_session()),
110-
ge.Session)
111-
112-
def test_initialize_token_env(self):
113-
with UrllibMocker() as m:
114-
m.get('http://mock-instance/session',
115-
request_headers={"Authorization": "Bearer e327d9c3-a4f3-4bd7-a5e1-30b26cae8064"},
116-
json={
117-
"id": "e327d9c3-a4f3-4bd7-a5e1-30b26cae8064",
118-
"user": {
119-
"id": "328ca8d1-15d7-4f59-a989-5d5d72c98744",
120-
},
121-
"created": "2021-06-08T15:22:22.605891994Z",
122-
"validUntil": "2021-06-08T16:22:22.605892183Z",
123-
"project": None,
124-
"view": None
125-
})
126-
127-
os.environ["GEOENGINE_TOKEN"] = "e327d9c3-a4f3-4bd7-a5e1-30b26cae8064"
128-
129-
try:
130-
ge.initialize("http://mock-instance")
131-
finally:
132-
del os.environ["GEOENGINE_TOKEN"]
133-
134-
self.assertEqual(type(ge.get_session()),
135-
ge.Session)
136-
137120
def test_user_agent(self):
138121
with UrllibMocker() as m:
139122
m.post('http://mock-instance/anonymous',

0 commit comments

Comments
 (0)