old_contents: from onadata.apps.api.tests.viewsets.test_abstract_viewset import \
      TestAbstractViewSet
  from onadata.apps.api.viewsets.attachment_viewset import AttachmentViewSet
  
  
  class TestAttachmentViewSet(TestAbstractViewSet):
      def setUp(self):
          super(TestAttachmentViewSet, self).setUp()
          self.retrieve_view = AttachmentViewSet.as_view({
              'get': 'retrieve'
          })
          self.list_view = AttachmentViewSet.as_view({
              'get': 'list'
          })
  
          self._publish_xls_form_to_project()
          self._submit_transport_instance_w_attachment()
  
      def test_retrieve_view(self):
          pk = self.attachment.pk
          data = {
              'url': 'http://testserver/api/v1/media/%s' % pk,
              "id": pk,
              'xform': self.xform.pk,
              'data_id': self.attachment.instance.pk,
              "mimetype": self.attachment.mimetype,
              "filename": self.attachment.media_file.name
          }
          request = self.factory.get('/', **self.extra)
          response = self.retrieve_view(request, pk=pk)
          self.assertEqual(response.status_code, 200)
          self.assertTrue(isinstance(response.data, dict))
          self.assertEqual(response.data, data)
  
          # file download
          filename = data['filename']
          ext = filename[filename.rindex('.') + 1:]
          request = self.factory.get('/', **self.extra)
          response = self.retrieve_view(request, pk=pk, format=ext)
          self.assertEqual(response.status_code, 200)
          self.assertEqual(response.content_type, 'image/jpeg')
  
      def test_list_view(self):
          request = self.factory.get('/', **self.extra)
          response = self.list_view(request)
          self.assertEqual(response.status_code, 200)
          self.assertTrue(isinstance(response.data, list))
  
new_contents: from onadata.apps.api.tests.viewsets.test_abstract_viewset import \
      TestAbstractViewSet
  from onadata.apps.api.viewsets.attachment_viewset import AttachmentViewSet
  
  
  class TestAttachmentViewSet(TestAbstractViewSet):
      def setUp(self):
          super(TestAttachmentViewSet, self).setUp()
          self.retrieve_view = AttachmentViewSet.as_view({
              'get': 'retrieve'
          })
          self.list_view = AttachmentViewSet.as_view({
              'get': 'list'
          })
  
          self._publish_xls_form_to_project()
          self._submit_transport_instance_w_attachment()
  
      def test_retrieve_view(self):
          pk = self.attachment.pk
          data = {
              'url': 'http://testserver/api/v1/media/%s' % pk,
              'download_url': 'http://testserver/api/v1/media/%s.jpg' % pk,
              "id": pk,
              'xform': self.xform.pk,
              'data_id': self.attachment.instance.pk,
              "mimetype": self.attachment.mimetype,
              "filename": self.attachment.media_file.name
          }
          request = self.factory.get('/', **self.extra)
          response = self.retrieve_view(request, pk=pk)
          self.assertEqual(response.status_code, 200)
          self.assertTrue(isinstance(response.data, dict))
          self.assertEqual(response.data, data)
  
          # file download
          filename = data['filename']
          ext = filename[filename.rindex('.') + 1:]
          request = self.factory.get('/', **self.extra)
          response = self.retrieve_view(request, pk=pk, format=ext)
          self.assertEqual(response.status_code, 200)
          self.assertEqual(response.content_type, 'image/jpeg')
  
      def test_list_view(self):
          request = self.factory.get('/', **self.extra)
          response = self.list_view(request)
          self.assertEqual(response.status_code, 200)
          self.assertTrue(isinstance(response.data, list))
  
subject: test for download_url