test_project_release_files.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. from sentry.testutils.silo import region_silo_test
  6. @region_silo_test
  7. class ProjectReleaseFilesListDocsTest(APIDocsTestCase):
  8. def setUp(self):
  9. project = self.create_project(name="foo")
  10. file1 = self.create_file(
  11. name="blah.js",
  12. size=42,
  13. type="release.file",
  14. headers={"Content-Type": "application/json"},
  15. checksum="dc1e3f3e411979d336c3057cce64294f3420f93a",
  16. )
  17. release = self.create_release(project=project, version="1")
  18. self.create_release_file(
  19. file=file1, release_id=release.id, name="http://example.com/blah.js"
  20. )
  21. self.url = reverse(
  22. "sentry-api-0-project-release-files",
  23. kwargs={
  24. "project_slug": project.slug,
  25. "organization_slug": project.organization.slug,
  26. "version": release.version,
  27. },
  28. )
  29. self.login_as(user=self.user)
  30. def test_get(self):
  31. response = self.client.get(self.url)
  32. request = RequestFactory().get(self.url)
  33. self.validate_schema(request, response)
  34. def test_post(self):
  35. data = {
  36. "name": "http://example.com/application.js",
  37. "header": "X-SourceMap: http://example.com",
  38. "file": SimpleUploadedFile(
  39. "application.js", b"function() { }", content_type="application/javascript"
  40. ),
  41. }
  42. response = self.client.post(
  43. self.url,
  44. data,
  45. format="multipart",
  46. )
  47. request = RequestFactory().post(self.url, data=data, content_type="multipart/form-data")
  48. self.validate_schema(request, response)