Skip to content

Commit

Permalink
Merge branch 'hotfix/py.test'
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardomurri committed Jan 14, 2016
2 parents 680d47a + a22d9ae commit 5543e1b
Show file tree
Hide file tree
Showing 13 changed files with 275 additions and 223 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ python:
- "2.6"
- "2.7"
install:
- "pip install nose mock"
- "pip install pytest mock"
- "pip install ."
script: nosetests
script: py.test
sudo: false
3 changes: 1 addition & 2 deletions elasticluster/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env python
#
# Copyright (C) 2013 S3IT, University of Zurich
# Copyright (C) 2013, 2016 S3IT, University of Zurich
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -20,7 +20,6 @@

import logging

logging.basicConfig()
log = logging.getLogger("gc3.elasticluster")
log.DO_NOT_FORK = False

Expand Down
6 changes: 4 additions & 2 deletions elasticluster/main.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env python
#
# Copyright (C) 2013-2014 S3IT, University of Zurich
# Copyright (C) 2013-2014, 2016 S3IT, University of Zurich
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -32,6 +32,8 @@
# Voluptuous version <= 0.7.2
from voluptuous.voluptuous import MultipleInvalid, Invalid

import coloredlogs

# Elasticluster imports
from elasticluster import log
from elasticluster.subcommands import Start, SetupCluster
Expand Down Expand Up @@ -117,7 +119,7 @@ def pre_run(self):
cli.app.CommandLineApp.pre_run(self)
# Set verbosity level
loglevel = max(1, logging.WARNING - 10 * max(0, self.params.verbose))
log.setLevel(loglevel)
coloredlogs.install(logger=log, level=loglevel)

# In debug mode, avoid forking
if self.params.verbose > 3:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import keystone_service

import mock
from nose.tools import assert_equal, assert_list_equal, assert_is_none
from nose import SkipTest


def setup():
Expand Down Expand Up @@ -68,7 +67,7 @@ def test_dispatch_service_present(mock_ensure_service_present,
region,
check_mode)]

assert_equal(manager.mock_calls, expected_calls)
assert manager.mock_calls == expected_calls


@mock.patch('keystone_service.ensure_endpoint_absent')
Expand Down Expand Up @@ -111,7 +110,7 @@ def test_dispatch_service_absent(mock_ensure_service_present,
mock.call.ensure_service_absent(keystone, name, check_mode)
]

assert_list_equal(manager.mock_calls, expected_calls)
assert manager.mock_calls == expected_calls


def test_ensure_service_present_when_present():
Expand All @@ -129,7 +128,7 @@ def test_ensure_service_present_when_present():

# Assertions
assert not changed
assert_equal(id, "b6a7ff03f2574cd9b5c7c61186e0d781")
assert id == "b6a7ff03f2574cd9b5c7c61186e0d781"

def test_ensure_service_present_when_present_check():
""" ensure_services_present when the service is present, check mode"""
Expand All @@ -146,7 +145,7 @@ def test_ensure_service_present_when_present_check():

# Assertions
assert not changed
assert_equal(id, "b6a7ff03f2574cd9b5c7c61186e0d781")
assert id=="b6a7ff03f2574cd9b5c7c61186e0d781"


def test_ensure_service_present_when_absent():
Expand All @@ -166,7 +165,7 @@ def test_ensure_service_present_when_absent():

# Assertions
assert changed
assert_equal(id, "a7ebed35051147d4abbe2ee049eeb346")
assert id=="a7ebed35051147d4abbe2ee049eeb346"
keystone.services.create.assert_called_with(name=name,
service_type=service_type,
description=description)
Expand All @@ -189,7 +188,7 @@ def test_ensure_service_present_when_absent_check():

# Assertions
assert changed
assert_equal(id, None)
assert id==None
assert not keystone.services.create.called


Expand All @@ -199,7 +198,7 @@ def test_get_endpoint_present():

endpoint = keystone_service.get_endpoint(keystone, "keystone")

assert_equal(endpoint.id, "600759628a214eb7b3acde39b1e85180")
assert endpoint.id=="600759628a214eb7b3acde39b1e85180"


def test_ensure_endpoint_present_when_present():
Expand All @@ -220,7 +219,7 @@ def test_ensure_endpoint_present_when_present():

# Assertions
assert not changed
assert_equal(id, "600759628a214eb7b3acde39b1e85180")
assert id=="600759628a214eb7b3acde39b1e85180"


def test_ensure_endpoint_present_when_present_check():
Expand All @@ -240,7 +239,7 @@ def test_ensure_endpoint_present_when_present_check():

# Assertions
assert not changed
assert_equal(id, "600759628a214eb7b3acde39b1e85180")
assert id=="600759628a214eb7b3acde39b1e85180"


def test_ensure_endpoint_present_when_absent():
Expand Down Expand Up @@ -277,7 +276,7 @@ def test_ensure_endpoint_present_when_absent():

# Assertions
assert changed
assert_equal(id, "622386d836b14fd986d9cec7504d208a")
assert id=="622386d836b14fd986d9cec7504d208a"
keystone.endpoints.create.assert_called_with(
service_id="0ad62de6cfe044c7a77ad3a7f2851b5d",
publicurl="http://192.168.206.130:8774/v2/%(tenant_id)s",
Expand Down Expand Up @@ -311,6 +310,5 @@ def test_ensure_endpoint_present_when_absent_check():

# Assertions
assert changed
assert_is_none(id)
assert id is None
assert not keystone.endpoints.create.called

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import keystone_user
import mock
from nose.tools import assert_equal, assert_is_none


def setup_tenant_user_role():
Expand Down Expand Up @@ -57,7 +56,7 @@ def test_ensure_tenant_exists_when_present():

# Assertions
assert not changed
assert_equal(id, "21b505b9cbf84bdfba60dc08cc2a4b8d")
assert id=="21b505b9cbf84bdfba60dc08cc2a4b8d"


def test_ensure_tenant_exists_when_present_check():
Expand All @@ -73,7 +72,7 @@ def test_ensure_tenant_exists_when_present_check():

# Assertions
assert not changed
assert_equal(id, "21b505b9cbf84bdfba60dc08cc2a4b8d")
assert id=="21b505b9cbf84bdfba60dc08cc2a4b8d"


def test_ensure_tenant_exists_when_absent():
Expand All @@ -90,7 +89,7 @@ def test_ensure_tenant_exists_when_absent():

# Assertions
assert changed
assert_equal(id, "7c310f797aa045898e2884a975ab32ab")
assert id=="7c310f797aa045898e2884a975ab32ab"
keystone.tenants.create.assert_called_with(tenant_name="bar",
description="The bar tenant",
enabled=True)
Expand All @@ -110,7 +109,7 @@ def test_ensure_tenant_exists_when_absent_check():

# Assertions
assert changed
assert_is_none(id)
assert id is None
assert not keystone.tenants.create.called


Expand All @@ -130,7 +129,7 @@ def test_ensure_user_exists_when_present():

# Assertions
assert not changed
assert_equal(id, "24073d9426ab4bc59527955d7c486179")
assert id=="24073d9426ab4bc59527955d7c486179"


def test_ensure_user_exists_when_present_check():
Expand All @@ -149,7 +148,7 @@ def test_ensure_user_exists_when_present_check():

# Assertions
assert not changed
assert_equal(id, "24073d9426ab4bc59527955d7c486179")
assert id=="24073d9426ab4bc59527955d7c486179"


def test_ensure_user_exists_when_absent():
Expand All @@ -173,7 +172,7 @@ def test_ensure_user_exists_when_absent():

# Assertions
assert changed
assert_equal(id, "5ce4b6ef2e814a4897907cc6db879536")
assert id=="5ce4b6ef2e814a4897907cc6db879536"
keystone.users.create.assert_called_with(
name='skippyjonjones',
password='1234567',
Expand Down Expand Up @@ -202,7 +201,7 @@ def test_ensure_user_exists_when_absent_check():

# Assertions
assert changed
assert_is_none(id)
assert id is None
assert not keystone.users.create.called


Expand All @@ -225,7 +224,7 @@ def test_ensure_role_exists_when_present():

# Assertions
assert not changed
assert_equal(id, "34a699ab89d04c38894bbf3d998e5229")
assert id=="34a699ab89d04c38894bbf3d998e5229"
assert not keystone.roles.create.called


Expand All @@ -249,7 +248,7 @@ def test_ensure_role_exists_when_present_check():

# Assertions
assert not changed
assert_equal(id, "34a699ab89d04c38894bbf3d998e5229")
assert id=="34a699ab89d04c38894bbf3d998e5229"
assert not keystone.roles.create.called


Expand All @@ -271,7 +270,7 @@ def test_ensure_role_exists_when_role_is_absent():

# Assertions
assert changed
assert_equal(id, "40b14f9c2d114b38b3f6bced49a792b8")
assert id=="40b14f9c2d114b38b3f6bced49a792b8"
keystone.roles.create.assert_called_with("webuser")


Expand All @@ -293,7 +292,7 @@ def test_ensure_role_exists_when_role_is_absent_check():

# Assertions
assert changed
assert_equal(id, None)
assert id is None
assert not keystone.roles.create.called


Expand All @@ -313,7 +312,7 @@ def test_ensure_role_exists_when_role_is_present_but_not_associated():

# Assertions
assert changed
assert_equal(id, "34a699ab89d04c38894bbf3d998e5229")
assert id=="34a699ab89d04c38894bbf3d998e5229"
assert not keystone.roles.create.called


Expand All @@ -334,7 +333,7 @@ def test_ensure_role_exists_when_role_is_present_but_not_associated_check():

# Assertions
assert changed
assert_is_none(id)
assert id is None
assert not keystone.roles.create.called


Expand All @@ -353,8 +352,7 @@ def test_dispatch_tenant_when_present(mock_ensure_tenant_exists):
# Assertions
mock_ensure_tenant_exists.assert_called_with(keystone, "bar",
"This is a bar", False)
assert_equal(res,
dict(changed=True, id="34469137412242129cd908e384717794"))
assert (res == dict(changed=True, id="34469137412242129cd908e384717794"))


def test_change_tenant_description():
Expand All @@ -368,7 +366,7 @@ def test_change_tenant_description():

# Assertions
assert changed
assert_equal(id, "21b505b9cbf84bdfba60dc08cc2a4b8d")
assert id=="21b505b9cbf84bdfba60dc08cc2a4b8d"


@mock.patch('keystone_user.ensure_user_exists')
Expand All @@ -389,8 +387,7 @@ def test_dispatch_user_when_present(mock_ensure_user_exists):
"12345", "admin@example.com",
"acme", False)

assert_equal(res,
dict(changed=True, id="0a6f3697fc314279b1a22c61d40c0919"))
assert (res == dict(changed=True, id="0a6f3697fc314279b1a22c61d40c0919"))


@mock.patch('keystone_user.ensure_role_exists')
Expand All @@ -407,5 +404,4 @@ def test_dispatch_role_present(mock_ensure_role_exists):
# Assertions
mock_ensure_role_exists.assert_called_with(keystone, "root",
"acme", "admin", False)
assert_equal(res,
dict(changed=True, id="7df22b53d9c4405f92032c802178a31e"))
assert (res == dict(changed=True, id="7df22b53d9c4405f92032c802178a31e"))
27 changes: 26 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def ansible_pb_files():
'ansible~=1.9.4',
'voluptuous>=0.8.2',
'configobj',
'coloredlogs',
# EC2 clouds
'boto',
# OpenStack clouds
Expand Down Expand Up @@ -99,6 +100,28 @@ def ansible_pb_files():
required_packages.append('python-novaclient')


## test runner setup
#
# See http://tox.readthedocs.org/en/latest/example/basic.html#integration-with-setuptools-distribute-test-commands
# on how to run tox when python setup.py test is run
#
from setuptools.command.test import test as TestCommand

class Tox(TestCommand):
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True

def run_tests(self):
# import here, cause outside the eggs aren't loaded
import tox
errno = tox.cmdline(self.test_args)
sys.exit(errno)


## real setup description begins here
#
setup(
name="elasticluster",
version="1.2.1.rc1",
Expand Down Expand Up @@ -131,15 +154,17 @@ def ansible_pb_files():
],
packages=find_packages(),
install_requires=required_packages,
tests_require=['tox', 'mock', 'nose'],
data_files=ansible_pb_files(),
entry_points={
'console_scripts': [
'elasticluster = elasticluster.main:main',
]
},
tests_require=['tox', 'mock', 'pytest'], # read right-to-left
cmdclass={'test': Tox},
)


if __name__ == "__main__":
if sys.argv[1] in ['develop', 'install']:
develop = True if sys.argv[1] == 'develop' else False
Expand Down
Empty file removed tests/__init__.py
Empty file.

0 comments on commit 5543e1b

Please sign in to comment.