예제 #1
0
 def test_upload_app_uses_environment_variables(self):
     with patch.dict(os.environ,
                     UBUNTU_STORE_API_ROOT_URL='http://example.com'):
         upload_url = ("http://example.com/click-package-upload/%s/" %
                       self.package_name)
         data = {
             'updown_id': self.data['upload_id'],
             'binary_filesize': self.data['binary_filesize'],
             'source_uploaded': self.data['source_uploaded'],
         }
         upload_app(self.package_name, self.data)
         self.mock_post.assert_called_once_with(
             upload_url, data=data, files=[])
예제 #2
0
 def test_upload_app_with_metadata(self):
     upload_app(self.package_name, self.data, metadata={
         'changelog': 'some changes', 'tagline': 'a tagline'})
     self.mock_post.assert_called_once_with(
         ANY,
         data={
             'updown_id': self.data['upload_id'],
             'binary_filesize': self.data['binary_filesize'],
             'source_uploaded': self.data['source_uploaded'],
             'changelog': 'some changes',
             'tagline': 'a tagline',
         },
         files=[],
     )
 def test_upload_app_uses_environment_variables(self):
     with patch.dict(os.environ,
                     UBUNTU_STORE_API_ROOT_URL='http://example.com'):
         upload_url = ("http://example.com/click-package-upload/%s/" %
                       self.package_name)
         data = {
             'updown_id': self.data['upload_id'],
             'binary_filesize': self.data['binary_filesize'],
             'source_uploaded': self.data['source_uploaded'],
         }
         upload_app(self.package_name, self.data)
         self.mock_post.assert_called_once_with(upload_url,
                                                data=data,
                                                files=[])
예제 #4
0
    def test_upload_app_ignore_non_ok_responses(self):
        mock_response = self.mock_post.return_value
        mock_response.ok = True
        mock_response.return_value = {
            'success': True,
            'status_url': 'http://example.com/status/',
        }

        ok_response = Response()
        ok_response.status_code = 200
        ok_response.encoding = 'utf-8'
        ok_response._content = json.dumps(
            {'completed': True, 'revision': 14}).encode('utf-8')
        nok_response = Response()
        nok_response.status_code = 503

        self.mock_get.side_effect = [nok_response, nok_response, ok_response]
        response = upload_app(self.package_name, self.data)
        self.assertEqual(response, {
            'success': True,
            'errors': [],
            'application_url': '',
            'revision': 14,
        })
        self.assertEqual(self.mock_get.call_count, 3)
예제 #5
0
    def test_upload_app_poll_status(self):
        mock_response = self.mock_post.return_value
        mock_response.ok = True
        mock_response.return_value = {
            'success': True,
            'status_url': 'http://example.com/status/'
        }

        response_not_completed = Response()
        response_not_completed.status_code = 200
        response_not_completed.encoding = 'utf-8'
        response_not_completed._content = json.dumps(
            {'completed': False, 'application_url': ''}).encode('utf-8')
        response_completed = Response()
        response_completed.status_code = 200
        response_completed.encoding = 'utf-8'
        response_completed._content = json.dumps(
            {'completed': True, 'revision': 14,
             'application_url': 'http://example.org'}).encode('utf-8')
        self.mock_get.side_effect = [
            response_not_completed,
            response_not_completed,
            response_completed,
        ]
        response = upload_app(self.package_name, self.data)
        self.assertEqual(response, {
            'success': True,
            'errors': [],
            'application_url': 'http://example.org',
            'revision': 14,
        })
        self.assertEqual(self.mock_get.call_count, 3)
    def test_upload_app_ignore_non_ok_responses(self):
        mock_response = self.mock_post.return_value
        mock_response.ok = True
        mock_response.return_value = {
            'success': True,
            'status_url': 'http://example.com/status/',
        }

        ok_response = Response()
        ok_response.status_code = 200
        ok_response.encoding = 'utf-8'
        ok_response._content = json.dumps({
            'completed': True,
            'revision': 14
        }).encode('utf-8')
        nok_response = Response()
        nok_response.status_code = 503

        self.mock_get.side_effect = [nok_response, nok_response, ok_response]
        response = upload_app(self.package_name, self.data)
        self.assertEqual(response, {
            'success': True,
            'errors': [],
            'application_url': '',
            'revision': 14,
        })
        self.assertEqual(self.mock_get.call_count, 3)
    def test_upload_app_abort_polling(self):
        mock_response = self.mock_post.return_value
        mock_response.ok = True
        mock_response.json.return_value = {
            'success': True,
            'status_url': 'http://example.com/status/',
            'web_status_url': 'http://example.com/status-web/',
        }

        mock_status_response = self.mock_get.return_value
        mock_status_response.ok = True
        mock_status_response.json.return_value = {'completed': False}
        response = upload_app(self.package_name, self.data)
        self.assertEqual(
            response, {
                'success':
                False,
                'errors': [
                    'Package scan took too long.',
                    'Please check the status later at: '
                    'http://example.com/status-web/.',
                ],
                'application_url':
                '',
                'revision':
                None,
            })
