@@ -0,0 +1,2369 @@
+# Copyright 2022 Planet Labs, PBC.%0A#%0A# Licensed under the Apache License, Version 2.0 (the %22License%22); you may not%0A# use this file except in compliance with the License. You may obtain a copy of%0A# the License at%0A#%0A#      http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the%0A# License for the specific language governing permissions and limitations under%0A# the License.%0Afrom unittest.mock import MagicMock%0A%0Afrom click.testing import CliRunner%0Aimport pytest%0A%0Aimport planet%0Afrom planet.cli import cli%0A%0A%0A@pytest.fixture%0Adef runner():%0A    return CliRunner()%0A%0A%0A@pytest.fixture(autouse=True)%0Adef patch_session(monkeypatch):%0A    '''Make sure we don't actually make any http calls'''%0A    monkeypatch.setattr(planet, 'Session', MagicMock(spec=planet.Session))%0A%0A%0Adef test_cli_auth_init_bad_pw(runner, monkeypatch):%0A    def apiexcept(*args, **kwargs):%0A        raise planet.exceptions.APIException('nope')%0A    monkeypatch.setattr(planet.Auth, 'from_login', apiexcept)%0A    result = runner.invoke(%0A            cli.main,%0A            args=%5B'auth', 'init'%5D,%0A            input='email%5Cnpw%5Cn')%0A    assert 'Error: nope' in result.output%0A%0A%0Adef test_cli_auth_init_success(runner, monkeypatch):%0A    mock_api_auth = MagicMock(spec=planet.auth.APIKeyAuth)%0A    mock_auth = MagicMock(spec=planet.Auth)%0A    mock_auth.from_login.return_value = mock_api_auth%0A    monkeypatch.setattr(planet, 'Auth', mock_auth)%0A%0A    result = runner.invoke(%0A            cli.main,%0A            args=%5B'auth', 'init'%5D,%0A            input='email%5Cnpw%5Cn')%0A    mock_auth.from_login.assert_called_once()%0A    mock_api_auth.write.assert_called_once()%0A    assert 'Initialized' in result.output%0A%0A%0Adef test_cli_auth_value_failure(runner, monkeypatch):%0A    def authexception(*args, **kwargs):%0A        raise planet.auth.AuthException%0A%0A    monkeypatch.setattr(planet.Auth, 'from_file', authexception)%0A%0A    result = runner.invoke(cli.main, %5B'auth', 'value'%5D)%0A    assert 'Error: Auth information does not exist or is corrupted.' %5C%0A        in result.output%0A%0A%0Adef test_cli_auth_value_success(runner):%0A    result = runner.invoke(cli.main, %5B'auth', 'value'%5D)%0A    assert not result.exception%0A    assert result.output == 'testkey%5Cn'%0A

include cli auth tests