tests.manager_tests package

Submodules

tests.manager_tests.mock_utils module

Utilities for mocking out AWS handlers

class tests.manager_tests.mock_utils.MockResponse(json_data, status_code)[source]
json()[source]
tests.manager_tests.mock_utils.mock_db_handler(data, keyname)[source]
Parameters:
  • data (dict) – dict from keys to data
  • keyname (string) –
tests.manager_tests.mock_utils.mock_gogs_handler(tokens)[source]
Parameters:tokens – collection of valid user tokens

tests.manager_tests.test_manager module

class tests.manager_tests.test_manager.ManagerTest(methodName='runTest')[source]

Bases: unittest.case.TestCase

MOCK_CALLBACK_URL = u'http://example.com/client/callback'
class PayloadMock(spec=None, side_effect=None, return_value=sentinel.DEFAULT, wraps=None, name=None, spec_set=None, parent=None, _spec_state=None, _new_name='', _new_parent=None, **kwargs)[source]

Bases: mock.mock.Mock

assert_any_call(*args, **kwargs)

assert the mock has been called with the specified arguments.

The assert passes if the mock has ever been called, unlike assert_called_with and assert_called_once_with that only pass if the call is the most recent one.

assert_called(*args, **kwargs)

assert that the mock was called at least once

assert_called_once(*args, **kwargs)

assert that the mock was called only once.

assert_called_once_with(*args, **kwargs)

assert that the mock was called exactly once and with the specified arguments.

assert_called_with(*args, **kwargs)

assert that the mock was called with the specified arguments.

Raises an AssertionError if the args and keyword args passed in are different to the last call to the mock.

assert_has_calls(*args, **kwargs)

assert the mock has been called with the specified calls. The mock_calls list is checked for the calls.

If any_order is False (the default) then the calls must be sequential. There can be extra calls before or after the specified calls.

If any_order is True then the calls can be in any order, but they must all appear in mock_calls.

assert_not_called(*args, **kwargs)

assert that the mock was never called.

attach_mock(*args, **kwargs)

Attach a mock as an attribute of this one, replacing its name and parent. Calls to the attached mock will be recorded in the method_calls and mock_calls attributes of this one.

configure_mock(*args, **kwargs)

Set attributes on the mock through keyword arguments.

Attributes plus return values and side effects can be set on child mocks using standard dot notation and unpacking a dictionary in the method call:

>>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError}
>>> mock.configure_mock(**attrs)
mock_add_spec(*args, **kwargs)

Add a spec to a mock. spec can either be an object or a list of strings. Only attributes on the spec can be fetched as attributes from the mock.

If spec_set is True then only attributes on the spec can be set.

read(*args, **kwargs)[source]
reset_mock(*args, **kwargs)

Restore the mock object to its initial state.

response = None
ManagerTest.addCleanup(*args, **kwargs)

Add a function, with arguments, to be called when the test is completed. Functions added are called on a LIFO basis and are called after tearDown on test failure or success.

Cleanup items are called even if setUp fails (unlike tearDown).

ManagerTest.addTypeEqualityFunc(*args, **kwargs)

Add a type specific assertEqual style function to compare a type.

This method is for use by TestCase subclasses that need to register their own type equality functions to provide nicer error messages.

Args:
typeobj: The data type to call this function on when both values
are of the same type in assertEqual().
function: The callable taking two arguments and an optional
msg= argument that raises self.failureException with a useful error message when the two arguments are not equal.
ManagerTest.assertAlmostEqual(*args, **kwargs)

Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the between the two objects is more than the given delta.

Note that decimal places (from zero) are usually not the same as significant digits (measured from the most signficant digit).

If the two objects compare equal then they will automatically compare almost equal.

ManagerTest.assertAlmostEquals(*args, **kwargs)

Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the between the two objects is more than the given delta.

Note that decimal places (from zero) are usually not the same as significant digits (measured from the most signficant digit).

If the two objects compare equal then they will automatically compare almost equal.

ManagerTest.assertDictContainsSubset(*args, **kwargs)

Checks whether actual is a superset of expected.

ManagerTest.assertDictEqual(*args, **kwargs)
ManagerTest.assertEqual(*args, **kwargs)

