test_repository_provider.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import responses
  2. from exam import fixture
  3. from sentry.models import Repository
  4. from sentry.testutils import TestCase
  5. from sentry_plugins.bitbucket.plugin 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. @fixture
  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. ]