def test_discovery_documents_preferred(clone_from_github_mock, glob_mock,
                                       open_mock):
    repo_mock = Mock()
    side_effect = common.clone_from_github_mock_side_effect(repo_mock)
    clone_from_github_mock.side_effect = side_effect
    glob_mock.glob.return_value = _DISCOVERY_FILENAMES
    open_mock.side_effect = [
        mock_open(read_data='{"id":"discovery:v1"}').return_value,
        mock_open(read_data='{"id":"admin:directory_v1"}').return_value,
        mock_open(read_data='{"id":"admin:datatransfer_v1"}').return_value,
        mock_open(read_data='{"id":"foo:v1"}').return_value,
        # Test that a Discovery document with the same ID as a previous one
        # isn't returned.
        mock_open(read_data='{"id":"foo:v1"}').return_value,
        mock_open(read_data='{"id":"baz:v1"}').return_value,
        mock_open(
            read_data=('{"items":['
                       '{"id":"discovery:v1","preferred":true},'
                       '{"id":"admin:directory_v1","preferred":false},'
                       '{"id":"admin:datatransfer_v1","preferred":false},'
                       '{"id":"foo:v1","preferred":true},'
                       '{"id":"baz:v1","preferred":false}]}')).return_value
    ]
    assert discovery_artifact_manager.discovery_documents(
        '/tmp', preferred=True) == {
            'discovery:v1': 'discoveries/discovery.v1.json',
            'admin:directory_v1': 'discoveries/admin.directory_v1.json',
            'admin:datatransfer_v1': 'discoveries/admin.datatransfer_v1.json',
            'foo:v1': 'discoveries/foo.v1.json'
        }
Ejemplo n.º 2
0
def php_update(filepath, github_account):
    """Wrapper over the PHP release function to standardize parameters."""
    ddocs = discovery_artifact_manager.discovery_documents(
        filepath,
        preferred=True,
        skip=['discovery:v1', 'websecurityscanner:v1'])
    google_api_php_client_services.update(filepath, github_account, ddocs)
def test_discovery_documents(clone_from_github_mock, glob_mock, open_mock):
    repo_mock = Mock()
    side_effect = common.clone_from_github_mock_side_effect(repo_mock)
    clone_from_github_mock.side_effect = side_effect
    glob_mock.glob.return_value = _DISCOVERY_FILENAMES
    open_mock.side_effect = [
        mock_open(read_data='{"id":"discovery:v1"}').return_value,
        mock_open(read_data='{"id":"admin:directory_v1"}').return_value,
        mock_open(read_data='{"id":"admin:datatransfer_v1"}').return_value,
        mock_open(read_data='{"id":"foo:v1"}').return_value,
        mock_open(read_data='{"id":"foo:v1"}').return_value,
        mock_open(read_data='{"id":"baz:v1"}').return_value
    ]
    assert discovery_artifact_manager.discovery_documents('/tmp') == {
        'discovery:v1': 'discoveries/discovery.v1.json',
        'admin:directory_v1': 'discoveries/admin.directory_v1.json',
        'admin:datatransfer_v1': 'discoveries/admin.datatransfer_v1.json',
        'foo:v1': 'discoveries/foo.v1.json',
        'baz:v1': 'discoveries/baz.v1.json'
    }