예제 #8
0
    def test_upload_app_abort_polling(self):
        mock_response = self.mock_post.return_value
        mock_response.ok = True
        mock_response.json.return_value = {
            'success': True,
            'status_url': 'http://example.com/status/',
            'web_status_url': 'http://example.com/status-web/',
        }

        mock_status_response = self.mock_get.return_value
        mock_status_response.ok = True
        mock_status_response.json.return_value = {
            'completed': False
        }
        response = upload_app(self.package_name, self.data)
        self.assertEqual(response, {
            'success': False,
            'errors': [
                'Package scan took too long.',
                'Please check the status later at: '
                'http://example.com/status-web/.',
            ],
            'application_url': '',
            'revision': None,
        })
 def test_upload_app_with_metadata(self):
     upload_app(self.package_name,
                self.data,
                metadata={
                    'changelog': 'some changes',
                    'tagline': 'a tagline'
                })
     self.mock_post.assert_called_once_with(
         ANY,
         data={
             'updown_id': self.data['upload_id'],
             'binary_filesize': self.data['binary_filesize'],
             'source_uploaded': self.data['source_uploaded'],
             'changelog': 'some changes',
             'tagline': 'a tagline',
         },
         files=[],
     )
예제 #10
0
 def test_upload_app_with_invalid_oauth_session(self):
     self.mock_get_oauth_session.return_value = None
     response = upload_app(self.package_name, self.data)
     self.assertEqual(response, {
         'success': False,
         'errors': ['No valid credentials found.'],
         'application_url': '',
         'revision': None,
     })
    def test_upload_app_with_icon(self, mock_open):
        with tempfile.NamedTemporaryFile() as icon:
            mock_open.return_value = icon

            upload_app(self.package_name,
                       self.data,
                       metadata={
                           'icon_256': icon.name,
                       })
            self.mock_post.assert_called_once_with(
                ANY,
                data={
                    'updown_id': self.data['upload_id'],
                    'binary_filesize': self.data['binary_filesize'],
                    'source_uploaded': self.data['source_uploaded'],
                },
                files=[
                    ('icon_256', icon),
                ],
            )
예제 #12
0
    def test_upload_app_with_icon(self, mock_open):
        with tempfile.NamedTemporaryFile() as icon:
            mock_open.return_value = icon

            upload_app(
                self.package_name, self.data,
                metadata={
                    'icon_256': icon.name,
                }
            )
            self.mock_post.assert_called_once_with(
                ANY,
                data={
                    'updown_id': self.data['upload_id'],
                    'binary_filesize': self.data['binary_filesize'],
                    'source_uploaded': self.data['source_uploaded'],
                },
                files=[
                    ('icon_256', icon),
                ],
            )
 def test_upload_app_ignore_special_attributes_in_metadata(self):
     upload_app(self.package_name,
                self.data,
                metadata={
                    'changelog': 'some changes',
                    'tagline': 'a tagline',
                    'upload_id': 'my-own-id',
                    'binary_filesize': 0,
                    'source_uploaded': False,
                })
     self.mock_post.assert_called_once_with(
         ANY,
         data={
             'updown_id': self.data['upload_id'],
             'binary_filesize': self.data['binary_filesize'],
             'source_uploaded': self.data['source_uploaded'],
             'changelog': 'some changes',
             'tagline': 'a tagline',
         },
         files=[],
     )
예제 #14
0
 def test_upload_app_ignore_special_attributes_in_metadata(self):
     upload_app(
         self.package_name,
         self.data, metadata={
             'changelog': 'some changes',
             'tagline': 'a tagline',
             'upload_id': 'my-own-id',
             'binary_filesize': 0,
             'source_uploaded': False,
         })
     self.mock_post.assert_called_once_with(
         ANY,
         data={
             'updown_id': self.data['upload_id'],
             'binary_filesize': self.data['binary_filesize'],
             'source_uploaded': self.data['source_uploaded'],
             'changelog': 'some changes',
             'tagline': 'a tagline',
         },
         files=[],
     )
