Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test fot the issue with cassette not recorded #206

Merged
merged 2 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions tests/test_E2E_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

import os
import unittest
import requests
import socket

from requre.helpers import record_requests
from requre.cassette import Cassette, StorageMode

PAGE = "http://example.com"


@record_requests
class TestWriteCls(unittest.TestCase):
def cassette_teardown(self, cassette: Cassette):
self.cassette = cassette
assert cassette.storage_file
assert cassette.storage_object
sf = self.cassette.storage_file
if sf and os.path.exists(sf):
os.remove(sf)

def test(self):
requests.get(PAGE)


class TestWrite(unittest.TestCase):
def cassette_setup(self, cassette: Cassette):
sf = self.cassette.storage_file
self.cassette.storage_object = {}
if sf and os.path.exists(sf):
os.remove(sf)

def cassette_teardown(self, cassette: Cassette):
self.cassette = cassette
assert cassette.storage_file
assert cassette.storage_object

@record_requests
def test(self):
self.test_executed = True
requests.get(PAGE)

def tearDown(self):
assert self.test_executed


@record_requests
class TestRead(unittest.TestCase):
def cassette_setup(self, cassette: Cassette):
# disable network for read mode to prove it read from file
if cassette.mode == StorageMode.read:
setattr(socket, "socket", lambda x: x)
Comment on lines +54 to +55
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain this a bit (in the code/comment)?


def cassette_teardown(self, cassette: Cassette):
self.cassette = cassette
assert cassette.storage_file
assert cassette.storage_object

def test(self):
requests.get(PAGE)


@record_requests
class TestFail(unittest.TestCase):
def test(self):
self.test_executed = True

