Skip to content

Commit

Permalink
Refactor and update SDK tests to use lightweight VCR interface
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
micahflee committed May 16, 2024
1 parent 7da359e commit 2e2dfd2
Show file tree
Hide file tree
Showing 98 changed files with 14,134 additions and 5,620 deletions.
1 change: 0 additions & 1 deletion client/tests/sdk/data/setup_method.json

This file was deleted.

22 changes: 22 additions & 0 deletions client/tests/sdk/data/setup_method.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
interactions:
- request:
body: '{"username": "journalist", "passphrase": "correct horse battery staple
profanity oil chewy", "one_time_code": "112097"}'
headers: {}
method: POST
uri: api/v1/token
response: !!python/object:securedrop_client.sdk.JSONResponse
data:
expiration: '2024-02-29T23:13:01.444028Z'
journalist_first_name: null
journalist_last_name: null
journalist_uuid: ed64b0fa-0565-4b12-9c48-6cfe27a73fd9
token: Ilhha2ZHZWpVcFZQVmpKdWJOUzJYRG1YVUc4QXZWS0JiOGVNQXJycE5GUFUi.ZeDzXQ.10ODTj49yF7kxKbeMm9eaayR3Xo
headers:
connection: close
content-length: '290'
content-type: application/json
date: Thu, 29 Feb 2024 21:13:01 GMT
server: Werkzeug/2.2.3 Python/3.8.10
status: 200
version: 1
34 changes: 0 additions & 34 deletions client/tests/sdk/data/test-badotp.yml

This file was deleted.

33 changes: 0 additions & 33 deletions client/tests/sdk/data/test-badpassword.yml

This file was deleted.

34 changes: 0 additions & 34 deletions client/tests/sdk/data/test-baduser.yml

This file was deleted.

0 comments on commit 2e2dfd2

Please sign in to comment.