Closed mdhaisne closed 1 year ago
I would go for https://github.com/getsentry/responses
once PR https://github.com/getsentry/responses/pull/624 is merged, you will be able to record all the HTTP calls and their reponses
I would go for https://github.com/getsentry/responses
once PR getsentry/responses#624 is merged, you will be able to record all the HTTP calls and their reponses
Thank for your reply. It does not seem to answer my need as I understand it. I don't want to record HTTP traffic. I'd like to avoid the need of an artifactory instance / server and have everything local. e.g. ArtifactoryPath("my_local_assets/")
.
But maybe I've misunderstood your point
but if you just want to see that your code does what it supposed to do, then comparing HTTP traffic is enough, no?
but if you just want to see that your code does what it supposed to do, then comparing HTTP traffic is enough, no?
It means that I need to deploy an artifactory instance ? (So that there is a traffic)
Quick and dirty example:
# File structure
artifactory_agent.py
artifactory_agent_test.py
assets/
foo_1.txt
foo_2.txt
foo_3.txt
# unit test
def test_get_foos():
agent = ArtifactoryAgent("assets")
foos = agent.get_foos()
assert len(foos) == 3
the constraint is that ArtifactoryPath
should use local assets this why I'm looking for mocking mechanisms at first sights.
But maybe there is an easier way to perform such tests. I'm kind of new in this repo.
this library sends HTTP requests. If you want to test, that right requests were executed in right order, then mock them
Hi! I'd go with using monkeypatch and mocks for that https://docs.pytest.org/en/7.1.x/how-to/monkeypatch.html If you don't use specific method - it's fine to believe that the library works and only what you need to test is the script's logic.
IMO, recording http requests and responses are useful for testing THIS library, but not the script with logic.
@allburov Here are pros and cons With http you can easily write tests in a matter of minutes
With monkeypatch you really have to invest time to write tests. However, as the general approach it will produce more explicit results and indeed, user should rely and trust our internal logic. Because for our reasons we may change internal http code, but keep API consistent
Thanks for your help, I think I got enough feedbacks ! I'm closing the issue.
hello everyone ! In my project, I'd like to write unit tests of my class
ArtifactoryDriver
with hasArtifactoryPath
as an instance attribute like below:For my unit test I want to mock ArtifactoryPath with unittest so it uses local assets and I don't have to deploy an artifactory repository for test purposes. Is there an easy way to do that ?
Regards and thanks for your help !