test_repository_provider.py 2.0 KB

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