-
Notifications
You must be signed in to change notification settings - Fork 0
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
chore(test): implement unit tests #11
Conversation
r = requests.post( | ||
URL, | ||
json=alert, | ||
headers=request.headers, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i had a bad feeling when changing this just to make testing easier, but the longer i think about it, the more it seems like the two implementations achieve the exact same thing under the hood.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved to session exactly because headers=request.headers didn't work directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I know... and i'm pretty sure i've done this before as well but i can't seem to remember why it didn't work directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# By using the 'with' statement we are sure the session is closed, thus we
# avoid leaving sockets open which can trigger a ResourceWarning in some
# cases, and look like a memory leak in others.
with sessions.Session() as session:
return session.request(method=method, url=url, **kwargs)
is whole request
function
post
function is return request("post", url, data=data, json=json, **kwargs)
request headers is just plain dict, while Flask request is werzeug.EnvironHeaders inheriting from werkzeug.Headers, closest those classes do is implement __iter__
, so headers=dict(request.headers)
?
"Host": "localhost", | ||
"Content-Type": "application/json", | ||
"Content-Length": "451", | ||
"Key": "SECRET", # TODO: redact this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "Key" header is a bit of a stand-in. Let's check if there are any sensitive headers that we want to scrub or potentially just implement an allow list to be on the really safe side.
name = "scrubbed" | ||
|
||
[build-system] | ||
build-backend = "flit_core.buildapi" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually lean towards using poetry
for everything to align myself with other efforts in the enterprise. flit
is much more lightweight in comparison, and it doesn't really matter during runtime anyway.
I did not know about/remember pyinstaller
and the only reason i touched these parts is because it helped me get pytest up and running without more complex folders whatnot.
For sure something we want to revisit before merging this, I'll gladly refactor back to requirement*txt if we want to stick with that route.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
going with pyproject lgtm too
}, | ||
], | ||
} | ||
assert upstream_request.last_request.headers == { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This list doesn't reflect what probably should be happening...
>>> import requests
>>> requests.sessions.Session().headers
{'User-Agent': 'python-requests/2.31.0', 'Accept-Encoding': 'gzip, deflate, br', 'Accept': '*/*', 'Connection': 'keep-alive'}
I verified that scrubbed does what it says on the box by writing comprehensive unit tests and the results look promising enough for this early draft PR.
I'm pretty sure this will fail fast and i'll try to follow up with some more details once i get the CI results i'm looking for :)