예제 #15
0
    def test_upload_app_error_response(self):
        mock_response = self.mock_post.return_value
        mock_response.ok = False
        mock_response.reason = '500 INTERNAL SERVER ERROR'
        mock_response.text = 'server failure'

        response = upload_app(self.package_name, self.data)
        self.assertEqual(response, {
            'success': False,
            'errors': ['server failure'],
            'application_url': '',
            'revision': None,
        })
예제 #16
0
    def test_upload_app_handle_malformed_response(self):
        mock_response = self.mock_post.return_value
        mock_response.ok = True
        mock_response.json.return_value = {}

        response = upload_app(self.package_name, self.data)
        err = KeyError('status_url')
        self.assertEqual(response, {
            'success': False,
            'errors': [str(err)],
            'application_url': '',
            'revision': None,
        })
    def test_upload_app_with_screenshots(self, mock_open):
        screenshot1 = tempfile.NamedTemporaryFile()
        screenshot2 = tempfile.NamedTemporaryFile()
        mock_open.side_effect = [screenshot1, screenshot2]

        upload_app(self.package_name,
                   self.data,
                   metadata={
                       'screenshots': [screenshot1.name, screenshot2.name],
                   })
        self.mock_post.assert_called_once_with(
            ANY,
            data={
                'updown_id': self.data['upload_id'],
                'binary_filesize': self.data['binary_filesize'],
                'source_uploaded': self.data['source_uploaded'],
            },
            files=[
                ('screenshots', screenshot1),
                ('screenshots', screenshot2),
            ],
        )
    def test_upload_app_error_response(self):
        mock_response = self.mock_post.return_value
        mock_response.ok = False
        mock_response.reason = '500 INTERNAL SERVER ERROR'
        mock_response.text = 'server failure'

        response = upload_app(self.package_name, self.data)
        self.assertEqual(
            response, {
                'success': False,
                'errors': ['server failure'],
                'application_url': '',
                'revision': None,
            })
예제 #19
0
    def test_upload_app_with_screenshots(self, mock_open):
        screenshot1 = tempfile.NamedTemporaryFile()
        screenshot2 = tempfile.NamedTemporaryFile()
        mock_open.side_effect = [screenshot1, screenshot2]

        upload_app(
            self.package_name, self.data,
            metadata={
                'screenshots': [screenshot1.name, screenshot2.name],
            }
        )
        self.mock_post.assert_called_once_with(
            ANY,
            data={
                'updown_id': self.data['upload_id'],
                'binary_filesize': self.data['binary_filesize'],
                'source_uploaded': self.data['source_uploaded'],
            },
            files=[
                ('screenshots', screenshot1),
                ('screenshots', screenshot2),
            ],
        )
예제 #20
0
    def upload(self, snap_filename):
        if not os.path.exists(snap_filename):
            raise FileNotFoundError(snap_filename)
        snap_name = _get_name_from_snap_file(snap_filename)

        if self.conf.get('unbound_discharge') is None:
            raise errors.InvalidCredentialsError()
        data = _upload.upload_files(snap_filename, self.updown)
        success = data.get('success', False)
        if not success:
            return data

        result = _upload.upload_app(self.sca, snap_name, data)
        return result
    def test_upload_app_handle_malformed_response(self):
        mock_response = self.mock_post.return_value
        mock_response.ok = True
        mock_response.json.return_value = {}

        response = upload_app(self.package_name, self.data)
        err = KeyError('status_url')
        self.assertEqual(
            response, {
                'success': False,
                'errors': [str(err)],
                'application_url': '',
                'revision': None,
            })
예제 #22
0
    def upload(self, snap_filename):
        if not os.path.exists(snap_filename):
            raise FileNotFoundError(snap_filename)
        snap_name = _get_name_from_snap_file(snap_filename)

        if self.conf.get('unbound_discharge') is None:
            raise errors.InvalidCredentialsError()
        data = _upload.upload_files(snap_filename, self.updown)
        success = data.get('success', False)
        if not success:
            return data

        result = _upload.upload_app(self.sca, snap_name, data)
        return result
 def test_upload_app_with_invalid_oauth_session(self):
     self.mock_get_oauth_session.return_value = None
     response = upload_app(self.package_name, self.data)
     self.assertEqual(
         response, {
             'success':
             False,
             'errors': [
                 'No valid credentials found. Have you run "snapcraft login"?'
             ],
             'application_url':
             '',
             'revision':
             None,
         })