def tearDown(self):
assert self.test_executed
62 changes: 62 additions & 0 deletions tests/test_data/test_E2E_example/TestRead.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
_requre:
DataTypes: 1
key_strategy: StorageKeysInspectSimple
version_storage_file: 3
requests.sessions:
send:
GET:
http://example.com/:
- metadata:
latency: 0.3191874027252197
module_call_list:
- unittest.case
- requre.record_and_replace
- tests.test_E2E_example
- requests.api
- requests.sessions
- requre.objects
- requre.cassette
- requests.sessions
- send
output:
__store_indicator: 1
_content:
"<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\
\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-type\"\
\ content=\"text/html; charset=utf-8\" />\n <meta name=\"viewport\"\
\ content=\"width=device-width, initial-scale=1\" />\n <style type=\"\
text/css\">\n body {\n background-color: #f0f0f2;\n margin:\
\ 0;\n padding: 0;\n font-family: -apple-system, system-ui,\
\ BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\"\
, Helvetica, Arial, sans-serif;\n \n }\n div {\n width:\
\ 600px;\n margin: 5em auto;\n padding: 2em;\n background-color:\
\ #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px\
\ 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color:\
\ #38488f;\n text-decoration: none;\n }\n @media (max-width:\
\ 700px) {\n div {\n margin: 0 auto;\n width:\
\ auto;\n }\n }\n </style> \n</head>\n\n<body>\n<div>\n\
\ <h1>Example Domain</h1>\n <p>This domain is for use in illustrative\
\ examples in documents. You may use this\n domain in literature without\
\ prior coordination or asking for permission.</p>\n <p><a href=\"\
https://www.iana.org/domains/example\">More information...</a></p>\n</div>\n\
</body>\n</html>\n"
_next: null
elapsed: 0.318763
encoding: UTF-8
headers:
Accept-Ranges: bytes
Age: "351312"
Cache-Control: max-age=604800
Content-Encoding: gzip
Content-Length: "648"
Content-Type: text/html; charset=UTF-8
Date: Fri, 18 Jun 2021 09:59:15 GMT
Etag: '"3147526947+ident"'
Expires: Fri, 25 Jun 2021 09:59:15 GMT
Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
Server: ECS (dcb/7F15)
Vary: Accept-Encoding
X-Cache: HIT
raw: !!binary ""
reason: OK
status_code: 200
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ requests.sessions:
GET:
https://fedoraproject.org/:
- metadata:
latency: 0.8099348545074463
latency: 0.6608798503875732
module_call_list:
- tests.test_pytest_fixtures
- requests.api
Expand Down Expand Up @@ -257,11 +257,11 @@ requests.sessions:
\ </ul> </div> </div> </div> </div> </div> </div> <script type=\"text/javascript\"\
\ src=\"/static/js/bundle.js?7e94bc65\"></script> </body> </html>"
_next: null
elapsed: 0.257042
elapsed: 0.100838
encoding: utf-8
headers:
Accept-Ranges: bytes
AppTime: D=928
AppTime: D=1281
Cache-Control: max-age=1800
Connection: Upgrade, Keep-Alive
Content-Encoding: gzip
Expand All @@ -273,20 +273,20 @@ requests.sessions:
script-src 'self'; style-src 'self' https://fonts.googleapis.com;
font-src 'self' https://fonts.gstatic.com; connect-src 'self' https://builds.coreos.fedoraproject.org; "
Content-Type: text/html; charset=utf-8
Date: Thu, 13 May 2021 12:47:14 GMT
ETag: '"40a2-5c234bb476694-gzip"'
Expires: Thu, 13 May 2021 13:17:14 GMT
Date: Fri, 18 Jun 2021 09:13:41 GMT
ETag: '"40a2-5c5059321cac9-gzip"'
Expires: Fri, 18 Jun 2021 09:43:41 GMT
Keep-Alive: timeout=15, max=500
Last-Modified: Thu, 13 May 2021 11:50:19 GMT
Last-Modified: Fri, 18 Jun 2021 07:50:17 GMT
Referrer-Policy: same-origin
Server: Apache
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
TCN: choice
Upgrade: h2
Vary: negotiate,accept,accept-language,Accept-Encoding
X-Content-Type-Options: nosniff
X-Fedora-ProxyServer: proxy32.fedoraproject.org
X-Fedora-RequestID: YJ0f0qKjyHFSkFKUZtKxtgAACNQ
X-Fedora-ProxyServer: proxy36.fedoraproject.org
X-Fedora-RequestID: YMxjxUuMh2JExvGrFIAqqwAADAg
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block
raw: !!binary ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ requests.sessions:
GET:
https://google.com/:
- metadata:
latency: 0.6050899028778076
latency: 0.3375589847564697
module_call_list:
- tests.test_pytest_fixtures
- requests.api
Expand All @@ -20,7 +20,7 @@ requests.sessions:
__store_indicator: 1
_content:
"<!DOCTYPE html><html lang=\"cs\" dir=\"ltr\"><head><style nonce=\"\
drfUWLDvzYKZuLKp3EHpoA\">\na, a:link, a:visited, a:active, a:hover {\n\
JufkzvlkX77/ZGjuKmOYHA\">\na, a:link, a:visited, a:active, a:hover {\n\
\ color: #1a73e8;\n text-decoration: none;\n}\nbody {\n font-family:\
\ Roboto,RobotoDraft,Helvetica,Arial,sans-serif;\n text-align: center;\n\
\ -ms-text-size-adjust: 100%;\n -moz-text-size-adjust: 100%;\n -webkit-text-size-adjust:\
Expand Down Expand Up @@ -109,8 +109,8 @@ requests.sessions:
\ type=\"hidden\" name=\"pc\" value=\"shp\"><input type=\"hidden\" name=\"\
continue\" value=\"https://www.google.com/\"><input type=\"hidden\" name=\"\
ca\" value=\"r\"><input type=\"hidden\" name=\"x\" value=\"8\"><input\
\ type=\"hidden\" name=\"v\" value=\"cb.20210509-17-p0.cs+FX+577\"><input\
\ type=\"hidden\" name=\"t\" value=\"ADw3F8j7UzqeJzmbjDV_9WykjQEUAduRzA:1620910033363\"\
\ type=\"hidden\" name=\"v\" value=\"cb.20210615-14-p0.cs+FX+192\"><input\
\ type=\"hidden\" name=\"t\" value=\"ADw3F8ilC5L4vMaWGXr_qYc1qMSX-YNawg:1624007620472\"\
><input type=\"hidden\" name=\"hl\" value=\"cs\"><input type=\"hidden\"\
\ name=\"src\" value=\"1\"><input type=\"submit\" value=\"Souhlas\xED\
m\" class=\"button\" aria-label=\"Vyj\xE1d\u0159it souhlas s\_pou\u017E\
Expand Down Expand Up @@ -187,22 +187,22 @@ requests.sessions:
>Z\xE1sady ochrany soukrom\xED</a> <a href=\"https://policies.google.com/terms?hl=cs&utm_source=ucb\"\
>Smluvn\xED podm\xEDnky</a></div></body></html>"
_next: null
elapsed: 0.4028
elapsed: 0.132254
encoding: utf-8
headers:
Alt-Svc:
h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443";
ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443";
ma=2592000; v="46,43"
h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-T051=":443";
ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443";
ma=2592000,quic=":443"; ma=2592000; v="46,43"
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Encoding: gzip
Content-Security-Policy:
script-src 'nonce-DyZ2VUTzo7xDYdRyDtzC8A' 'unsafe-inline';object-src
script-src 'nonce-J+6aQpGbm21n+/QBPPDPOQ' 'unsafe-inline';object-src
'none';base-uri 'self';report-uri /_/ConsentHttp/cspreport;worker-src
'self'
'self', require-trusted-types-for 'script';report-uri /_/ConsentHttp/cspreport
Content-Type: text/html; charset=utf-8
Cross-Origin-Resource-Policy: same-site
Date: Thu, 13 May 2021 12:47:13 GMT
Date: Fri, 18 Jun 2021 09:13:40 GMT
Expires: Mon, 01 Jan 1990 00:00:00 GMT
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Pragma: no-cache
Expand Down