Пример #1
0
def sync_open_project():
    """ """

    r = Response()
    args = arguments.from_request()
    definition = args.get('definition')
    source_directory = args.get('source_directory')

    if None in [definition, source_directory]:
        return r.fail(
            code='INVALID_ARGS',
            message='Invalid arguments. Unable to open project'
        ).response.flask_serialize()

    # Remove any shared library folders from the library list. These will be
    # stored using the single shared library folder instead
    definition['library_folders'] = [
        lf
        for lf in definition.get('library_folders', ['libs'])
        if lf and not lf.startswith('..')
    ]
    definition['library_folders'] += ['../__cauldron_shared_libs']

    container_folder = tempfile.mkdtemp(prefix='cd-remote-project-')
    os.makedirs(os.path.join(container_folder, '__cauldron_shared_libs'))
    os.makedirs(os.path.join(container_folder, '__cauldron_downloads'))

    project_folder = os.path.join(container_folder, definition['name'])
    os.makedirs(project_folder)

    definition_path = os.path.join(project_folder, 'cauldron.json')
    writer.write_json_file(definition_path, definition)

    sync_status.update({}, time=-1, project=None)

    open_response = project_opener.open_project(project_folder, forget=True)
    open_response.join()
    project = cd.project.get_internal_project()
    project.remote_source_directory = source_directory

    sync_status.update({}, time=-1, project=project)

    return r.consume(open_response).update(
        source_directory=project.source_directory,
        project=project.kernel_serialize()
    ).notify(
        kind='OPENED',
        code='PROJECT_OPENED',
        message='Project opened'
    ).response.flask_serialize()
Пример #2
0
def test_write_json_fail(attempt_json_write: MagicMock, sleep: MagicMock):
    """Should fail to write JSON data to file with retries"""
    attempt_json_write.return_value = IOError('FAKE')
    success, error = writer.write_json_file('fake', {}, retry_count=5)
    assert not success
    assert error is not None
    assert 5 == attempt_json_write.call_count
    assert 5 == sleep.call_count
Пример #3
0
def test_write_json(attempt_json_write: MagicMock, sleep: MagicMock):
    """Should successfully write JSON without retries"""
    attempt_json_write.return_value = None
    success, error = writer.write_json_file('fake', {})
    assert success
    assert error is None
    assert 1 == attempt_json_write.call_count
    assert 0 == sleep.call_count
Пример #4
0
def sync_open_project():
    """ """

    r = Response()
    args = arguments.from_request()
    definition = args.get('definition')
    source_directory = args.get('source_directory')

    if None in [definition, source_directory]:
        return r.fail(code='INVALID_ARGS',
                      message='Invalid arguments. Unable to open project'
                      ).response.flask_serialize()

    # Remove any shared library folders from the library list. These will be
    # stored using the single shared library folder instead
    definition['library_folders'] = [
        lf for lf in definition.get('library_folders', ['libs'])
        if lf and not lf.startswith('..')
    ]
    definition['library_folders'] += ['../__cauldron_shared_libs']

    container_folder = tempfile.mkdtemp(prefix='cd-remote-project-')
    os.makedirs(os.path.join(container_folder, '__cauldron_shared_libs'))
    os.makedirs(os.path.join(container_folder, '__cauldron_downloads'))

    project_folder = os.path.join(container_folder, definition['name'])
    os.makedirs(project_folder)

    definition_path = os.path.join(project_folder, 'cauldron.json')
    writer.write_json_file(definition_path, definition)

    sync_status.update({}, time=-1, project=None)

    open_response = project_opener.open_project(project_folder, forget=True)
    open_response.join()
    project = cd.project.get_internal_project()
    project.remote_source_directory = source_directory

    sync_status.update({}, time=-1, project=project)

    return r.consume(open_response).update(
        source_directory=project.source_directory,
        project=project.kernel_serialize()).notify(
            kind='SUCCESS', code='PROJECT_OPENED',
            message='Project opened').response.flask_serialize()
Пример #5
0
    def test_write_json(self, attempt_json_write: MagicMock, sleep: MagicMock):
        """Should successfully write JSON without retries"""

        attempt_json_write.return_value = None

        success, error = writer.write_json_file('fake', {})
        self.assertTrue(success)
        self.assertIsNone(error)
        self.assertEqual(1, attempt_json_write.call_count)
        self.assertEqual(0, sleep.call_count)
Пример #6
0
    def test_write_json_fail(self, attempt_json_write: MagicMock,
                             sleep: MagicMock):
        """Should fail to write JSON data to file with retries"""

        attempt_json_write.return_value = IOError('FAKE')

        success, error = writer.write_json_file('fake', {}, retry_count=5)
        self.assertFalse(success)
        self.assertIsNotNone(error)
        self.assertEqual(5, attempt_json_write.call_count)
        self.assertEqual(5, sleep.call_count)