test_organization_release_files.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from django.core.files.uploadedfile import SimpleUploadedFile
  2. from django.test.client import RequestFactory
  3. from django.urls import reverse
  4. from fixtures.apidocs_test_case import APIDocsTestCase
  5. class ReleaseFilesListDocsTest(APIDocsTestCase):
  6. def setUp(self):
  7. project = self.create_project(name="foo")
  8. release = self.create_release(project=self.project, version="1")
  9. file1 = self.create_file(
  10. name="blah.js",
  11. size=42,
  12. type="release.file",
  13. headers={"Content-Type": "application/json"},
  14. checksum="dc1e3f3e411979d336c3057cce64294f3420f93a",
  15. )
  16. self.create_release_file(
  17. file=file1, release_id=release.id, name="http://example.com/blah.js"
  18. )
  19. self.url = reverse(
  20. "sentry-api-0-organization-release-files",
  21. kwargs={
  22. "organization_id_or_slug": project.organization.slug,
  23. "version": release.version,
  24. },
  25. )
  26. self.login_as(user=self.user)
  27. def test_get(self):
  28. response = self.client.get(self.url)
  29. request = RequestFactory().get(self.url)
  30. self.validate_schema(request, response)
  31. def test_post(self):
  32. data = {
  33. "name": "http://example.com/application.js",
  34. "header": "X-SourceMap: http://example.com",
  35. "file": SimpleUploadedFile(
  36. "application.js", b"function() { }", content_type="application/javascript"
  37. ),
  38. }
  39. response = self.client.post(
  40. self.url,
  41. data,
  42. format="multipart",
  43. )
  44. request = RequestFactory().post(self.url, data=data, content_type="multipart/form-data")
  45. self.validate_schema(request, response)