-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Integration test for create configuration
It integrates the client with the API, saves the response and use it in the next tests. It includes the betamax library to record and replay tests so we don't rely on hand written mocks.
- Loading branch information
1 parent
8576fbe
commit 9d00945
Showing
6 changed files
with
190 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ pytest = "*" | |
sphinx = "*" | ||
coverage = "*" | ||
proselint = "*" | ||
betamax = "*" | ||
|
||
[packages] | ||
requests = "*" | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Configuration for all test cases.""" | ||
import json | ||
import os | ||
|
||
import betamax | ||
|
||
from betamax.serializers import JSONSerializer | ||
|
||
|
||
class PrettyJSONSerializer(JSONSerializer): | ||
"""Serializer that saves all cassettes | ||
in a human readable format, indenting and sorting keys.""" | ||
name = 'prettyjson' | ||
|
||
def serialize(self, cassette_data): | ||
return json.dumps( | ||
cassette_data, | ||
sort_keys=True, | ||
indent=2, | ||
separators=(',', ': '), | ||
) | ||
|
||
|
||
token = os.environ.get('AZ_TOKEN', 'foobar') | ||
|
||
# Register pretty JSON serializer | ||
betamax.Betamax.register_serializer(PrettyJSONSerializer) | ||
|
||
with betamax.Betamax.configure() as config: | ||
# Directory to save/load requests and responses | ||
# executed by betamax | ||
config.cassette_library_dir = 'tests/integration/cassettes' | ||
# Change real token by this placeholder | ||
config.define_cassette_placeholder('<AUTH_TOKEN>', token) | ||
# Save formatted JSON instead of one line files | ||
config.default_cassette_options['serialize_with'] = 'prettyjson' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{ | ||
"http_interactions": [ | ||
{ | ||
"recorded_at": "2018-06-06T02:20:05", | ||
"request": { | ||
"body": { | ||
"encoding": "utf-8", | ||
"string": "{\"name\": \"Dummy configuration\", \"origin_address\": \"www.example.com\", \"origin_host_header\": \"ww2.example.com\", \"cname\": [\"www.example-cname.com\"], \"cname_access_only\": false, \"delivery_protocol\": \"http\", \"origin_protocol_policy\": \"preserve\", \"browser_cache_settings\": false, \"browser_cache_settings_maximum_ttl\": 0, \"cdn_cache_settings\": \"honor\", \"cdn_cache_settings_maximum_ttl\": 0}" | ||
}, | ||
"headers": { | ||
"Accept": [ | ||
"application/json; version=1" | ||
], | ||
"Accept-Charset": [ | ||
"utf-8" | ||
], | ||
"Accept-Encoding": [ | ||
"gzip, deflate" | ||
], | ||
"Authorization": [ | ||
"token <AUTH_TOKEN>" | ||
], | ||
"Connection": [ | ||
"keep-alive" | ||
], | ||
"Content-Length": [ | ||
"382" | ||
], | ||
"Content-Type": [ | ||
"application/json" | ||
], | ||
"User-Agent": [ | ||
"python-requests/2.18.4" | ||
] | ||
}, | ||
"method": "POST", | ||
"uri": "https://api.azion.net/content_delivery/configurations" | ||
}, | ||
"response": { | ||
"body": { | ||
"encoding": null, | ||
"string": "{\"id\":1528252734,\"name\":\"Dummy configuration\",\"domain_name\":\"109445k.ha.azioncdn.net\",\"active\":true,\"delivery_protocol\":\"http\",\"digital_certificate\":null,\"cname_access_only\":false,\"rawlogs\":false,\"cname\":[\"www.example-cname.com\"]}" | ||
}, | ||
"headers": { | ||
"Allow": [ | ||
"GET, POST, OPTIONS" | ||
], | ||
"Connection": [ | ||
"keep-alive" | ||
], | ||
"Content-Language": [ | ||
"en" | ||
], | ||
"Content-Length": [ | ||
"230" | ||
], | ||
"Content-Type": [ | ||
"application/json" | ||
], | ||
"Date": [ | ||
"Wed, 06 Jun 2018 02:20:05 GMT" | ||
], | ||
"Server": [ | ||
"azion webserver" | ||
], | ||
"Vary": [ | ||
"Accept-Language, Cookie" | ||
], | ||
"X-Frame-Options": [ | ||
"SAMEORIGIN" | ||
], | ||
"X-RateLimit-Limit": [ | ||
"20" | ||
], | ||
"X-RateLimit-Remaining": [ | ||
"18" | ||
], | ||
"X-RateLimit-Reset": [ | ||
"2018-06-06T02:21:04.340405" | ||
], | ||
"x-content-type-options": [ | ||
"nosniff" | ||
], | ||
"x-xss-protection": [ | ||
"1; mode=block" | ||
] | ||
}, | ||
"status": { | ||
"code": 201, | ||
"message": "CREATED" | ||
}, | ||
"url": "https://api.azion.net/content_delivery/configurations" | ||
} | ||
} | ||
], | ||
"recorded_with": "betamax/0.8.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
|
||
from azion.client import Azion | ||
from azion.models import Configuration | ||
|
||
import betamax | ||
|
||
token = os.environ.get('AZ_TOKEN', 'foobar') | ||
|
||
|
||
class TestConfiguration(object): | ||
|
||
def test_create_configuration(self): | ||
client = Azion(token) | ||
recorder = betamax.Betamax(client.session) | ||
|
||
with recorder.use_cassette('Configuration_create'): | ||
configuration = client.create_configuration( | ||
'Dummy configuration', 'www.example.com', 'ww2.example.com', | ||
cname=['www.example-cname.com'], delivery_protocol='http') | ||
assert isinstance(configuration, Configuration) | ||
assert configuration.active is True | ||
assert configuration.id | ||
assert configuration.cname == ['www.example-cname.com'] | ||
assert configuration.digital_certificate is None | ||
assert configuration.rawlogs is False | ||
assert configuration.delivery_protocol == 'http' | ||
assert configuration.cname_access_only is False | ||
assert configuration.name == 'Dummy configuration' | ||
assert configuration.domain_name |