Пример #1
0
    def test_get_last_remote_version_with_proxy_404(self, mock):
        from papaye.models import Package

        fake_response = FakeGRequestResponse(status_code=404, content=b'{"info": {"version": "1.0"}}')
        mock.return_value = fake_response

        # Test data
        package = Package('test')

        result = Package.get_last_remote_version(True, package.name)

        self.assertEqual(mock.call_count, 1)
        self.assertIsNone(result)
Пример #2
0
 def __call__(self):
     check_update = True if self.request.GET.get('check_update', 'true') == 'true' else False
     package = self.context.__parent__.__parent__
     last_remote_version = Package.get_last_remote_version(self.proxy, package.name)
     if check_update:
         if not package.repository_is_up_to_date(last_remote_version):
             return not_found(self.request)
     response = Response()
     response.content_disposition = 'attachment; filename="{}"'.format(self.context.filename)
     response.charset = 'utf-8'
     response.content_type = self.context.content_type
     response.body_file = self.context.content.open()
     return response
Пример #3
0
    def test_get_last_remote_version_without_proxy(self, mock):
        from papaye.models import Package

        fake_response = Response(status=200, body='{"info": {"version": "1.0"}}')
        mock.return_value = fake_response

        # Test data
        package = Package('test')

        result = Package.get_last_remote_version(False, package.name)

        self.assertEqual(mock.call_count, 0)
        self.assertIsNone(result)
Пример #4
0
    def test_get_last_remote_version_with_proxy_404(self, mock):
        from papaye.models import Package

        fake_response = FakeGRequestResponse(
            status_code=404, content=b'{"info": {"version": "1.0"}}')
        mock.return_value = fake_response

        # Test data
        package = Package('test')

        result = Package.get_last_remote_version(True, package.name)

        self.assertEqual(mock.call_count, 1)
        self.assertIsNone(result)
Пример #5
0
    def test_get_last_remote_version_without_proxy(self, mock):
        from papaye.models import Package

        fake_response = Response(status=200,
                                 body='{"info": {"version": "1.0"}}')
        mock.return_value = fake_response

        # Test data
        package = Package('test')

        result = Package.get_last_remote_version(False, package.name)

        self.assertEqual(mock.call_count, 0)
        self.assertIsNone(result)
Пример #6
0
 def __call__(self):
     package = self.context
     release_files = []
     for release in package.releases.values():
         for release_file in release.release_files.values():
             release_files.append(release_file)
     context = {
         'objects': ((self.request.resource_url(
             release_file,
             route_name='simple'
         )[:-1] + "#md5={}".format(release_file.md5_digest), release_file) for release_file in release_files),
     }
     if package.repository_is_up_to_date(Package.get_last_remote_version(self.proxy, package.name)):
         return context
     else:
         return not_found(self.request)
Пример #7
0
 def __call__(self):
     check_update = True if self.request.GET.get(
         'check_update', 'true') == 'true' else False
     package = self.context.__parent__.__parent__
     last_remote_version = Package.get_last_remote_version(
         self.proxy, package.name)
     if check_update:
         if not package.repository_is_up_to_date(last_remote_version):
             return not_found(self.request)
     response = Response()
     response.content_disposition = 'attachment; filename="{}"'.format(
         self.context.filename)
     response.charset = 'utf-8'
     response.content_type = self.context.content_type
     response.body_file = self.context.content.open()
     response.content_length = self.context.size
     return response
Пример #8
0
 def __call__(self):
     package = self.context
     release_files = []
     for release in package.releases.values():
         for release_file in release.release_files.values():
             release_file.__name__ = release_file.__name__.replace(' ', '-')
             release_files.append(release_file)
     context = {
         'objects':
         ((self.request.resource_url(release_file, route_name='simple')[:-1]
           + "#md5={}".format(release_file.md5_digest), release_file)
          for release_file in release_files),
     }
     if package.repository_is_up_to_date(
             Package.get_last_remote_version(self.proxy, package.name)):
         return context
     else:
         return not_found(self.request)