test_organization_release_files.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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={"organization_slug": project.organization.slug, "version": release.version},
  22. )
  23. self.login_as(user=self.user)
  24. def test_get(self):
  25. response = self.client.get(self.url)
  26. request = RequestFactory().get(self.url)
  27. self.validate_schema(request, response)
  28. def test_post(self):
  29. data = {
  30. "name": "http://example.com/application.js",
  31. "header": "X-SourceMap: http://example.com",
  32. "file": SimpleUploadedFile(
  33. "application.js", b"function() { }", content_type="application/javascript"
  34. ),
  35. }
  36. response = self.client.post(
  37. self.url,
  38. data,
  39. format="multipart",
  40. )
  41. request = RequestFactory().post(self.url, data=data, content_type="multipart/form-data")
  42. self.validate_schema(request, response)