forked from Katello/katello
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tomas Strachota
committed
Aug 26, 2011
1 parent
a5be798
commit 0566781
Showing
2 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import unittest | ||
from mock import Mock | ||
import os | ||
|
||
from cli_test_utils import CLIOptionTestCase, CLIActionTestCase | ||
import test_data | ||
|
||
import katello.client.core.product | ||
from katello.client.core.product import Sync | ||
|
||
|
||
|
||
class RequiredCLIOptionsTests(CLIOptionTestCase): | ||
|
||
def setUp(self): | ||
self.set_action(Sync()) | ||
self.mock_options() | ||
|
||
def test_missing_org_generates_error(self): | ||
self.assertRaises(Exception, self.action.process_options, ['synchronize', '--name=product_1']) | ||
|
||
def test_missing_product_generates_error(self): | ||
self.assertRaises(Exception, self.action.process_options, ['synchronize', '--org=ACME']) | ||
|
||
def test_no_error_if_org_and_product_provided(self): | ||
self.action.process_options(['list', '--org=ACME', '--name=product_1']) | ||
self.assertEqual(len(self.action.optErrors), 0) | ||
|
||
|
||
class ProductSyncTest(CLIActionTestCase): | ||
|
||
ORG = test_data.ORGS[0] | ||
ENV = test_data.ENVS[0] | ||
PROV = test_data.PROVIDERS[2] | ||
PROD = test_data.PRODUCTS[0] | ||
|
||
OPTIONS = { | ||
'org': ORG['name'], | ||
'name': PROD['name'] | ||
} | ||
|
||
def setUp(self): | ||
self.set_action(Sync()) | ||
self.set_module(katello.client.core.product) | ||
|
||
self.mock_options(self.OPTIONS) | ||
|
||
self.mock(self.action.api, 'sync', test_data.SYNC_RESULT_WITHOUT_ERROR) | ||
|
||
self.mock(self.module, 'get_product', self.PROD) | ||
self.mock(self.module, 'run_async_task_with_status', test_data.SYNC_RESULT_WITHOUT_ERROR) | ||
|
||
|
||
def test_finds_the_product(self): | ||
self.action.run() | ||
self.module.get_product.assert_called_once_with(self.ORG['name'], self.PROD['name']) | ||
|
||
def test_returns_with_error_when_no_product_found(self): | ||
self.module.get_product.return_value = None | ||
self.assertEqual(self.action.run(), os.EX_DATAERR) | ||
|
||
def test_calls_sync_api(self): | ||
self.action.run() | ||
self.action.api.sync.assert_called_once_with(self.PROD['id']) | ||
|
||
def test_waits_for_sync(self): | ||
self.action.run() | ||
self.module.run_async_task_with_status.assert_called_once() | ||
|
||
def test_returns_ok_when_sync_was_successful(self): | ||
self.assertEqual(self.action.run(), os.EX_OK) | ||
|
||
def test_returns_error_if_sync_failed(self): | ||
self.module.run_async_task_with_status.return_value = test_data.SYNC_RESULT_WITH_ERROR | ||
self.assertEqual(self.action.run(), os.EX_DATAERR) | ||
|
||
|