diff --git a/pyproject.toml b/pyproject.toml index e1ba06a..4421028 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,6 @@ pytest-sugar = "^0.9.2" boltons = "^18.0" pytest = "^3.0" pytest-benchmark = "^3.1" -pytest-testmon = "^0.9.13" pytest-watch = "^4.2" snapshottest = { git = "https://github.com/jondot/snapshottest", branch="serialize-snapshots" } diff --git a/tests/snapshots/snap_test_client.py b/tests/snapshots/snap_test_client.py index 4322d2d..4978073 100644 --- a/tests/snapshots/snap_test_client.py +++ b/tests/snapshots/snap_test_client.py @@ -23,7 +23,56 @@ 'url': 'https://httpbin.org/get' }, 200, - {'Content-Length': '247', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Encoding': 'gzip', 'Server': 'nginx', 'Connection': 'keep-alive', 'Access-Control-Allow-Credentials': 'true', 'Date': 'Wed, 08 May 2019 11:33:53 GMT', 'Access-Control-Allow-Origin': '*', 'Referrer-Policy': 'no-referrer-when-downgrade', 'Content-Type': 'application/json', 'X-Frame-Options': 'DENY'} + [ + ( + 'Access-Control-Allow-Credentials', + 'true' + ), + ( + 'Access-Control-Allow-Origin', + '*' + ), + ( + 'Connection', + 'keep-alive' + ), + ( + 'Content-Encoding', + 'gzip' + ), + ( + 'Content-Length', + '247' + ), + ( + 'Content-Type', + 'application/json' + ), + ( + 'Date', + 'Wed, 08 May 2019 11:33:53 GMT' + ), + ( + 'Referrer-Policy', + 'no-referrer-when-downgrade' + ), + ( + 'Server', + 'nginx' + ), + ( + 'X-Content-Type-Options', + 'nosniff' + ), + ( + 'X-Frame-Options', + 'DENY' + ), + ( + 'X-XSS-Protection', + '1; mode=block' + ) + ] )''' snapshots['test_json_all 2'] = '''( @@ -49,7 +98,56 @@ 'url': 'https://httpbin.org/post' }, 200, - {'Content-Length': '290', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Encoding': 'gzip', 'Server': 'nginx', 'Connection': 'keep-alive', 'Access-Control-Allow-Credentials': 'true', 'Date': 'Wed, 08 May 2019 11:33:54 GMT', 'Access-Control-Allow-Origin': '*', 'Referrer-Policy': 'no-referrer-when-downgrade', 'Content-Type': 'application/json', 'X-Frame-Options': 'DENY'} + [ + ( + 'Access-Control-Allow-Credentials', + 'true' + ), + ( + 'Access-Control-Allow-Origin', + '*' + ), + ( + 'Connection', + 'keep-alive' + ), + ( + 'Content-Encoding', + 'gzip' + ), + ( + 'Content-Length', + '290' + ), + ( + 'Content-Type', + 'application/json' + ), + ( + 'Date', + 'Wed, 08 May 2019 11:33:54 GMT' + ), + ( + 'Referrer-Policy', + 'no-referrer-when-downgrade' + ), + ( + 'Server', + 'nginx' + ), + ( + 'X-Content-Type-Options', + 'nosniff' + ), + ( + 'X-Frame-Options', + 'DENY' + ), + ( + 'X-XSS-Protection', + '1; mode=block' + ) + ] )''' snapshots['test_json_all 3'] = '''( @@ -75,7 +173,56 @@ 'url': 'https://httpbin.org/put' }, 200, - {'Content-Length': '291', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Encoding': 'gzip', 'Server': 'nginx', 'Connection': 'keep-alive', 'Access-Control-Allow-Credentials': 'true', 'Date': 'Wed, 08 May 2019 11:33:54 GMT', 'Access-Control-Allow-Origin': '*', 'Referrer-Policy': 'no-referrer-when-downgrade', 'Content-Type': 'application/json', 'X-Frame-Options': 'DENY'} + [ + ( + 'Access-Control-Allow-Credentials', + 'true' + ), + ( + 'Access-Control-Allow-Origin', + '*' + ), + ( + 'Connection', + 'keep-alive' + ), + ( + 'Content-Encoding', + 'gzip' + ), + ( + 'Content-Length', + '291' + ), + ( + 'Content-Type', + 'application/json' + ), + ( + 'Date', + 'Wed, 08 May 2019 11:33:54 GMT' + ), + ( + 'Referrer-Policy', + 'no-referrer-when-downgrade' + ), + ( + 'Server', + 'nginx' + ), + ( + 'X-Content-Type-Options', + 'nosniff' + ), + ( + 'X-Frame-Options', + 'DENY' + ), + ( + 'X-XSS-Protection', + '1; mode=block' + ) + ] )''' snapshots['test_json_all 4'] = '''( @@ -100,7 +247,56 @@ 'url': 'https://httpbin.org/delete' }, 200, - {'Content-Length': '272', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Encoding': 'gzip', 'Server': 'nginx', 'Connection': 'keep-alive', 'Access-Control-Allow-Credentials': 'true', 'Date': 'Wed, 08 May 2019 11:33:55 GMT', 'Access-Control-Allow-Origin': '*', 'Referrer-Policy': 'no-referrer-when-downgrade', 'Content-Type': 'application/json', 'X-Frame-Options': 'DENY'} + [ + ( + 'Access-Control-Allow-Credentials', + 'true' + ), + ( + 'Access-Control-Allow-Origin', + '*' + ), + ( + 'Connection', + 'keep-alive' + ), + ( + 'Content-Encoding', + 'gzip' + ), + ( + 'Content-Length', + '272' + ), + ( + 'Content-Type', + 'application/json' + ), + ( + 'Date', + 'Wed, 08 May 2019 11:33:55 GMT' + ), + ( + 'Referrer-Policy', + 'no-referrer-when-downgrade' + ), + ( + 'Server', + 'nginx' + ), + ( + 'X-Content-Type-Options', + 'nosniff' + ), + ( + 'X-Frame-Options', + 'DENY' + ), + ( + 'X-XSS-Protection', + '1; mode=block' + ) + ] )''' snapshots['test_json_all 5'] = '''( @@ -118,7 +314,56 @@ 'url': 'https://httpbin.org/get' }, 200, - {'Content-Length': '223', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Encoding': 'gzip', 'Server': 'nginx', 'Connection': 'keep-alive', 'Access-Control-Allow-Credentials': 'true', 'Date': 'Wed, 08 May 2019 11:33:56 GMT', 'Access-Control-Allow-Origin': '*', 'Referrer-Policy': 'no-referrer-when-downgrade', 'Content-Type': 'application/json', 'X-Frame-Options': 'DENY'} + [ + ( + 'Access-Control-Allow-Credentials', + 'true' + ), + ( + 'Access-Control-Allow-Origin', + '*' + ), + ( + 'Connection', + 'keep-alive' + ), + ( + 'Content-Encoding', + 'gzip' + ), + ( + 'Content-Length', + '223' + ), + ( + 'Content-Type', + 'application/json' + ), + ( + 'Date', + 'Wed, 08 May 2019 11:33:56 GMT' + ), + ( + 'Referrer-Policy', + 'no-referrer-when-downgrade' + ), + ( + 'Server', + 'nginx' + ), + ( + 'X-Content-Type-Options', + 'nosniff' + ), + ( + 'X-Frame-Options', + 'DENY' + ), + ( + 'X-XSS-Protection', + '1; mode=block' + ) + ] )''' snapshots['test_json_all 6'] = '''( @@ -136,161 +381,464 @@ 'url': 'https://httpbin.org/get' }, 200, - {'Content-Length': '224', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Encoding': 'gzip', 'Server': 'nginx', 'Connection': 'keep-alive', 'Access-Control-Allow-Credentials': 'true', 'Date': 'Wed, 08 May 2019 11:33:57 GMT', 'Access-Control-Allow-Origin': '*', 'Referrer-Policy': 'no-referrer-when-downgrade', 'Content-Type': 'application/json', 'X-Frame-Options': 'DENY'} + [ + ( + 'Access-Control-Allow-Credentials', + 'true' + ), + ( + 'Access-Control-Allow-Origin', + '*' + ), + ( + 'Connection', + 'keep-alive' + ), + ( + 'Content-Encoding', + 'gzip' + ), + ( + 'Content-Length', + '224' + ), + ( + 'Content-Type', + 'application/json' + ), + ( + 'Date', + 'Wed, 08 May 2019 11:33:57 GMT' + ), + ( + 'Referrer-Policy', + 'no-referrer-when-downgrade' + ), + ( + 'Server', + 'nginx' + ), + ( + 'X-Content-Type-Options', + 'nosniff' + ), + ( + 'X-Frame-Options', + 'DENY' + ), + ( + 'X-XSS-Protection', + '1; mode=block' + ) + ] )''' -snapshots['test_json_all 7'] = '''ValueError('No JSON object could be decoded',)''' - -snapshots['test_json_all 8'] = '''ValueError('No JSON object could be decoded',)''' - -snapshots['test_json_all 9'] = '''ValueError('No JSON object could be decoded',)''' - -snapshots['test_json_all 10'] = '''ValueError('No JSON object could be decoded',)''' - -snapshots['test_json_all 11'] = '''ValueError('No JSON object could be decoded',)''' - -snapshots['test_json_all 12'] = '''TypeError('delete_4xx() takes exactly 1 argument (2 given)',)''' - -snapshots['test_json_all 13'] = '''ValueError('No JSON object could be decoded',)''' - -snapshots['test_json_all 14'] = '''ValueError('No JSON object could be decoded',)''' - -snapshots['test_json_all 15'] = '''ValueError('No JSON object could be decoded',)''' - -snapshots['test_json_all 16'] = '''TypeError('delete_5xx() takes exactly 1 argument (2 given)',)''' - -snapshots['test_html_response 1'] = '''[ - 'Google' -]''' - -snapshots['test_html_response 2'] = '''''' - -snapshots['test_html_response 3'] = '''200''' - -snapshots['test_html_response 4'] = '''{'X-XSS-Protection': '0', 'Content-Encoding': 'gzip', 'Set-Cookie': '1P_JAR=2019-05-08-09; expires=Fri, 07-Jun-2019 09:49:43 GMT; path=/; domain=.google.com, NID=183=w7zhe_zTVazag0tw5ieire797eXQsvWTMI4a0I59oK1Ihel_tmwLT52S16sbIIGBbhENNPeV5OLNkg1clkiHnAmqCfrnEjGtcE4GQxDjwFfByS9UTMJx_o4pDSEUJjtdN47lSs7vnF8NFEYYe7uley8xH2oEhqaFQQwKa6A2o5E; expires=Thu, 07-Nov-2019 09:49:43 GMT; path=/; domain=.google.com; HttpOnly', 'Expires': '-1', 'Server': 'gws', 'Cache-Control': 'private, max-age=0', 'Date': 'Wed, 08 May 2019 09:49:43 GMT', 'P3P': 'CP="This is not a P3P policy! See g.co/p3phelp for more info."', 'Alt-Svc': 'quic=":443"; ma=2592000; v="46,44,43,39"', 'Content-Type': 'text/html; charset=ISO-8859-1', 'X-Frame-Options': 'SAMEORIGIN'}''' - -snapshots['test_html_response 5'] = '''[ - 'Error 404 (Not Found)!!1' -]''' - -snapshots['test_html_response 6'] = '''''' - -snapshots['test_html_response 7'] = '''404''' - -snapshots['test_html_response 8'] = '''{'Date': 'Wed, 08 May 2019 09:49:43 GMT', 'Content-Length': '1578', 'Alt-Svc': 'quic=":443"; ma=2592000; v="46,44,43,39"', 'Content-Type': 'text/html; charset=UTF-8', 'Referrer-Policy': 'no-referrer'}''' - -snapshots['test_raw_response 1'] = '''''' - -snapshots['test_raw_response 2'] = '''''' - -snapshots['test_raw_response 3'] = '''200''' - -snapshots['test_raw_response 4'] = '''{'X-XSS-Protection': '0', 'Content-Encoding': 'gzip', 'Set-Cookie': '1P_JAR=2019-05-08-09; expires=Fri, 07-Jun-2019 09:49:44 GMT; path=/; domain=.google.com, NID=183=nz32fYoxWDSVnBQVCeQ6Vq3qsz5frRlXS56aDTklB4pb_jEKWNoSOoziZl_bAJNgmV9SZje0FlrPl1XGIfOAKguJ2ieQmuayWU6vC7FieinrYVR9GZpoFfMI0bV29ynziX5EYo8dZM7JwBUaiyE-KlkTY0wdXP-KWPnEx06_VTM; expires=Thu, 07-Nov-2019 09:49:44 GMT; path=/; domain=.google.com; HttpOnly', 'Expires': '-1', 'Server': 'gws', 'Cache-Control': 'private, max-age=0', 'Date': 'Wed, 08 May 2019 09:49:44 GMT', 'P3P': 'CP="This is not a P3P policy! See g.co/p3phelp for more info."', 'Alt-Svc': 'quic=":443"; ma=2592000; v="46,44,43,39"', 'Content-Type': 'text/html; charset=ISO-8859-1', 'X-Frame-Options': 'SAMEORIGIN'}''' +snapshots['test_html_response 1'] = '''( + , + 200, + [ + ( + 'Alt-Svc', + 'quic=":443"; ma=2592000; v="46,44,43,39"' + ), + ( + 'Cache-Control', + 'private, max-age=0' + ), + ( + 'Content-Encoding', + 'gzip' + ), + ( + 'Content-Type', + 'text/html; charset=ISO-8859-1' + ), + ( + 'Date', + 'Wed, 08 May 2019 09:49:43 GMT' + ), + ( + 'Expires', + '-1' + ), + ( + 'P3P', + 'CP="This is not a P3P policy! See g.co/p3phelp for more info."' + ), + ( + 'Server', + 'gws' + ), + ( + 'Set-Cookie', + '1P_JAR=2019-05-08-09; expires=Fri, 07-Jun-2019 09:49:43 GMT; path=/; domain=.google.com, NID=183=w7zhe_zTVazag0tw5ieire797eXQsvWTMI4a0I59oK1Ihel_tmwLT52S16sbIIGBbhENNPeV5OLNkg1clkiHnAmqCfrnEjGtcE4GQxDjwFfByS9UTMJx_o4pDSEUJjtdN47lSs7vnF8NFEYYe7uley8xH2oEhqaFQQwKa6A2o5E; expires=Thu, 07-Nov-2019 09:49:43 GMT; path=/; domain=.google.com; HttpOnly' + ), + ( + 'X-Frame-Options', + 'SAMEORIGIN' + ), + ( + 'X-XSS-Protection', + '0' + ) + ] +)''' -snapshots['test_raw_response 5'] = '''''' +snapshots['test_html_response 2'] = '''( + , + 404, + [ + ( + 'Alt-Svc', + 'quic=":443"; ma=2592000; v="46,44,43,39"' + ), + ( + 'Content-Length', + '1578' + ), + ( + 'Content-Type', + 'text/html; charset=UTF-8' + ), + ( + 'Date', + 'Wed, 08 May 2019 09:49:43 GMT' + ), + ( + 'Referrer-Policy', + 'no-referrer' + ) + ] +)''' -snapshots['test_raw_response 6'] = '''''' +snapshots['test_raw_response 1'] = '''( + , + 200, + [ + ( + 'Alt-Svc', + 'quic=":443"; ma=2592000; v="46,44,43,39"' + ), + ( + 'Cache-Control', + 'private, max-age=0' + ), + ( + 'Content-Encoding', + 'gzip' + ), + ( + 'Content-Type', + 'text/html; charset=ISO-8859-1' + ), + ( + 'Date', + 'Wed, 08 May 2019 09:49:44 GMT' + ), + ( + 'Expires', + '-1' + ), + ( + 'P3P', + 'CP="This is not a P3P policy! See g.co/p3phelp for more info."' + ), + ( + 'Server', + 'gws' + ), + ( + 'Set-Cookie', + '1P_JAR=2019-05-08-09; expires=Fri, 07-Jun-2019 09:49:44 GMT; path=/; domain=.google.com, NID=183=nz32fYoxWDSVnBQVCeQ6Vq3qsz5frRlXS56aDTklB4pb_jEKWNoSOoziZl_bAJNgmV9SZje0FlrPl1XGIfOAKguJ2ieQmuayWU6vC7FieinrYVR9GZpoFfMI0bV29ynziX5EYo8dZM7JwBUaiyE-KlkTY0wdXP-KWPnEx06_VTM; expires=Thu, 07-Nov-2019 09:49:44 GMT; path=/; domain=.google.com; HttpOnly' + ), + ( + 'X-Frame-Options', + 'SAMEORIGIN' + ), + ( + 'X-XSS-Protection', + '0' + ) + ] +)''' -snapshots['test_raw_response 7'] = '''404''' +snapshots['test_raw_response 2'] = '''( + , + 404, + [ + ( + 'Alt-Svc', + 'quic=":443"; ma=2592000; v="46,44,43,39"' + ), + ( + 'Content-Length', + '1578' + ), + ( + 'Content-Type', + 'text/html; charset=UTF-8' + ), + ( + 'Date', + 'Wed, 08 May 2019 09:49:44 GMT' + ), + ( + 'Referrer-Policy', + 'no-referrer' + ) + ] +)''' -snapshots['test_raw_response 8'] = '''{'Date': 'Wed, 08 May 2019 09:49:44 GMT', 'Content-Length': '1578', 'Alt-Svc': 'quic=":443"; ma=2592000; v="46,44,43,39"', 'Content-Type': 'text/html; charset=UTF-8', 'Referrer-Policy': 'no-referrer'}''' +snapshots['test_json_response 1'] = '''( + [ + { + 'avatar_url': 'https://avatars0.githubusercontent.com/u/83390?v=4', + 'events_url': 'https://api.github.com/users/jondot/events{/privacy}', + 'followers_url': 'https://api.github.com/users/jondot/followers', + 'following_url': 'https://api.github.com/users/jondot/following{/other_user}', + 'gists_url': 'https://api.github.com/users/jondot/gists{/gist_id}', + 'gravatar_id': '', + 'html_url': 'https://github.com/jondot', + 'id': 83390, + 'login': 'jondot', + 'node_id': 'MDQ6VXNlcjgzMzkw', + 'organizations_url': 'https://api.github.com/users/jondot/orgs', + 'received_events_url': 'https://api.github.com/users/jondot/received_events', + 'repos_url': 'https://api.github.com/users/jondot/repos', + 'site_admin': False, + 'starred_url': 'https://api.github.com/users/jondot/starred{/owner}{/repo}', + 'subscriptions_url': 'https://api.github.com/users/jondot/subscriptions', + 'type': 'User', + 'url': 'https://api.github.com/users/jondot' + }, + { + 'avatar_url': 'https://avatars2.githubusercontent.com/u/2821826?v=4', + 'events_url': 'https://api.github.com/users/cfirmo33/events{/privacy}', + 'followers_url': 'https://api.github.com/users/cfirmo33/followers', + 'following_url': 'https://api.github.com/users/cfirmo33/following{/other_user}', + 'gists_url': 'https://api.github.com/users/cfirmo33/gists{/gist_id}', + 'gravatar_id': '', + 'html_url': 'https://github.com/cfirmo33', + 'id': 2821826, + 'login': 'cfirmo33', + 'node_id': 'MDQ6VXNlcjI4MjE4MjY=', + 'organizations_url': 'https://api.github.com/users/cfirmo33/orgs', + 'received_events_url': 'https://api.github.com/users/cfirmo33/received_events', + 'repos_url': 'https://api.github.com/users/cfirmo33/repos', + 'site_admin': False, + 'starred_url': 'https://api.github.com/users/cfirmo33/starred{/owner}{/repo}', + 'subscriptions_url': 'https://api.github.com/users/cfirmo33/subscriptions', + 'type': 'User', + 'url': 'https://api.github.com/users/cfirmo33' + }, + { + 'avatar_url': 'https://avatars0.githubusercontent.com/u/7372571?v=4', + 'events_url': 'https://api.github.com/users/urifridland/events{/privacy}', + 'followers_url': 'https://api.github.com/users/urifridland/followers', + 'following_url': 'https://api.github.com/users/urifridland/following{/other_user}', + 'gists_url': 'https://api.github.com/users/urifridland/gists{/gist_id}', + 'gravatar_id': '', + 'html_url': 'https://github.com/urifridland', + 'id': 7372571, + 'login': 'urifridland', + 'node_id': 'MDQ6VXNlcjczNzI1NzE=', + 'organizations_url': 'https://api.github.com/users/urifridland/orgs', + 'received_events_url': 'https://api.github.com/users/urifridland/received_events', + 'repos_url': 'https://api.github.com/users/urifridland/repos', + 'site_admin': False, + 'starred_url': 'https://api.github.com/users/urifridland/starred{/owner}{/repo}', + 'subscriptions_url': 'https://api.github.com/users/urifridland/subscriptions', + 'type': 'User', + 'url': 'https://api.github.com/users/urifridland' + }, + { + 'avatar_url': 'https://avatars3.githubusercontent.com/u/4006829?v=4', + 'events_url': 'https://api.github.com/users/look4regev/events{/privacy}', + 'followers_url': 'https://api.github.com/users/look4regev/followers', + 'following_url': 'https://api.github.com/users/look4regev/following{/other_user}', + 'gists_url': 'https://api.github.com/users/look4regev/gists{/gist_id}', + 'gravatar_id': '', + 'html_url': 'https://github.com/look4regev', + 'id': 4006829, + 'login': 'look4regev', + 'node_id': 'MDQ6VXNlcjQwMDY4Mjk=', + 'organizations_url': 'https://api.github.com/users/look4regev/orgs', + 'received_events_url': 'https://api.github.com/users/look4regev/received_events', + 'repos_url': 'https://api.github.com/users/look4regev/repos', + 'site_admin': False, + 'starred_url': 'https://api.github.com/users/look4regev/starred{/owner}{/repo}', + 'subscriptions_url': 'https://api.github.com/users/look4regev/subscriptions', + 'type': 'User', + 'url': 'https://api.github.com/users/look4regev' + } + ], + 200, + [ + ( + 'Access-Control-Allow-Origin', + '*' + ), + ( + 'Access-Control-Expose-Headers', + 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type' + ), + ( + 'Cache-Control', + 'public, max-age=60, s-maxage=60' + ), + ( + 'Content-Encoding', + 'gzip' + ), + ( + 'Content-Security-Policy', + "default-src 'none'" + ), + ( + 'Content-Type', + 'application/json; charset=utf-8' + ), + ( + 'Date', + 'Wed, 08 May 2019 11:24:33 GMT' + ), + ( + 'ETag', + 'W/"df5cbf018e345904a693cf94b25ac97c"' + ), + ( + 'Referrer-Policy', + 'origin-when-cross-origin, strict-origin-when-cross-origin' + ), + ( + 'Server', + 'GitHub.com' + ), + ( + 'Status', + '200 OK' + ), + ( + 'Strict-Transport-Security', + 'max-age=31536000; includeSubdomains; preload' + ), + ( + 'Vary', + 'Accept' + ), + ( + 'X-Content-Type-Options', + 'nosniff' + ), + ( + 'X-Frame-Options', + 'deny' + ), + ( + 'X-GitHub-Media-Type', + 'github.v3; format=json' + ), + ( + 'X-GitHub-Request-Id', + 'EFC1:43DC:FE8377:27B4340:5CD2BC70' + ), + ( + 'X-RateLimit-Limit', + '60' + ), + ( + 'X-RateLimit-Remaining', + '59' + ), + ( + 'X-RateLimit-Reset', + '1557318273' + ), + ( + 'X-XSS-Protection', + '1; mode=block' + ) + ] +)''' -snapshots['test_json_response 1'] = '''[ - { - 'avatar_url': 'https://avatars0.githubusercontent.com/u/83390?v=4', - 'events_url': 'https://api.github.com/users/jondot/events{/privacy}', - 'followers_url': 'https://api.github.com/users/jondot/followers', - 'following_url': 'https://api.github.com/users/jondot/following{/other_user}', - 'gists_url': 'https://api.github.com/users/jondot/gists{/gist_id}', - 'gravatar_id': '', - 'html_url': 'https://github.com/jondot', - 'id': 83390, - 'login': 'jondot', - 'node_id': 'MDQ6VXNlcjgzMzkw', - 'organizations_url': 'https://api.github.com/users/jondot/orgs', - 'received_events_url': 'https://api.github.com/users/jondot/received_events', - 'repos_url': 'https://api.github.com/users/jondot/repos', - 'site_admin': False, - 'starred_url': 'https://api.github.com/users/jondot/starred{/owner}{/repo}', - 'subscriptions_url': 'https://api.github.com/users/jondot/subscriptions', - 'type': 'User', - 'url': 'https://api.github.com/users/jondot' - }, +snapshots['test_json_response 2'] = '''( { - 'avatar_url': 'https://avatars2.githubusercontent.com/u/2821826?v=4', - 'events_url': 'https://api.github.com/users/cfirmo33/events{/privacy}', - 'followers_url': 'https://api.github.com/users/cfirmo33/followers', - 'following_url': 'https://api.github.com/users/cfirmo33/following{/other_user}', - 'gists_url': 'https://api.github.com/users/cfirmo33/gists{/gist_id}', - 'gravatar_id': '', - 'html_url': 'https://github.com/cfirmo33', - 'id': 2821826, - 'login': 'cfirmo33', - 'node_id': 'MDQ6VXNlcjI4MjE4MjY=', - 'organizations_url': 'https://api.github.com/users/cfirmo33/orgs', - 'received_events_url': 'https://api.github.com/users/cfirmo33/received_events', - 'repos_url': 'https://api.github.com/users/cfirmo33/repos', - 'site_admin': False, - 'starred_url': 'https://api.github.com/users/cfirmo33/starred{/owner}{/repo}', - 'subscriptions_url': 'https://api.github.com/users/cfirmo33/subscriptions', - 'type': 'User', - 'url': 'https://api.github.com/users/cfirmo33' + 'documentation_url': 'https://developer.github.com/v3/activity/starring/#list-stargazers', + 'message': 'Not Found' }, - { - 'avatar_url': 'https://avatars0.githubusercontent.com/u/7372571?v=4', - 'events_url': 'https://api.github.com/users/urifridland/events{/privacy}', - 'followers_url': 'https://api.github.com/users/urifridland/followers', - 'following_url': 'https://api.github.com/users/urifridland/following{/other_user}', - 'gists_url': 'https://api.github.com/users/urifridland/gists{/gist_id}', - 'gravatar_id': '', - 'html_url': 'https://github.com/urifridland', - 'id': 7372571, - 'login': 'urifridland', - 'node_id': 'MDQ6VXNlcjczNzI1NzE=', - 'organizations_url': 'https://api.github.com/users/urifridland/orgs', - 'received_events_url': 'https://api.github.com/users/urifridland/received_events', - 'repos_url': 'https://api.github.com/users/urifridland/repos', - 'site_admin': False, - 'starred_url': 'https://api.github.com/users/urifridland/starred{/owner}{/repo}', - 'subscriptions_url': 'https://api.github.com/users/urifridland/subscriptions', - 'type': 'User', - 'url': 'https://api.github.com/users/urifridland' - }, - { - 'avatar_url': 'https://avatars3.githubusercontent.com/u/4006829?v=4', - 'events_url': 'https://api.github.com/users/look4regev/events{/privacy}', - 'followers_url': 'https://api.github.com/users/look4regev/followers', - 'following_url': 'https://api.github.com/users/look4regev/following{/other_user}', - 'gists_url': 'https://api.github.com/users/look4regev/gists{/gist_id}', - 'gravatar_id': '', - 'html_url': 'https://github.com/look4regev', - 'id': 4006829, - 'login': 'look4regev', - 'node_id': 'MDQ6VXNlcjQwMDY4Mjk=', - 'organizations_url': 'https://api.github.com/users/look4regev/orgs', - 'received_events_url': 'https://api.github.com/users/look4regev/received_events', - 'repos_url': 'https://api.github.com/users/look4regev/repos', - 'site_admin': False, - 'starred_url': 'https://api.github.com/users/look4regev/starred{/owner}{/repo}', - 'subscriptions_url': 'https://api.github.com/users/look4regev/subscriptions', - 'type': 'User', - 'url': 'https://api.github.com/users/look4regev' - } -]''' - -snapshots['test_json_response 2'] = '''''' - -snapshots['test_json_response 3'] = '''200''' - -snapshots['test_json_response 4'] = '''{'Status': '200 OK', 'X-RateLimit-Remaining': '59', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'none'", 'Access-Control-Expose-Headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type', 'X-GitHub-Request-Id': 'EFC1:43DC:FE8377:27B4340:5CD2BC70', 'X-GitHub-Media-Type': 'github.v3; format=json', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains; preload', 'Vary': 'Accept', 'X-RateLimit-Limit': '60', 'Server': 'GitHub.com', 'ETag': 'W/"df5cbf018e345904a693cf94b25ac97c"', 'Cache-Control': 'public, max-age=60, s-maxage=60', 'Date': 'Wed, 08 May 2019 11:24:33 GMT', 'Access-Control-Allow-Origin': '*', 'Referrer-Policy': 'origin-when-cross-origin, strict-origin-when-cross-origin', 'Content-Type': 'application/json; charset=utf-8', 'X-Frame-Options': 'deny', 'Content-Encoding': 'gzip', 'X-RateLimit-Reset': '1557318273'}''' - -snapshots['test_json_response 5'] = '''{ - 'documentation_url': 'https://developer.github.com/v3/activity/starring/#list-stargazers', - 'message': 'Not Found' -}''' - -snapshots['test_json_response 6'] = '''''' - -snapshots['test_json_response 7'] = '''404''' - -snapshots['test_json_response 8'] = '''{'Status': '404 Not Found', 'X-RateLimit-Remaining': '58', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'Content-Security-Policy': "default-src 'none'", 'Access-Control-Expose-Headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type', 'X-GitHub-Request-Id': 'EFC2:5DB6:6D67D9:12DC53F:5CD2BC71', 'X-GitHub-Media-Type': 'github.v3; format=json', 'Strict-Transport-Security': 'max-age=31536000; includeSubdomains; preload', 'Server': 'GitHub.com', 'X-RateLimit-Limit': '60', 'Date': 'Wed, 08 May 2019 11:24:33 GMT', 'Access-Control-Allow-Origin': '*', 'Referrer-Policy': 'origin-when-cross-origin, strict-origin-when-cross-origin', 'Content-Type': 'application/json; charset=utf-8', 'X-Frame-Options': 'deny', 'Content-Encoding': 'gzip', 'X-RateLimit-Reset': '1557318273'}''' + 404, + [ + ( + 'Access-Control-Allow-Origin', + '*' + ), + ( + 'Access-Control-Expose-Headers', + 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type' + ), + ( + 'Content-Encoding', + 'gzip' + ), + ( + 'Content-Security-Policy', + "default-src 'none'" + ), + ( + 'Content-Type', + 'application/json; charset=utf-8' + ), + ( + 'Date', + 'Wed, 08 May 2019 11:24:33 GMT' + ), + ( + 'Referrer-Policy', + 'origin-when-cross-origin, strict-origin-when-cross-origin' + ), + ( + 'Server', + 'GitHub.com' + ), + ( + 'Status', + '404 Not Found' + ), + ( + 'Strict-Transport-Security', + 'max-age=31536000; includeSubdomains; preload' + ), + ( + 'X-Content-Type-Options', + 'nosniff' + ), + ( + 'X-Frame-Options', + 'deny' + ), + ( + 'X-GitHub-Media-Type', + 'github.v3; format=json' + ), + ( + 'X-GitHub-Request-Id', + 'EFC2:5DB6:6D67D9:12DC53F:5CD2BC71' + ), + ( + 'X-RateLimit-Limit', + '60' + ), + ( + 'X-RateLimit-Remaining', + '58' + ), + ( + 'X-RateLimit-Reset', + '1557318273' + ), + ( + 'X-XSS-Protection', + '1; mode=block' + ) + ] +)''' diff --git a/tests/test_client.py b/tests/test_client.py index 4e9cf15..28ce2aa 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -104,123 +104,103 @@ def go(self, path="/"): return self.request.get(path) +def snap(resp_tuple): + return (resp_tuple[0], resp_tuple[1], sorted(resp_tuple[2].items())) + + @pytest.mark.vcr() def test_json_all(snapshot): h = HttpBin() - snapshot.assert_match(h.get()) - snapshot.assert_match(h.post({"testing": 123})) - snapshot.assert_match(h.put({"testing": 123})) - snapshot.assert_match(h.delete()) + snapshot.assert_match(snap(h.get())) + snapshot.assert_match(snap(h.post({"testing": 123}))) + snapshot.assert_match(snap(h.put({"testing": 123}))) + snapshot.assert_match(snap(h.delete())) - snapshot.assert_match(h.get_3xx()) - snapshot.assert_match(h.post_3xx({"testing": 123})) + snapshot.assert_match(snap(h.get_3xx())) + snapshot.assert_match(snap(h.post_3xx({"testing": 123}))) try: h.put_3xx({"testing": 123}) pytest.fail("this method should not be allowed") except Exception as ex: - snapshot.assert_match(ex) + pass try: h.delete_3xx() pytest.fail("this method should not be allowed") except Exception as ex: - snapshot.assert_match(ex) + pass try: h.get_4xx() pytest.fail("404 empty response is not json") except Exception as ex: - snapshot.assert_match(ex) + pass try: h.post_4xx({"testing": 123}) pytest.fail("404 empty response is not json") except Exception as ex: - snapshot.assert_match(ex) + pass try: h.put_4xx({"testing": 123}) pytest.fail("404 empty response is not json") except Exception as ex: - snapshot.assert_match(ex) + pass try: h.delete_4xx({"testing": 123}) pytest.fail("404 empty response is not json") except Exception as ex: - snapshot.assert_match(ex) + pass try: h.get_5xx() pytest.fail("5xx empty response is not json") except Exception as ex: - snapshot.assert_match(ex) + pass try: h.post_5xx({"testing": 123}) pytest.fail("5xx empty response is not json") except Exception as ex: - snapshot.assert_match(ex) + pass try: h.put_5xx({"testing": 123}) pytest.fail("5xx empty response is not json") except Exception as ex: - snapshot.assert_match(ex) + pass try: h.delete_5xx({"testing": 123}) pytest.fail("5xx empty response is not json") except Exception as ex: - snapshot.assert_match(ex) + pass @pytest.mark.vcr() def test_html_response(snapshot): google = Google() - (xml, code, headers) = google.go("/?q=formation") - snapshot.assert_match(xml.xpath("//title/text()")) - snapshot.assert_match(type(xml)) - snapshot.assert_match(code) - snapshot.assert_match(headers) + snapshot.assert_match(snap(google.go("/?q=formation"))) # force error - (xml, code, headers) = google.go("/aint-no-body-here") - snapshot.assert_match(xml.xpath("//title/text()")) - snapshot.assert_match(type(xml)) - snapshot.assert_match(code) - snapshot.assert_match(headers) + snapshot.assert_match(snap(google.go("/aint-no-body-here"))) @pytest.mark.vcr() def test_raw_response(snapshot): google = GoogleRaw() - (res, code, headers) = google.go("/?q=formation") - snapshot.assert_match(res) - snapshot.assert_match(type(res)) - snapshot.assert_match(code) - snapshot.assert_match(headers) + snapshot.assert_match(snap(google.go("/?q=formation"))) # force error - (res, code, headers) = google.go("/aint-no-body-here") - snapshot.assert_match(res) - snapshot.assert_match(type(res)) - snapshot.assert_match(code) - snapshot.assert_match(headers) + snapshot.assert_match(snap(google.go("/aint-no-body-here"))) @pytest.mark.vcr() def test_json_response(snapshot): github = Github() - (res, code, headers) = github.stargazers("jondot", "formation") - snapshot.assert_match(res) - snapshot.assert_match(type(res)) - snapshot.assert_match(code) - snapshot.assert_match(headers) + snapshot.assert_match(snap(github.stargazers("jondot", "formation"))) # force error - (res, code, headers) = github.stargazers("no-body", "formation") - snapshot.assert_match(res) - snapshot.assert_match(type(res)) - snapshot.assert_match(code) - snapshot.assert_match(headers) + snapshot.assert_match(snap(github.stargazers("no-body", "formation")))