test_repository_provider.py 2.0 KB

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