-
Notifications
You must be signed in to change notification settings - Fork 671
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
unit test for webhook #808
Comments
Hi @zhan9san , |
Hi @Spacetown Thanks for your attention. I agree with you that there is already a test framework, and it does work well. I appreciate that you guys have made this great project. But in the other hand, I find that it tests too many functions rather than one tiny bit of functionality. I'd like to know would it be possible to introduce tiny independent unit test. As we just wrap the original api, the unit test for the corresponding function would be simple, do you agree? Or do we really need unit test for this kind of feature? |
Hi @zhan9san, |
I think this should work.
responses = {
'{"active": True, "events": ["repo:refs_changed", "pr:merged", "pr:opened"], "webhook_url": "https://example.com", "name": fake_name}' : {
"id": 10,
"name": "fake_name",
"createdDate": 1513106011000,
"updatedDate": 1513106011000,
"events": [
"repo:refs_changed",
"pr:merged",
"pr:opened"
],
"configuration": {
"secret": "fake_secret"
},
"url": "https://example.com",
"active": True
}
}
from atlassian import Bitbucket
BITBUCKET = None
try:
from .mockup import mockup_server
BITBUCKET = Bitbucket(
"{}/bitbucket/server".format(mockup_server()), username="username", password="password"
)
except ImportError:
pass
def test_create_webhook(self):
rst = BIiTBUCKET.create_webhook(
"fake_project",
"fake_repo",
"fake_name",
["repo:refs_changed", "pr:merged", "pr:opened"],
"https://example.com",
True
)
self.assertEqual(rst["name"], self.fake_data["name"])
self.assertEqual(rst["events"], self.fake_data["events"])
self.assertEqual(rst["configuration"]["secret"], self.fake_data["secret"])
self.assertEqual(rst["url"], self.fake_data["webhook_url"])
self.assertEqual(rst["active"], self.fake_data["active"]) |
Hi @Spacetown Thanks for your advice. I re-considered this approach of test and found it is really amazing. I narrowly considered the test is unit test, but it's more like an integration test here. The rest tests will be added these days. Besides, this inspires me to add tests to Artifactory Project. |
@zhan9san That was the reason why I introduced this mookup. Ther where a couble of errors in refactroing the BB implementation. For implementing the OO interface I searched for a way to test all functions in the interface and implemnted this mookup. It's a little bit of work to implement the responses but than you can test a specific endpoint in detail. |
Hi @gonchik
I noticed you have #806 merged. Thank you.
As we just invoke the original rest api #806, the unit tests would be too simple.
Do we need to add this kind of code style of unit test for this feature?
If yes, I'd like to summit another PR.
If no, could you please show some better code style of unit test?
Here is the snippet. It seems stupid, but it does work.
The text was updated successfully, but these errors were encountered: