Skip to content

Commit

Permalink
zalando-stups/lizzy#119 clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcs committed Jun 10, 2016
1 parent 1781b6c commit 7b2f43c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 26 deletions.
2 changes: 0 additions & 2 deletions lizzy_client/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ def convert(self, value, param, ctx):
if isinstance(value, str):
try:
url = value if '://' in value else 'file://{}'.format(quote(os.path.abspath(value)))
# if '://' not in value:
# url = 'file://{}'.format(quote(os.path.abspath(value)))

response = urlopen(url)
data = yaml.safe_load(response.read())
Expand Down
3 changes: 1 addition & 2 deletions lizzy_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ def delete(stack_ref: List[str],
all_with_version = all(stack.version is not None
for stack in stack_refs)

# TODO unit test this
# this is misleading but it's the current behaviour of senza
# this is misleading but it's the current behaviour of senza
# TODO Lizzy list (stack_refs) to see if it actually matches more than one stack
# to match senza behaviour
if (not all_with_version and not dry_run and not force):
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/test_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SenzaInfo:
- Something
File renamed without changes.
18 changes: 9 additions & 9 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import json
from pathlib import Path
from unittest.mock import MagicMock

import pytest
import os.path
import requests
import json
from click.testing import CliRunner
from unittest.mock import MagicMock
from lizzy_client.cli import fetch_token, main
from lizzy_client.lizzy import Lizzy
from lizzy_client.version import MAJOR_VERSION, MINOR_VERSION, VERSION
from tokens import InvalidCredentialsError
from urlpath import URL

from lizzy_client.cli import main, fetch_token
from lizzy_client.version import VERSION, MAJOR_VERSION, MINOR_VERSION
from lizzy_client.lizzy import Lizzy

test_dir = os.path.dirname(__file__)
config_path = os.path.join(test_dir, 'test_config.yaml')
fixtures_dir = Path(__file__).parent / 'fixtures'
config_path = str(fixtures_dir / 'test_config.yaml')

FAKE_ENV = {'OAUTH2_ACCESS_TOKEN_URL': 'oauth.example.com',
'LIZZY_URL': 'lizzy.example.com'}
Expand Down
2 changes: 0 additions & 2 deletions tests/test_config.yaml

This file was deleted.

16 changes: 5 additions & 11 deletions tests/test_lizzy.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import json
from unittest.mock import MagicMock
from requests import Response

import pytest
import json
import os
from lizzy_client.lizzy import Lizzy, make_header
from requests import Response

from lizzy_client.lizzy import make_header, Lizzy

STACK1 = """{"creation_time": 1460635167,
"description": "Lizzy Bus (ImageVersion: 257)",
Expand Down Expand Up @@ -55,7 +55,7 @@ def test_delete(monkeypatch, stack_id, region, dry_run):
lizzy.delete(stack_id, region=region, dry_run=dry_run)

header = make_header('7E5770K3N')
url = 'https://lizzy.example/api/stacks/'+stack_id
url = 'https://lizzy.example/api/stacks/{}'.format(stack_id)
expected_data = {"region": region, "dry_run": dry_run}
mock_delete.assert_called_once_with(url,
json=expected_data,
Expand Down Expand Up @@ -120,12 +120,6 @@ def test_traffic(monkeypatch):
def test_new_stack(monkeypatch,
version, parameters, region, disable_rollback, dry_run,
force, tags, keep_stacks, new_traffic):
test_dir = os.path.dirname(__file__)
yaml_path = os.path.join(test_dir,
'test_config.yaml') # we can use any file for this test
with open(yaml_path) as yaml_file:
senza_yaml = yaml_file.read()

mock_post = MagicMock()
mock_post.return_value = FakeResponse(200, STACK1)
monkeypatch.setattr('requests.post', mock_post)
Expand Down

0 comments on commit 7b2f43c

Please sign in to comment.