def test_metadata_from_file(self): mock_response = self.mock_post.return_value mock_response.ok = True mock_response.json.return_value = { 'successful': True, 'upload_id': 'some-valid-upload-id', } with self.get_temporary_file() as metadata_file: data = json.dumps({'name': 'from_file'}) metadata_file.write(data.encode('utf-8')) metadata_file.flush() upload( self.binary_file.name, 'foo', metadata_filename=metadata_file.name) data = { 'updown_id': 'some-valid-upload-id', 'source_uploaded': False, 'binary_filesize': self.binary_file_size, 'name': 'from_file', } self.mock_post.assert_called_with( get_upload_url('foo'), data=data, files=[])
def test_metadata_from_file(self): mock_response = self.mock_post.return_value mock_response.ok = True mock_response.json.return_value = { 'successful': True, 'upload_id': 'some-valid-upload-id', } with self.get_temporary_file() as metadata_file: data = json.dumps({'name': 'from_file'}) metadata_file.write(data.encode('utf-8')) metadata_file.flush() upload(self.binary_file.name, 'foo', metadata_filename=metadata_file.name) data = { 'updown_id': 'some-valid-upload-id', 'source_uploaded': False, 'binary_filesize': self.binary_file_size, 'name': 'from_file', } self.mock_post.assert_called_with(get_upload_url('foo'), data=data, files=[])
def test_upload_app_ok(self): # fake upload response mock_response = self.mock_post.return_value mock_response.ok = True mock_response.return_value = { 'success': True, 'status_url': 'http://example.com/status/', } # fake poll status response application_url = 'http://example.com/app/1' revision = '1' ok_response = Response() ok_response.status_code = 200 ok_response.encoding = 'utf-8' ok_response._content = json.dumps({ 'completed': True, 'revision': revision, 'application_url': application_url }).encode('utf-8') self.mock_get.return_value = ok_response success = upload(self.binary_file.name, 'foo') self.assertTrue(success) self.assertIn( call('Application uploaded successfully (as revision {})'.format( revision)), self.mock_logger.info.call_args_list) self.assertIn( call('Please check out the application at: %s\n', application_url), self.mock_logger.info.call_args_list)
def test_upload_app_ok(self): # fake upload response mock_response = self.mock_post.return_value mock_response.ok = True mock_response.return_value = { 'success': True, 'status_url': 'http://example.com/status/', } # fake poll status response application_url = 'http://example.com/app/1' revision = '1' ok_response = Response() ok_response.status_code = 200 ok_response.encoding = 'utf-8' ok_response._content = json.dumps( {'completed': True, 'revision': revision, 'application_url': application_url}).encode('utf-8') self.mock_get.return_value = ok_response success = upload(self.binary_file.name, 'foo') self.assertTrue(success) self.assertIn( call('Application uploaded successfully (as revision {})'.format( revision)), self.mock_logger.info.call_args_list) self.assertIn(call('Please check out the application at: %s\n', application_url), self.mock_logger.info.call_args_list)
def test_upload_app_ok_without_revision(self): # fake upload response mock_response = self.mock_post.return_value mock_response.ok = True mock_response.return_value = { 'success': True, 'status_url': 'http://example.com/status/', } # fake poll status response ok_response = Response() ok_response.status_code = 200 ok_response.encoding = 'utf-8' ok_response._content = json.dumps( {'completed': True}).encode('utf-8') self.mock_get.return_value = ok_response success = upload(self.binary_file.name) self.assertTrue(success) self.assertIn( call('Application uploaded successfully.'), self.mock_logger.info.call_args_list) self.assertNotIn( call('Uploaded as revision %s.', ANY), self.mock_logger.info.call_args_list)
def test_upload_files_failed(self): self.mock_post.side_effect = Exception('some error') success = upload(self.binary_file.name, 'foo') self.assertFalse(success) self.mock_logger.info.assert_called_once_with('Upload failed:\n\n%s\n', 'some error')
def test_upload_files_failed(self): self.mock_post.side_effect = Exception('some error') success = upload(self.binary_file.name, 'foo') self.assertFalse(success) self.mock_logger.info.assert_called_once_with( 'Upload failed:\n\n%s\n', 'some error')
def test_default_metadata(self): mock_response = self.mock_post.return_value mock_response.ok = True mock_response.json.return_value = { 'successful': True, 'upload_id': 'some-valid-upload-id', } upload(self.binary_file.name, 'foo') data = { 'updown_id': 'some-valid-upload-id', 'source_uploaded': False, 'binary_filesize': self.binary_file_size, } self.mock_post.assert_called_with( get_upload_url('foo'), data=data, files=[])
def test_invalid_package_name(self): self.suffix = '_0.1_all.img' self.binary_file = self.get_temporary_file(suffix=self.suffix) success = upload(self.binary_file.name) self.assertIsNone(success) self.mock_logger.info.assert_called_once_with( 'Invalid package filename.')
def test_default_metadata(self): mock_response = self.mock_post.return_value mock_response.ok = True mock_response.json.return_value = { 'successful': True, 'upload_id': 'some-valid-upload-id', } upload(self.binary_file.name) data = { 'updown_id': 'some-valid-upload-id', 'source_uploaded': False, 'binary_filesize': 0, } name = os.path.basename(self.binary_file.name).replace(self.suffix, '') self.mock_post.assert_called_with( get_upload_url(name), data=data, files=[])
def test_default_metadata(self): mock_response = self.mock_post.return_value mock_response.ok = True mock_response.json.return_value = { 'successful': True, 'upload_id': 'some-valid-upload-id', } upload(self.binary_file.name, 'foo') data = { 'updown_id': 'some-valid-upload-id', 'source_uploaded': False, 'binary_filesize': self.binary_file_size, } self.mock_post.assert_called_with(get_upload_url('foo'), data=data, files=[])
def test_upload_files_failed(self): self.mock_post.side_effect = Exception('some error') success = upload(self.binary_file.name) self.assertFalse(success) self.assertEqual(self.mock_logger.info.call_args_list, [ call('Uploading files...'), call('Upload failed:\n\n%s\n', 'some error'), ])
def test_upload_app_failed(self): # fake upload response mock_response = self.mock_post.return_value mock_response.ok = True mock_response.return_value = { 'success': True, 'status_url': 'http://example.com/status/', } # file uploaded ok, application submission failed self.mock_post.side_effect = [mock_response, Exception('some error')] success = upload(self.binary_file.name, 'foo') self.assertFalse(success) self.assertIn(call('Upload did not complete.'), self.mock_logger.info.call_args_list) self.assertIn(call('Some errors were detected:\n\n%s\n', 'some error'), self.mock_logger.info.call_args_list)
def test_upload_app_ok_without_revision(self): # fake upload response mock_response = self.mock_post.return_value mock_response.ok = True mock_response.return_value = { 'success': True, 'status_url': 'http://example.com/status/', } # fake poll status response ok_response = Response() ok_response.status_code = 200 ok_response.encoding = 'utf-8' ok_response._content = json.dumps({'completed': True}).encode('utf-8') self.mock_get.return_value = ok_response success = upload(self.binary_file.name, 'foo') self.assertTrue(success) self.assertNotIn(call('Uploaded as revision %s.', ANY), self.mock_logger.info.call_args_list)
def test_upload_app_failed(self): # fake upload response mock_response = self.mock_post.return_value mock_response.ok = True mock_response.return_value = { 'success': True, 'status_url': 'http://example.com/status/', } # file uploaded ok, application submission failed self.mock_post.side_effect = [mock_response, Exception('some error')] success = upload(self.binary_file.name, 'foo') self.assertFalse(success) self.assertIn( call('Upload did not complete.'), self.mock_logger.info.call_args_list) self.assertIn( call('Some errors were detected:\n\n%s\n', 'some error'), self.mock_logger.info.call_args_list)