Skip to content

Commit 2d98183

Browse files
cfmlegoktm
authored andcommitted
Refactor and update SDK tests to use lightweight VCR interface
We can't use VCR.py's "custom_patches" parameter because our API._send_json_request() is RPC- rather than connection-oriented. But we can just instrument _send_json_request() directly, which is what we do here. We subclass vcr.cassette.Cassette to handle identical requests with different responses, which was suggestd by @vickyliin as a workaround for kevin1024/vcrpy#753. Now that the SDK‒proxy connection is itself instrumented, there's only one path to test, with no special error-handling logic required, so merge TestAPIProxy into TestAPI. I considered merging TestAPI and TestShared as well, now that (without TestAPIProxy) TestAPI is the only subclass of TestShared. But reorganizing the alphabetized helpers in TestShared versus the strictly-sequenced TestAPI methods can wait. The tests are also now more patient with slow deletion operations. I'd want to DRY up this logic if this pattern shows up in more places, but it would require adding another level of indirection. A @Retry decorator isn't appropriate at the level of the test method, and a context manager can't loop over its closure. And re-apply the hack from 880635d by renaming test_logout to start with a "z" so it runs last.
1 parent 72f392f commit 2d98183

File tree

98 files changed

+14134
-5597
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+14134
-5597
lines changed

Diff for: client/tests/sdk/data/setup_method.json

-1
This file was deleted.

Diff for: client/tests/sdk/data/setup_method.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
interactions:
2+
- request:
3+
body: '{"username": "journalist", "passphrase": "correct horse battery staple
4+
profanity oil chewy", "one_time_code": "112097"}'
5+
headers: {}
6+
method: POST
7+
uri: api/v1/token
8+
response: !!python/object:securedrop_client.sdk.JSONResponse
9+
data:
10+
expiration: '2024-02-29T23:13:01.444028Z'
11+
journalist_first_name: null
12+
journalist_last_name: null
13+
journalist_uuid: ed64b0fa-0565-4b12-9c48-6cfe27a73fd9
14+
token: Ilhha2ZHZWpVcFZQVmpKdWJOUzJYRG1YVUc4QXZWS0JiOGVNQXJycE5GUFUi.ZeDzXQ.10ODTj49yF7kxKbeMm9eaayR3Xo
15+
headers:
16+
connection: close
17+
content-length: '290'
18+
content-type: application/json
19+
date: Thu, 29 Feb 2024 21:13:01 GMT
20+
server: Werkzeug/2.2.3 Python/3.8.10
21+
status: 200
22+
version: 1

Diff for: client/tests/sdk/data/test-badotp.yml

-34
This file was deleted.

Diff for: client/tests/sdk/data/test-badpassword.yml

-33
This file was deleted.

Diff for: client/tests/sdk/data/test-baduser.yml

-34
This file was deleted.

0 commit comments

Comments
 (0)