def test_valid_shared(self): """Should synchronize file remotely to shared library location.""" support.create_project(self, 'peter-2') project = cauldron.project.get_internal_project() response = support.run_remote_command( 'open "{}" --forget'.format(project.source_directory) ) self.assert_no_errors(response) project = cauldron.project.get_internal_project() posted = self.post('/sync-file', { 'relative_path': 'library/test.md', 'chunk': sync.io.pack_chunk(b'abcdefg'), 'location': 'shared' }) self.assert_no_errors(posted.response) written_path = os.path.join( project.source_directory, '..', '__cauldron_shared_libs', 'library', 'test.md' ) self.assertTrue(os.path.exists(written_path)) support.run_remote_command('close')
def test_show_remote(self): """ should show remote url """ remote_connection = environ.RemoteConnection( url='http://my-fake.url', active=True ) support.run_remote_command( command='open @examples:hello_cauldron', remote_connection=remote_connection ) project = cauldron.project.internal_project url = project.make_remote_url(remote_connection.url) with patch('webbrowser.open') as func: r = support.run_remote_command( command='show', remote_connection=remote_connection ) self.assertFalse(r.failed, 'should not have failed') func.assert_called_once_with(url) support.run_command('close')
def test_sync_project_again(self): """ should synchronize files only when needed """ support.run_remote_command('open @examples:hello_cauldron') response = support.run_remote_command('sync') self.assertTrue(response.success) self.assertGreater(response.data['synchronized_count'], 0) response = support.run_remote_command('sync') self.assertEqual(response.data['synchronized_count'], 0)
def test_sync_project(self): """ should synchronize local files to remote location """ support.run_remote_command('open @examples:hello_cauldron') response = support.run_remote_command('sync') self.assertTrue(response.success) project = cauldron.project.get_internal_project() remote_files = sorted(os.listdir(project.remote_source_directory)) local_files = sorted(os.listdir(project.source_directory)) self.assertEqual(remote_files, local_files)
def test_sync_project(self): """ should synchronize local files to remote location """ support.run_remote_command('open @examples:hello_cauldron') response = support.run_remote_command('sync') self.assertTrue(response.success) project = cauldron.project.internal_project remote_files = sorted(os.listdir(project.remote_source_directory)) local_files = sorted(os.listdir(project.source_directory)) self.assertEqual(remote_files, local_files)
def test_remote_download_error(self, download_file: MagicMock): """ """ download_file.return_value = Response().fail().response support.create_project(self, 'apophis') project = cauldron.project.get_internal_project() support.run_remote_command('open "{}"'.format(project.source_directory)) response = support.run_remote_command('save') self.assertTrue(response.failed)
def test_remote(self, download_file: MagicMock): """ """ download_file.return_value = Response() support.create_project(self, 'apophis') project = cauldron.project.internal_project support.run_remote_command('open "{}"'.format(project.source_directory)) response = support.run_remote_command('save') self.assert_has_success_code(response, 'DOWNLOAD_SAVED')
def test_remote(self, download_file: MagicMock): """ """ download_file.return_value = Response() support.create_project(self, 'apophis') project = cauldron.project.get_internal_project() support.run_remote_command('open "{}"'.format(project.source_directory)) response = support.run_remote_command('save') self.assert_has_success_code(response, 'DOWNLOAD_SAVED')
def test_remote_download_error(self, download_file: MagicMock): """ """ download_file.return_value = Response().fail().response support.create_project(self, 'apophis') project = cauldron.project.internal_project support.run_remote_command('open "{}"'.format(project.source_directory)) response = support.run_remote_command('save') self.assertTrue(response.failed)
def test_valid(self): """ should successfully download file """ support.create_project(self, 'downloader') project = cauldron.project.get_internal_project() support.run_remote_command('open "{}"'.format(project.source_directory)) my_path = os.path.realpath(__file__) with patch('os.path.realpath', return_value=my_path) as func: downloaded = self.get('/download/fake.filename.not_real') self.assertGreater(func.call_count, 0) self.assertEqual(downloaded.flask.status_code, 200)
def test_remote(self): """Should function remotely""" support.create_project(self, 'nails') project = cauldron.project.get_internal_project() support.run_remote_command('open "{}" --forget'.format( project.source_directory)) project = cauldron.project.get_internal_project() added_response = support.run_remote_command('steps add') self.assertTrue(added_response.success, Message('Add Step Failed', response=added_response)) self.assertEqual(len(project.steps), 1)
def test_run_remote(self): """ should successfully run remote project """ support.create_project(self, 'rhino') support.add_step(self, contents='print("hello!")') source_directory = cauldron.project.internal_project.source_directory opened_response = support.run_remote_command( 'open "{}"'.format(source_directory)) self.assertTrue(opened_response.success) run_response = support.run_remote_command('run') self.assertTrue(run_response.success)
def test_valid(self): """ should successfully download file """ support.create_project(self, 'downloader') project = cauldron.project.get_internal_project() support.run_remote_command('open "{}"'.format( project.source_directory)) my_path = os.path.realpath(__file__) with patch('os.path.realpath', return_value=my_path) as func: downloaded = self.get('/download/fake.filename.not_real') self.assertGreater(func.call_count, 0) self.assertEqual(downloaded.flask.status_code, 200)
def test_status_remote(self): """ """ support.run_command('open @examples:seaborn') r = support.run_remote_command('status') self.assertFalse(r.failed, 'should not have failed') self.assertEqual(r.messages[0].code, 'STATUS_CREATED')
def test_refresh_remote(self): """ should refresh """ support.run_command('open @examples:hello_cauldron') r = support.run_remote_command('refresh') self.assertFalse(r.failed, 'should not have failed') self.assert_has_success_code(r, 'PROJECT_REFRESHED')
def test_reload_remote(self): """ should reload the currently opened project """ support.run_command('open @examples:hello_cauldron') r = support.run_remote_command('reload') self.assertFalse(r.failed, 'should not have failed') support.run_command('close')
def test_run_remote_sync_fail(self, sync_execute: MagicMock): """ should fail if the remote sync was not successful """ sync_execute.return_value = Response().fail().response support.create_project(self, 'pig') support.add_step(self, contents='print("hello!")') source_directory = cauldron.project.internal_project.source_directory opened_response = support.run_remote_command( 'open "{}"'.format(source_directory)) self.assertTrue(opened_response.success) run_response = support.run_remote_command('run') self.assertTrue(run_response.failed)
def test_run_remote(self): """ should successfully run remote project """ support.create_project(self, 'rhino') support.add_step(self, contents='print("hello!")') source_directory = ( cauldron.project.get_internal_project().source_directory ) opened_response = support.run_remote_command( 'open "{}"'.format(source_directory) ) self.assertTrue(opened_response.success) run_response = support.run_remote_command('run') self.assertTrue(run_response.success)
def test_remote(self): """Should function remotely""" support.create_project(self, 'nails') project = cauldron.project.get_internal_project() support.run_remote_command('open "{}" --forget'.format( project.source_directory )) project = cauldron.project.get_internal_project() added_response = support.run_remote_command('steps add') self.assertTrue(added_response.success, Message( 'Add Step Failed', response=added_response )) self.assertEqual(len(project.steps), 1)
def test_failed_status(self): """ should fail if unable to get remote sync status """ def mock_send_request(*args, **kwargs): return Response().fail(code='FAKE-ERROR').response response = support.run_remote_command( command='sync', mock_send_request=mock_send_request) self.assertTrue(response.failed) self.assert_has_error_code(response, 'FAKE-ERROR')
def test_run_remote_sync_fail(self, sync_execute: MagicMock): """ should fail if the remote sync was not successful """ sync_execute.return_value = Response().fail().response support.create_project(self, 'pig') support.add_step(self, contents='print("hello!")') source_directory = ( cauldron.project.get_internal_project().source_directory ) opened_response = support.run_remote_command( 'open "{}"'.format(source_directory) ) self.assertTrue(opened_response.success) run_response = support.run_remote_command('run') self.assertTrue(run_response.failed)
def test_no_such_project(self): """ should fail if unable to get remote sync status """ def mock_send_request(*args, **kwargs): return Response().update( remote_source_directory=directory).response directory = os.path.dirname(os.path.realpath(__file__)) response = support.run_remote_command( command='sync', mock_send_request=mock_send_request) self.assert_has_error_code(response, 'NO_PROJECT')
def test_valid(self): """ should synchronize file remotely """ support.create_project(self, 'peter') project = cauldron.project.get_internal_project() response = support.run_remote_command('open "{}"'.format( project.source_directory)) self.assert_no_errors(response) project = cauldron.project.get_internal_project() posted = self.post('/sync-file', { 'relative_path': 'test.md', 'chunk': sync.io.pack_chunk(b'abcdefg') }) self.assert_no_errors(posted.response) written_path = os.path.join(project.source_directory, 'test.md') self.assertTrue(os.path.exists(written_path)) support.run_remote_command('close')
def test_failed_status(self): """ should fail if unable to get remote sync status """ def mock_send_request(*args, **kwargs): return Response().fail(code='FAKE-ERROR').response response = support.run_remote_command( command='sync', mock_send_request=mock_send_request ) self.assertTrue(response.failed) self.assert_has_error_code(response, 'FAKE-ERROR')
def test_valid(self): """ should synchronize file remotely """ support.create_project(self, 'peter') project = cauldron.project.get_internal_project() response = support.run_remote_command( 'open "{}"'.format(project.source_directory) ) self.assert_no_errors(response) project = cauldron.project.get_internal_project() posted = self.post('/sync-file', { 'relative_path': 'test.md', 'chunk': sync.io.pack_chunk(b'abcdefg') }) self.assert_no_errors(posted.response) written_path = os.path.join(project.source_directory, 'test.md') self.assertTrue(os.path.exists(written_path)) support.run_remote_command('close')
def test_no_such_project(self): """ should fail if unable to get remote sync status """ def mock_send_request(*args, **kwargs): return Response().update( remote_source_directory=directory ).response directory = os.path.dirname(os.path.realpath(__file__)) response = support.run_remote_command( command='sync', mock_send_request=mock_send_request ) self.assert_has_error_code(response, 'NO_PROJECT')
def test_purge_remote(self): """ should purge current results directory """ r = support.run_remote_command('purge --force') self.assertFalse(r.failed, 'should not have failed')
def test_remote(self): """Should not close remotely when no project is open""" response = support.run_remote_command('close') self.assert_has_success_code(response, 'NO_OPEN_PROJECT')
def test_remote_save_no_project(self): """ """ response = support.run_remote_command('save') self.assertTrue(response.failed)
def test_version_remote(self): """ should retrieve version info """ r = support.run_remote_command('version') self.assertFalse(r.failed, 'should not have failed')
def test_remote(self): """ """ response = support.run_remote_command('close') self.assert_has_success_code(response, 'NO_OPEN_PROJECT')
def test_reload_remote(self): """ should reload the currently opened project """ support.run_command('open @examples:hello_cauldron') r = support.run_remote_command('reload') self.assertFalse(r.failed, 'should not have failed')
def test_remote(self): """ should error when no remote project is open """ response = support.run_remote_command('clear') self.assert_has_error_code(response, 'NO_OPEN_PROJECT')