Skip to content

Commit

Permalink
tests: add tests for entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-napoleone committed Dec 20, 2018
1 parent 211ea16 commit badac82
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/test_goutte.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from click.testing import CliRunner
import digitalocean
import pytest
import toml
Expand All @@ -11,6 +12,71 @@ def test_version():
assert __version__ == '1.0.0'


def test_entrypoint(caplog, monkeypatch):
def load_config(*args):
return {'retention': 2}
monkeypatch.setattr(main, '_load_config', load_config)
monkeypatch.setattr(main, '_process_droplets', mock.nothing)
monkeypatch.setattr(main, '_process_volumes', mock.nothing)
runner = CliRunner()
with runner.isolated_filesystem():
with caplog.at_level('INFO'):
with open('test.toml', 'w') as f:
f.write('Hello World!')
result = runner.invoke(main.entrypoint, [
'test.toml',
'token123',
])
assert result.exit_code == 0
assert len(caplog.records) == 1
assert caplog.records[0].levelname == 'INFO'


def test_entrypoint_debug(caplog, monkeypatch):
def load_config(*args):
return {'retention': 2}
monkeypatch.setattr(main, '_load_config', load_config)
monkeypatch.setattr(main, '_process_droplets', mock.nothing)
monkeypatch.setattr(main, '_process_volumes', mock.nothing)
monkeypatch.setattr(main.log, 'setLevel', mock.nothing)
runner = CliRunner()
with runner.isolated_filesystem():
with caplog.at_level('INFO'):
with open('test.toml', 'w') as f:
f.write('Hello World!')
result = runner.invoke(main.entrypoint, [
'test.toml',
'token123',
'--debug',
])
assert result.exit_code == 0
assert len(caplog.records) == 1
assert caplog.records[0].levelname == 'INFO'


def test_entrypoint_only(caplog, monkeypatch):
def load_config(*args):
return {'retention': 2}
monkeypatch.setattr(main, '_load_config', load_config)
monkeypatch.setattr(main, '_process_droplets', mock.nothing)
monkeypatch.setattr(main, '_process_volumes', mock.nothing)
monkeypatch.setattr(main.log, 'setLevel', mock.nothing)
runner = CliRunner()
with runner.isolated_filesystem():
with caplog.at_level('INFO'):
with open('test.toml', 'w') as f:
f.write('Hello World!')
result = runner.invoke(main.entrypoint, [
'test.toml',
'token123',
'--debug',
'--only', 'prune',
])
assert result.exit_code == 0
assert len(caplog.records) == 1
assert caplog.records[0].levelname == 'INFO'


def test_load_config(monkeypatch):
def load(file):
return {'retention': 2}
Expand Down

0 comments on commit badac82

Please sign in to comment.