Skip to content

Commit

Permalink
Initial tests setup
Browse files Browse the repository at this point in the history
  • Loading branch information
wohlgejm committed Feb 21, 2016
1 parent 24d672e commit 6154143
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 11 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include *.txt
recursive-include accountable *.py
29 changes: 20 additions & 9 deletions accountable/accountable.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import absolute_import

import os

import yaml
import click

from services.jira import Jira
from accountable.jira import Jira


class Accountable(object):
Expand All @@ -18,25 +20,32 @@ def __init__(self, **kwargs):
self.username = self.config['username']
self.password = self.config['password']
self.domain = self.config['domain']
self.client = Jira(self.username, self.password, self.domain)
self.metadata = self.client.metadata()

def _metadata(self):
client = Jira(self.username, self.password, self.domain)
metadata = client.metadata()
return metadata

def _initial_setup(self):
username = str(self.kwargs.get('username'))
password = str(self.kwargs.get('password'))
domain = str(self.kwargs.get('domain'))
self._create_config(username, password, domain)
config_dict = self._config_dict(username, password, domain)
self._create_config(config_dict)

def _create_config_dir(self):
if not os.path.exists(self.CONFIG_DIR):
click.echo('Creating {}'.format(self.CONFIG_DIR))
os.makedirs(self.CONFIG_DIR)

def _create_config(self, username, password, domain):
self._create_config_dir()
def _config_dict(self, username, password, domain):
config = {'username': username, 'password': password, 'domain': domain}
return config

def _create_config(self, config_dict):
self._create_config_dir()
with open(self.CONFIG_FILE, 'w') as f:
f.write(yaml.dump(config, default_flow_style=False))
f.write(yaml.dump(config_dict, default_flow_style=False))
click.echo('Configuration file written to {}'.format(self.CONFIG_FILE))

def _load_config(self):
Expand All @@ -45,13 +54,15 @@ def _load_config(self):
return config

def projects(self):
metadata = self._metadata()
return [(project['key'],
project['name']) for project in self.metadata['projects']]
project['name']) for project in metadata['projects']]

def issue_types(self, project_key):
metadata = self._metadata()
if project_key:
project = next(
project for project in self.metadata['projects']
project for project in metadata['projects']
if project['key'] == str(project_key)
)
return {project_key: project['issuetypes']}
Expand Down
File renamed without changes.
Empty file removed accountable/services/__init__.py
Empty file.
33 changes: 31 additions & 2 deletions tests/test_accountable.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
import mock

from accountable.accountable import Accountable


def config_values():
return {
'username': 'testusername',
'password': 'testpassword',
'domain': 'testdomain',
'create_config': True,
}


class TestAccountable(object):
def test_initial_setup(self):
assert 5 == 5
@mock.patch.object(Accountable, '_initial_setup')
def test_initial_setup(self, mock_method):
Accountable(**config_values())
mock_method.assert_called_once_with()

@mock.patch.object(Accountable, '_load_config')
def test_load_config(self, mock_method):
Accountable(**config_values())
mock_method.assert_called_once_with()

@mock.patch.object(Accountable, '_initial_setup')
def test_does_not_setup_if_config_exists(self, mock_method):
Accountable(**config_values())
do_not_create_config = config_values().copy()
del do_not_create_config['create_config']
Accountable(**do_not_create_config)
mock_method.assert_called_once_with()
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ deps =
check-manifest
coveralls
pytest-cov
mock
commands =
check-manifest --ignore tox.ini,tests*
flake8 .
Expand Down

0 comments on commit 6154143

Please sign in to comment.