예제 #24
0
    def upload(self, snap_filename):
        snap_name = _get_name_from_snap_file(snap_filename)

        # FIXME This should be raised by the function that uses the
        # discharge. --elopio -2016-06-20
        if self.conf.get('unbound_discharge') is None:
            raise errors.InvalidCredentialsError(
                'Unbound discharge not in the config file')

        data = _upload.upload_files(snap_filename, self.updown)
        success = data.get('success', False)
        if not success:
            return data

        result = _upload.upload_app(self.sca, snap_name, data)
        return result
    def test_upload_app_poll_status(self):
        mock_response = self.mock_post.return_value
        mock_response.ok = True
        mock_response.return_value = {
            'success': True,
            'status_url': 'http://example.com/status/'
        }

        response_not_completed = Response()
        response_not_completed.status_code = 200
        response_not_completed.encoding = 'utf-8'
        response_not_completed._content = json.dumps({
            'completed': False,
            'application_url': ''
        }).encode('utf-8')
        response_completed = Response()
        response_completed.status_code = 200
        response_completed.encoding = 'utf-8'
        response_completed._content = json.dumps({
            'completed':
            True,
            'revision':
            14,
            'application_url':
            'http://example.org'
        }).encode('utf-8')
        self.mock_get.side_effect = [
            response_not_completed,
            response_not_completed,
            response_completed,
        ]
        response = upload_app(self.package_name, self.data)
        self.assertEqual(
            response, {
                'success': True,
                'errors': [],
                'application_url': 'http://example.org',
                'revision': 14,
            })
        self.assertEqual(self.mock_get.call_count, 3)
예제 #26
0
    def test_upload_app(self):
        mock_response = self.mock_post.return_value
        mock_response.ok = True
        mock_response.json.return_value = {
            'success': True,
            'status_url': 'http://example.com/status/'
        }

        mock_status_response = self.mock_get.return_value
        mock_status_response.ok = True
        mock_status_response.json.return_value = {
            'completed': True,
            'revision': 15,
        }

        response = upload_app(self.package_name, self.data)
        self.assertEqual(response, {
            'success': True,
            'errors': [],
            'application_url': '',
            'revision': 15,
        })
    def test_upload_app(self):
        mock_response = self.mock_post.return_value
        mock_response.ok = True
        mock_response.json.return_value = {
            'success': True,
            'status_url': 'http://example.com/status/'
        }

        mock_status_response = self.mock_get.return_value
        mock_status_response.ok = True
        mock_status_response.json.return_value = {
            'completed': True,
            'revision': 15,
        }

        response = upload_app(self.package_name, self.data)
        self.assertEqual(response, {
            'success': True,
            'errors': [],
            'application_url': '',
            'revision': 15,
        })
예제 #28
0
    def test_upload_app_with_errors_during_scan(self):
        mock_response = self.mock_post.return_value
        mock_response.ok = True
        mock_response.json.return_value = {
            'success': True,
            'status_url': 'http://example.com/status/'
        }

        mock_status_response = self.mock_get.return_value
        mock_status_response.ok = True
        mock_status_response.json.return_value = {
            'completed': True,
            'message': 'some error',
            'application_url': 'http://example.com/myapp',
        }

        response = upload_app(self.package_name, self.data)
        self.assertEqual(response, {
            'success': False,
            'errors': ['some error'],
            'application_url': 'http://example.com/myapp',
            'revision': None,
        })
    def test_upload_app_with_errors_during_scan(self):
        mock_response = self.mock_post.return_value
        mock_response.ok = True
        mock_response.json.return_value = {
            'success': True,
            'status_url': 'http://example.com/status/'
        }

        mock_status_response = self.mock_get.return_value
        mock_status_response.ok = True
        mock_status_response.json.return_value = {
            'completed': True,
            'message': 'some error',
            'application_url': 'http://example.com/myapp',
        }

        response = upload_app(self.package_name, self.data)
        self.assertEqual(
            response, {
                'success': False,
                'errors': ['some error'],
                'application_url': 'http://example.com/myapp',
                'revision': None,
            })