test_repository_provider.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from __future__ import absolute_import
  2. import responses
  3. from exam import fixture
  4. from sentry.models import Repository
  5. from sentry.testutils import PluginTestCase
  6. from social_auth.models import UserSocialAuth
  7. from sentry_plugins.bitbucket.plugin import BitbucketRepositoryProvider
  8. from sentry_plugins.bitbucket.testutils import COMPARE_COMMITS_EXAMPLE, COMMIT_DIFF_PATCH
  9. class BitbucketPluginTest(PluginTestCase):
  10. @fixture
  11. def provider(self):
  12. return BitbucketRepositoryProvider("bitbucket")
  13. @responses.activate
  14. def test_compare_commits(self):
  15. responses.add(
  16. responses.GET,
  17. "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/commits/e18e4e72de0d824edfbe0d73efe34cbd0d01d301",
  18. body=COMPARE_COMMITS_EXAMPLE,
  19. )
  20. responses.add(
  21. responses.GET,
  22. "https://api.bitbucket.org/2.0/repositories/maxbittker/newsdiffs/diff/e18e4e72de0d824edfbe0d73efe34cbd0d01d301",
  23. body=COMMIT_DIFF_PATCH,
  24. )
  25. repo = Repository.objects.create(
  26. provider="bitbucket",
  27. name="maxbittker/newsdiffs",
  28. organization_id=1,
  29. config={"name": "maxbittker/newsdiffs"},
  30. )
  31. user = self.user
  32. UserSocialAuth.objects.create(
  33. provider="bitbucket",
  34. user=user,
  35. uid="1",
  36. extra_data={
  37. "access_token": "oauth_token=oauth-token&oauth_token_secret=oauth-token-secret"
  38. },
  39. )
  40. res = self.provider.compare_commits(
  41. repo, None, "e18e4e72de0d824edfbe0d73efe34cbd0d01d301", actor=user
  42. )
  43. assert res == [
  44. {
  45. "author_email": "max@getsentry.com",
  46. "author_name": "Max Bittker",
  47. "message": "README.md edited online with Bitbucket",
  48. "id": "e18e4e72de0d824edfbe0d73efe34cbd0d01d301",
  49. "repository": "maxbittker/newsdiffs",
  50. "patch_set": [{"path": u"README.md", "type": "M"}],
  51. }
  52. ]