From 1e397b35728912445a5fa5f64aadb1a266356a8e Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Thu, 1 Oct 2026 11:22:46 -0600 Subject: [PATCH 1/2] feat: add create, delete, enable, and disable api keys examples --- .../docs/csharp/current/api-keys/create.cs | 20 +++++ .../docs/csharp/current/api-keys/delete.cs | 15 ++++ .../docs/csharp/current/api-keys/disable.cs | 20 +++++ .../docs/csharp/current/api-keys/enable.cs | 20 +++++ .../docs/golang/current/api-keys/create.go | 15 ++++ .../docs/golang/current/api-keys/delete.go | 15 ++++ .../docs/golang/current/api-keys/disable.go | 15 ++++ .../docs/golang/current/api-keys/enable.go | 15 ++++ .../docs/java/current/api-keys/create.java | 15 ++++ .../docs/java/current/api-keys/delete.java | 12 +++ .../docs/java/current/api-keys/disable.java | 15 ++++ .../docs/java/current/api-keys/enable.java | 15 ++++ official/docs/node/current/api-keys/create.js | 9 +++ official/docs/node/current/api-keys/delete.js | 7 ++ .../docs/node/current/api-keys/disable.js | 9 +++ official/docs/node/current/api-keys/enable.js | 9 +++ official/docs/php/current/api-keys/create.php | 7 ++ official/docs/php/current/api-keys/delete.php | 5 ++ .../docs/php/current/api-keys/disable.php | 7 ++ official/docs/php/current/api-keys/enable.php | 7 ++ .../docs/python/current/api-keys/create.py | 7 ++ .../docs/python/current/api-keys/delete.py | 5 ++ .../docs/python/current/api-keys/disable.py | 7 ++ .../docs/python/current/api-keys/enable.py | 7 ++ official/docs/responses/api-keys/create.json | 4 +- official/docs/responses/api-keys/disable.json | 4 +- official/docs/responses/api-keys/enable.json | 4 +- official/docs/ruby/current/api-keys/create.rb | 7 ++ official/docs/ruby/current/api-keys/delete.rb | 5 ++ .../docs/ruby/current/api-keys/disable.rb | 7 ++ official/docs/ruby/current/api-keys/enable.rb | 7 ++ .../tests/test_api_keys.py | 79 ++++++++----------- 32 files changed, 341 insertions(+), 54 deletions(-) create mode 100644 official/docs/csharp/current/api-keys/create.cs create mode 100644 official/docs/csharp/current/api-keys/delete.cs create mode 100644 official/docs/csharp/current/api-keys/disable.cs create mode 100644 official/docs/csharp/current/api-keys/enable.cs create mode 100644 official/docs/golang/current/api-keys/create.go create mode 100644 official/docs/golang/current/api-keys/delete.go create mode 100644 official/docs/golang/current/api-keys/disable.go create mode 100644 official/docs/golang/current/api-keys/enable.go create mode 100644 official/docs/java/current/api-keys/create.java create mode 100644 official/docs/java/current/api-keys/delete.java create mode 100644 official/docs/java/current/api-keys/disable.java create mode 100644 official/docs/java/current/api-keys/enable.java create mode 100644 official/docs/node/current/api-keys/create.js create mode 100644 official/docs/node/current/api-keys/delete.js create mode 100644 official/docs/node/current/api-keys/disable.js create mode 100644 official/docs/node/current/api-keys/enable.js create mode 100644 official/docs/php/current/api-keys/create.php create mode 100644 official/docs/php/current/api-keys/delete.php create mode 100644 official/docs/php/current/api-keys/disable.php create mode 100644 official/docs/php/current/api-keys/enable.php create mode 100644 official/docs/python/current/api-keys/create.py create mode 100644 official/docs/python/current/api-keys/delete.py create mode 100644 official/docs/python/current/api-keys/disable.py create mode 100644 official/docs/python/current/api-keys/enable.py create mode 100644 official/docs/ruby/current/api-keys/create.rb create mode 100644 official/docs/ruby/current/api-keys/delete.rb create mode 100644 official/docs/ruby/current/api-keys/disable.rb create mode 100644 official/docs/ruby/current/api-keys/enable.rb diff --git a/official/docs/csharp/current/api-keys/create.cs b/official/docs/csharp/current/api-keys/create.cs new file mode 100644 index 00000000..b976a6b3 --- /dev/null +++ b/official/docs/csharp/current/api-keys/create.cs @@ -0,0 +1,20 @@ +using System; +using System.Threading.Tasks; +using EasyPost; +using EasyPost.Models.API; +using Newtonsoft.Json; + +namespace EasyPostExamples +{ + public class Examples + { + public static async Task Main() + { + var client = new EasyPost.Client(new EasyPost.ClientConfiguration("EASYPOST_API_KEY")); + + ApiKey apiKey = await client.ApiKey.Create("test"); + + Console.WriteLine(JsonConvert.SerializeObject(apiKey, Formatting.Indented)); + } + } +} diff --git a/official/docs/csharp/current/api-keys/delete.cs b/official/docs/csharp/current/api-keys/delete.cs new file mode 100644 index 00000000..5bd21a67 --- /dev/null +++ b/official/docs/csharp/current/api-keys/delete.cs @@ -0,0 +1,15 @@ +using System.Threading.Tasks; +using EasyPost; + +namespace EasyPostExamples +{ + public class Examples + { + public static async Task Main() + { + var client = new EasyPost.Client(new EasyPost.ClientConfiguration("EASYPOST_API_KEY")); + + await client.ApiKey.Delete("ak_..."); + } + } +} diff --git a/official/docs/csharp/current/api-keys/disable.cs b/official/docs/csharp/current/api-keys/disable.cs new file mode 100644 index 00000000..2fa0463f --- /dev/null +++ b/official/docs/csharp/current/api-keys/disable.cs @@ -0,0 +1,20 @@ +using System; +using System.Threading.Tasks; +using EasyPost; +using EasyPost.Models.API; +using Newtonsoft.Json; + +namespace EasyPostExamples +{ + public class Examples + { + public static async Task Main() + { + var client = new EasyPost.Client(new EasyPost.ClientConfiguration("EASYPOST_API_KEY")); + + ApiKey apiKey = await client.ApiKey.Disable("ak_..."); + + Console.WriteLine(JsonConvert.SerializeObject(apiKey, Formatting.Indented)); + } + } +} diff --git a/official/docs/csharp/current/api-keys/enable.cs b/official/docs/csharp/current/api-keys/enable.cs new file mode 100644 index 00000000..92f41347 --- /dev/null +++ b/official/docs/csharp/current/api-keys/enable.cs @@ -0,0 +1,20 @@ +using System; +using System.Threading.Tasks; +using EasyPost; +using EasyPost.Models.API; +using Newtonsoft.Json; + +namespace EasyPostExamples +{ + public class Examples + { + public static async Task Main() + { + var client = new EasyPost.Client(new EasyPost.ClientConfiguration("EASYPOST_API_KEY")); + + ApiKey apiKey = await client.ApiKey.Enable("ak_..."); + + Console.WriteLine(JsonConvert.SerializeObject(apiKey, Formatting.Indented)); + } + } +} diff --git a/official/docs/golang/current/api-keys/create.go b/official/docs/golang/current/api-keys/create.go new file mode 100644 index 00000000..591ad477 --- /dev/null +++ b/official/docs/golang/current/api-keys/create.go @@ -0,0 +1,15 @@ +package example + +import ( + "fmt" + + "github.com/EasyPost/easypost-go/v5" +) + +func create() { + client := easypost.New("EASYPOST_API_KEY") + + apiKey, _ := client.CreateAPIKey("test") + + fmt.Println(apiKey) +} diff --git a/official/docs/golang/current/api-keys/delete.go b/official/docs/golang/current/api-keys/delete.go new file mode 100644 index 00000000..33c98649 --- /dev/null +++ b/official/docs/golang/current/api-keys/delete.go @@ -0,0 +1,15 @@ +package example + +import ( + "fmt" + + "github.com/EasyPost/easypost-go/v5" +) + +func delete() { + client := easypost.New("EASYPOST_API_KEY") + + err := client.DeleteAPIKey("ak_...") + + fmt.Println(err) +} diff --git a/official/docs/golang/current/api-keys/disable.go b/official/docs/golang/current/api-keys/disable.go new file mode 100644 index 00000000..17511f89 --- /dev/null +++ b/official/docs/golang/current/api-keys/disable.go @@ -0,0 +1,15 @@ +package example + +import ( + "fmt" + + "github.com/EasyPost/easypost-go/v5" +) + +func disable() { + client := easypost.New("EASYPOST_API_KEY") + + apiKey, _ := client.DisableAPIKey("ak_...") + + fmt.Println(apiKey) +} diff --git a/official/docs/golang/current/api-keys/enable.go b/official/docs/golang/current/api-keys/enable.go new file mode 100644 index 00000000..f49dff82 --- /dev/null +++ b/official/docs/golang/current/api-keys/enable.go @@ -0,0 +1,15 @@ +package example + +import ( + "fmt" + + "github.com/EasyPost/easypost-go/v5" +) + +func enable() { + client := easypost.New("EASYPOST_API_KEY") + + apiKey, _ := client.EnableAPIKey("ak_...") + + fmt.Println(apiKey) +} diff --git a/official/docs/java/current/api-keys/create.java b/official/docs/java/current/api-keys/create.java new file mode 100644 index 00000000..14df1989 --- /dev/null +++ b/official/docs/java/current/api-keys/create.java @@ -0,0 +1,15 @@ +package api_keys; + +import com.easypost.exception.EasyPostException; +import com.easypost.model.ApiKey; +import com.easypost.service.EasyPostClient; + +public class Create { + public static void main(String[] args) throws EasyPostException { + EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY"); + + ApiKey apiKey = client.apiKey.create("test"); + + System.out.println(apiKey); + } +} diff --git a/official/docs/java/current/api-keys/delete.java b/official/docs/java/current/api-keys/delete.java new file mode 100644 index 00000000..7d8990d8 --- /dev/null +++ b/official/docs/java/current/api-keys/delete.java @@ -0,0 +1,12 @@ +package api_keys; + +import com.easypost.exception.EasyPostException; +import com.easypost.service.EasyPostClient; + +public class Delete { + public static void main(String[] args) throws EasyPostException { + EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY"); + + client.apiKey.delete("ak_..."); + } +} diff --git a/official/docs/java/current/api-keys/disable.java b/official/docs/java/current/api-keys/disable.java new file mode 100644 index 00000000..8c4301bd --- /dev/null +++ b/official/docs/java/current/api-keys/disable.java @@ -0,0 +1,15 @@ +package api_keys; + +import com.easypost.exception.EasyPostException; +import com.easypost.model.ApiKey; +import com.easypost.service.EasyPostClient; + +public class Disable { + public static void main(String[] args) throws EasyPostException { + EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY"); + + ApiKey apiKey = client.apiKey.disable("ak_..."); + + System.out.println(apiKey); + } +} diff --git a/official/docs/java/current/api-keys/enable.java b/official/docs/java/current/api-keys/enable.java new file mode 100644 index 00000000..7ca8c91c --- /dev/null +++ b/official/docs/java/current/api-keys/enable.java @@ -0,0 +1,15 @@ +package api_keys; + +import com.easypost.exception.EasyPostException; +import com.easypost.model.ApiKey; +import com.easypost.service.EasyPostClient; + +public class Enable { + public static void main(String[] args) throws EasyPostException { + EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY"); + + ApiKey apiKey = client.apiKey.enable("ak_..."); + + System.out.println(apiKey); + } +} diff --git a/official/docs/node/current/api-keys/create.js b/official/docs/node/current/api-keys/create.js new file mode 100644 index 00000000..e7a1cfa3 --- /dev/null +++ b/official/docs/node/current/api-keys/create.js @@ -0,0 +1,9 @@ +const EasyPostClient = require('@easypost/api'); + +const client = new EasyPostClient('EASYPOST_API_KEY'); + +(async () => { + const apiKey = await client.ApiKey.create('test'); + + console.log(apiKey); +})(); diff --git a/official/docs/node/current/api-keys/delete.js b/official/docs/node/current/api-keys/delete.js new file mode 100644 index 00000000..faf92102 --- /dev/null +++ b/official/docs/node/current/api-keys/delete.js @@ -0,0 +1,7 @@ +const EasyPostClient = require('@easypost/api'); + +const client = new EasyPostClient('EASYPOST_API_KEY'); + +(async () => { + await client.ApiKey.delete('ak_...'); +})(); diff --git a/official/docs/node/current/api-keys/disable.js b/official/docs/node/current/api-keys/disable.js new file mode 100644 index 00000000..de8a60d8 --- /dev/null +++ b/official/docs/node/current/api-keys/disable.js @@ -0,0 +1,9 @@ +const EasyPostClient = require('@easypost/api'); + +const client = new EasyPostClient('EASYPOST_API_KEY'); + +(async () => { + const apiKey = await client.ApiKey.disable('ak_...'); + + console.log(apiKey); +})(); diff --git a/official/docs/node/current/api-keys/enable.js b/official/docs/node/current/api-keys/enable.js new file mode 100644 index 00000000..f3687f43 --- /dev/null +++ b/official/docs/node/current/api-keys/enable.js @@ -0,0 +1,9 @@ +const EasyPostClient = require('@easypost/api'); + +const client = new EasyPostClient('EASYPOST_API_KEY'); + +(async () => { + const apiKey = await client.ApiKey.enable('ak_...'); + + console.log(apiKey); +})(); diff --git a/official/docs/php/current/api-keys/create.php b/official/docs/php/current/api-keys/create.php new file mode 100644 index 00000000..14713e18 --- /dev/null +++ b/official/docs/php/current/api-keys/create.php @@ -0,0 +1,7 @@ +apiKeys->create('test'); + +echo $apiKey; diff --git a/official/docs/php/current/api-keys/delete.php b/official/docs/php/current/api-keys/delete.php new file mode 100644 index 00000000..9df77ef2 --- /dev/null +++ b/official/docs/php/current/api-keys/delete.php @@ -0,0 +1,5 @@ +apiKeys->delete('ak_...'); diff --git a/official/docs/php/current/api-keys/disable.php b/official/docs/php/current/api-keys/disable.php new file mode 100644 index 00000000..d87904d8 --- /dev/null +++ b/official/docs/php/current/api-keys/disable.php @@ -0,0 +1,7 @@ +apiKeys->disable('ak_...'); + +echo $apiKey; diff --git a/official/docs/php/current/api-keys/enable.php b/official/docs/php/current/api-keys/enable.php new file mode 100644 index 00000000..0f27f04a --- /dev/null +++ b/official/docs/php/current/api-keys/enable.php @@ -0,0 +1,7 @@ +apiKeys->enable('ak_...'); + +echo $apiKey; diff --git a/official/docs/python/current/api-keys/create.py b/official/docs/python/current/api-keys/create.py new file mode 100644 index 00000000..2625d33e --- /dev/null +++ b/official/docs/python/current/api-keys/create.py @@ -0,0 +1,7 @@ +import easypost + +client = easypost.EasyPostClient("EASYPOST_API_KEY") + +api_key = client.api_keys.create(mode="test") + +print(api_key) diff --git a/official/docs/python/current/api-keys/delete.py b/official/docs/python/current/api-keys/delete.py new file mode 100644 index 00000000..5e32eed3 --- /dev/null +++ b/official/docs/python/current/api-keys/delete.py @@ -0,0 +1,5 @@ +import easypost + +client = easypost.EasyPostClient("EASYPOST_API_KEY") + +client.api_keys.delete("ak_...") diff --git a/official/docs/python/current/api-keys/disable.py b/official/docs/python/current/api-keys/disable.py new file mode 100644 index 00000000..9ca5e565 --- /dev/null +++ b/official/docs/python/current/api-keys/disable.py @@ -0,0 +1,7 @@ +import easypost + +client = easypost.EasyPostClient("EASYPOST_API_KEY") + +api_key = client.api_keys.disable("ak_...") + +print(api_key) diff --git a/official/docs/python/current/api-keys/enable.py b/official/docs/python/current/api-keys/enable.py new file mode 100644 index 00000000..0f386ccf --- /dev/null +++ b/official/docs/python/current/api-keys/enable.py @@ -0,0 +1,7 @@ +import easypost + +client = easypost.EasyPostClient("EASYPOST_API_KEY") + +api_key = client.api_keys.enable("ak_...") + +print(api_key) diff --git a/official/docs/responses/api-keys/create.json b/official/docs/responses/api-keys/create.json index 48c4648f..c4c3ec3b 100644 --- a/official/docs/responses/api-keys/create.json +++ b/official/docs/responses/api-keys/create.json @@ -2,7 +2,7 @@ "object": "ApiKey", "key": "", "mode": "test", - "created_at": "2022-01-29T00:02:36Z", + "created_at": "2026-10-01T17:19:24Z", "active": true, - "id": "ak_..." + "id": "ak_a092e6149cdc4c3da65cc62b10ba46a1" } diff --git a/official/docs/responses/api-keys/disable.json b/official/docs/responses/api-keys/disable.json index 6a879491..7629f979 100644 --- a/official/docs/responses/api-keys/disable.json +++ b/official/docs/responses/api-keys/disable.json @@ -2,7 +2,7 @@ "object": "ApiKey", "key": "", "mode": "test", - "created_at": "2022-01-29T00:02:36Z", + "created_at": "2026-10-01T17:19:26Z", "active": false, - "id": "ak_..." + "id": "ak_3628513daaa248f487b2184419964b11" } diff --git a/official/docs/responses/api-keys/enable.json b/official/docs/responses/api-keys/enable.json index 48c4648f..cf06418f 100644 --- a/official/docs/responses/api-keys/enable.json +++ b/official/docs/responses/api-keys/enable.json @@ -2,7 +2,7 @@ "object": "ApiKey", "key": "", "mode": "test", - "created_at": "2022-01-29T00:02:36Z", + "created_at": "2026-10-01T17:19:25Z", "active": true, - "id": "ak_..." + "id": "ak_0b001461ee0842ee9dad6e14ad437b54" } diff --git a/official/docs/ruby/current/api-keys/create.rb b/official/docs/ruby/current/api-keys/create.rb new file mode 100644 index 00000000..4e6b5526 --- /dev/null +++ b/official/docs/ruby/current/api-keys/create.rb @@ -0,0 +1,7 @@ +require 'easypost' + +client = EasyPost::Client.new(api_key: 'EASYPOST_API_KEY') + +api_key = client.api_key.create('test') + +puts api_key diff --git a/official/docs/ruby/current/api-keys/delete.rb b/official/docs/ruby/current/api-keys/delete.rb new file mode 100644 index 00000000..281192df --- /dev/null +++ b/official/docs/ruby/current/api-keys/delete.rb @@ -0,0 +1,5 @@ +require 'easypost' + +client = EasyPost::Client.new(api_key: 'EASYPOST_API_KEY') + +client.api_key.delete('ak_...') diff --git a/official/docs/ruby/current/api-keys/disable.rb b/official/docs/ruby/current/api-keys/disable.rb new file mode 100644 index 00000000..df10c39e --- /dev/null +++ b/official/docs/ruby/current/api-keys/disable.rb @@ -0,0 +1,7 @@ +require 'easypost' + +client = EasyPost::Client.new(api_key: 'EASYPOST_API_KEY') + +api_key = client.api_key.disable('ak_...') + +puts api_key diff --git a/official/docs/ruby/current/api-keys/enable.rb b/official/docs/ruby/current/api-keys/enable.rb new file mode 100644 index 00000000..0ac0d64d --- /dev/null +++ b/official/docs/ruby/current/api-keys/enable.rb @@ -0,0 +1,7 @@ +require 'easypost' + +client = EasyPost::Client.new(api_key: 'EASYPOST_API_KEY') + +api_key = client.api_key.enable('ak_...') + +puts api_key diff --git a/tools/build_doc_json_responses/tests/test_api_keys.py b/tools/build_doc_json_responses/tests/test_api_keys.py index ae0431e9..8f8b545b 100644 --- a/tools/build_doc_json_responses/tests/test_api_keys.py +++ b/tools/build_doc_json_responses/tests/test_api_keys.py @@ -1,10 +1,5 @@ -import os - import pytest -from builder.snippets import ( - build_response_snippet, - save_raw_json, -) +from builder.snippets import build_response_snippet @pytest.mark.vcr() @@ -15,54 +10,42 @@ def test_api_keys_retrieve(prod_client): build_response_snippet(interaction_index=1) -def test_api_keys_create(prod_client): - test_name = os.environ.get("PYTEST_CURRENT_TEST").split(":")[-1].split(" ")[0] - - response_dict = { - "object": "ApiKey", - "key": "", - "mode": "test", - "created_at": "2022-01-29T00:02:36Z", - "active": True, - "id": "ak_...", - } - - save_raw_json(test_name, response_dict) - - -def test_api_keys_delete(prod_client): - test_name = os.environ.get("PYTEST_CURRENT_TEST").split(":")[-1].split(" ")[0] - - response_dict = {} +@pytest.mark.vcr() +def test_api_keys_create(referral_customer_prod_client): + api_key = referral_customer_prod_client.api_keys.create(mode="test") - save_raw_json(test_name, response_dict) + try: + build_response_snippet() + finally: + referral_customer_prod_client.api_keys.delete(id=api_key.id) -def test_api_keys_enable(prod_client): - test_name = os.environ.get("PYTEST_CURRENT_TEST").split(":")[-1].split(" ")[0] +@pytest.mark.vcr() +def test_api_keys_delete(referral_customer_prod_client): + api_key = referral_customer_prod_client.api_keys.create(mode="test") + referral_customer_prod_client.api_keys.delete(id=api_key.id) - response_dict = { - "object": "ApiKey", - "key": "", - "mode": "test", - "created_at": "2022-01-29T00:02:36Z", - "active": True, - "id": "ak_...", - } + build_response_snippet(interaction_index=1) - save_raw_json(test_name, response_dict) +@pytest.mark.vcr() +def test_api_keys_enable(referral_customer_prod_client): + api_key = referral_customer_prod_client.api_keys.create(mode="test") + referral_customer_prod_client.api_keys.disable(id=api_key.id) + referral_customer_prod_client.api_keys.enable(id=api_key.id) -def test_api_keys_disable(prod_client): - test_name = os.environ.get("PYTEST_CURRENT_TEST").split(":")[-1].split(" ")[0] + try: + build_response_snippet(interaction_index=2) + finally: + referral_customer_prod_client.api_keys.delete(id=api_key.id) - response_dict = { - "object": "ApiKey", - "key": "", - "mode": "test", - "created_at": "2022-01-29T00:02:36Z", - "active": False, - "id": "ak_...", - } - save_raw_json(test_name, response_dict) +@pytest.mark.vcr() +def test_api_keys_disable(referral_customer_prod_client): + api_key = referral_customer_prod_client.api_keys.create(mode="test") + referral_customer_prod_client.api_keys.disable(id=api_key.id) + + try: + build_response_snippet(interaction_index=1) + finally: + referral_customer_prod_client.api_keys.delete(id=api_key.id) From 51a3221fbc826f39d7a06169128fb13259e3817c Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Thu, 1 Oct 2026 11:31:50 -0600 Subject: [PATCH 2/2] fix: port try/finally pattern when deleting response tooling --- .../tests/test_carrier_account.py | 29 +++++++----- .../tests/test_user.py | 9 ++-- .../tests/test_webhook.py | 46 +++++++++---------- 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/tools/build_doc_json_responses/tests/test_carrier_account.py b/tools/build_doc_json_responses/tests/test_carrier_account.py index 1b1fc7be..11414535 100644 --- a/tools/build_doc_json_responses/tests/test_carrier_account.py +++ b/tools/build_doc_json_responses/tests/test_carrier_account.py @@ -6,19 +6,23 @@ def test_carrier_accounts_create(prod_client, carrier_account_create): carrier_account = prod_client.carrier_account.create(**carrier_account_create) - prod_client.carrier_account.delete(id=carrier_account.id) # Delete the carrier account once it's done being tested. - - build_response_snippet() + try: + build_response_snippet() + finally: + # we are deleting the carrier account here so we don't keep sending events to a dead carrier account. + prod_client.carrier_account.delete(id=carrier_account.id) @pytest.mark.vcr() def test_carrier_accounts_retrieve(prod_client, carrier_account_create): carrier_account = prod_client.carrier_account.create(**carrier_account_create) - prod_client.carrier_account.retrieve(id=carrier_account.id) - prod_client.carrier_account.delete(id=carrier_account.id) # Delete the carrier account once it's done being tested. - - build_response_snippet(interaction_index=1) + try: + prod_client.carrier_account.retrieve(id=carrier_account.id) + build_response_snippet(interaction_index=1) + finally: + # we are deleting the carrier account here so we don't keep sending events to a dead carrier account. + prod_client.carrier_account.delete(id=carrier_account.id) @pytest.mark.vcr() @@ -32,11 +36,12 @@ def test_carrier_accounts_list(prod_client, page_size): def test_carrier_accounts_update(prod_client, carrier_account_create): carrier_account = prod_client.carrier_account.create(**carrier_account_create) - carrier_account = prod_client.carrier_account.update(id=carrier_account.id, description="My custom description") - - prod_client.carrier_account.delete(id=carrier_account.id) # Delete the carrier account once it's done being tested. - - build_response_snippet(interaction_index=1) + try: + carrier_account = prod_client.carrier_account.update(id=carrier_account.id, description="My custom description") + build_response_snippet(interaction_index=1) + finally: + # we are deleting the carrier account here so we don't keep sending events to a dead carrier account. + prod_client.carrier_account.delete(id=carrier_account.id) @pytest.mark.vcr() diff --git a/tools/build_doc_json_responses/tests/test_user.py b/tools/build_doc_json_responses/tests/test_user.py index 2d8ec969..c9c81897 100644 --- a/tools/build_doc_json_responses/tests/test_user.py +++ b/tools/build_doc_json_responses/tests/test_user.py @@ -6,10 +6,11 @@ def test_child_users_create(prod_client): user = prod_client.user.create(name="Test User") - # Delete the user so we don't clutter up the test environment - prod_client.user.delete(id=user.id) - - build_response_snippet() + try: + build_response_snippet() + finally: + # Delete the user so we don't clutter up the test environment + prod_client.user.delete(id=user.id) @pytest.mark.vcr() diff --git a/tools/build_doc_json_responses/tests/test_webhook.py b/tools/build_doc_json_responses/tests/test_webhook.py index 29344c7f..ea7fcb12 100644 --- a/tools/build_doc_json_responses/tests/test_webhook.py +++ b/tools/build_doc_json_responses/tests/test_webhook.py @@ -6,47 +6,47 @@ def test_webhooks_create(test_client, webhook_create): webhook = test_client.webhook.create(**webhook_create) - test_client.webhook.delete( - id=webhook.id - ) # we are deleting the webhook here so we don't keep sending events to a dead webhook. - - build_response_snippet() + try: + build_response_snippet() + finally: + # we are deleting the webhook here so we don't keep sending events to a dead webhook. + test_client.webhook.delete(id=webhook.id) @pytest.mark.vcr() def test_webhooks_retrieve(test_client, webhook_create): webhook = test_client.webhook.create(**webhook_create) - test_client.webhook.retrieve(id=webhook.id) - - test_client.webhook.delete( - id=webhook.id - ) # we are deleting the webhook here so we don't keep sending events to a dead webhook. - build_response_snippet(interaction_index=1) + try: + test_client.webhook.retrieve(id=webhook.id) + build_response_snippet(interaction_index=1) + finally: + # we are deleting the webhook here so we don't keep sending events to a dead webhook. + test_client.webhook.delete(id=webhook.id) @pytest.mark.vcr() def test_webhooks_list(test_client, webhook_create, page_size): webhook = test_client.webhook.create(**webhook_create) - test_client.webhook.all(page_size=page_size) - test_client.webhook.delete( - id=webhook.id - ) # we are deleting the webhook here so we don't keep sending events to a dead webhook. - - build_response_snippet(interaction_index=1) + try: + test_client.webhook.all(page_size=page_size) + build_response_snippet(interaction_index=1) + finally: + # we are deleting the webhook here so we don't keep sending events to a dead webhook. + test_client.webhook.delete(id=webhook.id) @pytest.mark.vcr() def test_webhooks_update(test_client, webhook_create, webhook_update): webhook = test_client.webhook.create(**webhook_create) - test_client.webhook.update(id=webhook.id, **webhook_update) - - test_client.webhook.delete( - id=webhook.id - ) # we are deleting the webhook here so we don't keep sending events to a dead webhook. - build_response_snippet(interaction_index=1) + try: + test_client.webhook.update(id=webhook.id, **webhook_update) + build_response_snippet(interaction_index=1) + finally: + # we are deleting the webhook here so we don't keep sending events to a dead webhook. + test_client.webhook.delete(id=webhook.id) @pytest.mark.vcr()