Fail if the two objects are unequal as determined by the ‘==’ operator.

ManagerTest.assertEquals(*args, **kwargs)

Fail if the two objects are unequal as determined by the ‘==’ operator.

ManagerTest.assertFalse(*args, **kwargs)

Check that the expression is false.

ManagerTest.assertGreater(*args, **kwargs)

Just like self.assertTrue(a > b), but with a nicer default message.

ManagerTest.assertGreaterEqual(*args, **kwargs)

Just like self.assertTrue(a >= b), but with a nicer default message.

ManagerTest.assertIn(*args, **kwargs)

Just like self.assertTrue(a in b), but with a nicer default message.

ManagerTest.assertIs(*args, **kwargs)

Just like self.assertTrue(a is b), but with a nicer default message.

ManagerTest.assertIsInstance(*args, **kwargs)

Same as self.assertTrue(isinstance(obj, cls)), with a nicer default message.

ManagerTest.assertIsNone(*args, **kwargs)

Same as self.assertTrue(obj is None), with a nicer default message.

ManagerTest.assertIsNot(*args, **kwargs)

Just like self.assertTrue(a is not b), but with a nicer default message.

ManagerTest.assertIsNotNone(*args, **kwargs)

Included for symmetry with assertIsNone.

ManagerTest.assertItemsEqual(*args, **kwargs)

An unordered sequence specific comparison. It asserts that actual_seq and expected_seq have the same element counts. Equivalent to:

self.assertEqual(Counter(iter(actual_seq)),
                 Counter(iter(expected_seq)))

Asserts that each element has the same count in both sequences. Example:

  • [0, 1, 1] and [1, 0, 1] compare equal.
  • [0, 0, 1] and [0, 1] compare unequal.
ManagerTest.assertLess(*args, **kwargs)

Just like self.assertTrue(a < b), but with a nicer default message.

ManagerTest.assertLessEqual(*args, **kwargs)

Just like self.assertTrue(a <= b), but with a nicer default message.

ManagerTest.assertListEqual(*args, **kwargs)

A list-specific equality assertion.

Args:

list1: The first list to compare. list2: The second list to compare. msg: Optional message to use on failure instead of a list of

differences.
ManagerTest.assertMultiLineEqual(*args, **kwargs)

Assert that two multi-line strings are equal.

ManagerTest.assertNotAlmostEqual(*args, **kwargs)

Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the between the two objects is less than the given delta.

Note that decimal places (from zero) are usually not the same as significant digits (measured from the most signficant digit).

Objects that are equal automatically fail.

ManagerTest.assertNotAlmostEquals(*args, **kwargs)

Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the between the two objects is less than the given delta.

Note that decimal places (from zero) are usually not the same as significant digits (measured from the most signficant digit).

Objects that are equal automatically fail.

ManagerTest.assertNotEqual(*args, **kwargs)

Fail if the two objects are equal as determined by the ‘!=’ operator.

ManagerTest.assertNotEquals(*args, **kwargs)

Fail if the two objects are equal as determined by the ‘!=’ operator.

ManagerTest.assertNotIn(*args, **kwargs)

Just like self.assertTrue(a not in b), but with a nicer default message.

ManagerTest.assertNotIsInstance(*args, **kwargs)

Included for symmetry with assertIsInstance.

ManagerTest.assertNotRegexpMatches(*args, **kwargs)

Fail the test if the text matches the regular expression.

ManagerTest.assertRaises(*args, **kwargs)

Fail unless an exception of class excClass is raised by callableObj when invoked with arguments args and keyword arguments kwargs. If a different type of exception is raised, it will not be caught, and the test case will be deemed to have suffered an error, exactly as for an unexpected exception.

If called with callableObj omitted or None, will return a context object used like this:

with self.assertRaises(SomeException):
    do_something()

The context manager keeps a reference to the exception as the ‘exception’ attribute. This allows you to inspect the exception after the assertion:

with self.assertRaises(SomeException) as cm:
    do_something()
the_exception = cm.exception
self.assertEqual(the_exception.error_code, 3)
ManagerTest.assertRaisesRegexp(*args, **kwargs)

Asserts that the message in a raised exception matches a regexp.

Args:

expected_exception: Exception class expected to be raised. expected_regexp: Regexp (re pattern object or string) expected

to be found in error message.

callable_obj: Function to be called. args: Extra args. kwargs: Extra kwargs.

ManagerTest.assertRegexpMatches(*args, **kwargs)

Fail the test unless the text matches the regular expression.

ManagerTest.assertSequenceEqual(*args, **kwargs)

An equality assertion for ordered sequences (like lists and tuples).

For the purposes of this function, a valid ordered sequence type is one which can be indexed, has a length, and has an equality operator.

Args:

seq1: The first sequence to compare. seq2: The second sequence to compare. seq_type: The expected datatype of the sequences, or None if no

datatype should be enforced.
msg: Optional message to use on failure instead of a list of
differences.
ManagerTest.assertSetEqual(*args, **kwargs)

A set-specific equality assertion.

Args:

set1: The first set to compare. set2: The second set to compare. msg: Optional message to use on failure instead of a list of

differences.

assertSetEqual uses ducktyping to support different types of sets, and is optimized for sets specifically (parameters must support a difference method).

ManagerTest.assertTrue(*args, **kwargs)

Check that the expression is true.

ManagerTest.assertTupleEqual(*args, **kwargs)

A tuple-specific equality assertion.

Args:

tuple1: The first tuple to compare. tuple2: The second tuple to compare. msg: Optional message to use on failure instead of a list of

differences.
ManagerTest.assert_(*args, **kwargs)

Check that the expression is true.

ManagerTest.call_args(*args, **kwargs)[source]
Parameters:
  • mock_object – mock object that is expected to have been called
  • num_args – expected number of (non-keyword) arguments
  • num_kwargs – expected number of keyword arguments
Returns:

(args, kwargs) of last invocation of mock_object

ManagerTest.countTestCases(*args, **kwargs)
ManagerTest.create_mock_payload(*args, **kwargs)[source]
ManagerTest.debug(*args, **kwargs)

Run the test without collecting errors in a TestResult

ManagerTest.defaultTestResult(*args, **kwargs)
ManagerTest.doCleanups(*args, **kwargs)

Execute all cleanup functions. Normally called for you after tearDown.

ManagerTest.fail(*args, **kwargs)

Fail immediately, with the given message.

ManagerTest.failIf(*args, **kwargs)
ManagerTest.failIfAlmostEqual(*args, **kwargs)
ManagerTest.failIfEqual(*args, **kwargs)
ManagerTest.failUnless(*args, **kwargs)
ManagerTest.failUnlessAlmostEqual(*args, **kwargs)
ManagerTest.failUnlessEqual(*args, **kwargs)
ManagerTest.failUnlessRaises(*args, **kwargs)
ManagerTest.failureException

alias of AssertionError

ManagerTest.get_count_from_row(*args, **kwargs)[source]
ManagerTest.id(*args, **kwargs)
ManagerTest.init_items(*args, **kwargs)[source]
ManagerTest.mock_build_language_popularity_tables(*args, **kwargs)[source]
ManagerTest.mock_gogs = None
ManagerTest.populate_tables(*args, **kwargs)[source]
ManagerTest.requested_urls = []
ManagerTest.run(*args, **kwargs)
ManagerTest.setUp(*args, **kwargs)[source]

Runs before each test.

classmethod ManagerTest.setUpClass()[source]
ManagerTest.shortDescription(*args, **kwargs)

Returns a one-line description of the test, or None if no description has been provided.

The default implementation of this method returns the first line of the specified test method’s docstring.

ManagerTest.skipTest(*args, **kwargs)

Skip this test.

ManagerTest.tearDown(*args, **kwargs)[source]

Runs after each test.

classmethod ManagerTest.tearDownClass()[source]
ManagerTest.test_generate_dashboard(*args, **kwargs)[source]
ManagerTest.test_generate_dashboard_max_two(*args, **kwargs)[source]
ManagerTest.test_list_jobs(*args, **kwargs)[source]

Test list_jobs and list_endpoint methods.

ManagerTest.test_register_module(*args, **kwargs)[source]
ManagerTest.validateFailureTable(*args, **kwargs)[source]
ManagerTest.validateModule(*args, **kwargs)[source]

Module contents