test_project_release_files.py 1.8 KB

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