示例#1
0
 def test_error_on_positional_constructor_args(self):
     with self.assertRaises(TypeError):
         PlainNamespace('a')
     with self.assertRaises(TypeError):
         PlainNamespace('a', 'bb')
     with self.assertRaises(TypeError):
         PlainNamespace('xyz', a=sentinel.a, bb=sentinel.bb)
示例#2
0
    def test_initialization_with_default_binding_key(self,
                                                     binding_key,
                                                     mocked_conf_from_files,
                                                     expected_config,
                                                     expected_config_full,
                                                     custom_config_spec_pattern=None):
        class SomeParser(BaseParser):
            default_binding_key = binding_key  # => it's a concrete class

        if custom_config_spec_pattern is not None:
            SomeParser.config_spec_pattern = custom_config_spec_pattern

        unready_instance = SomeParser.__new__(SomeParser)
        self._asserts_of_proper__new__instance_adjustment(unready_instance)
        self._asserts_of_proper_preinit_hook_instance_adjustment(unready_instance, binding_key)

        super_cls_mock = PlainNamespace(__init__=Mock())
        with patch_always('n6.parsers.generic.super',
                          return_value=super_cls_mock) as super_mock, \
             patch('n6.parsers.generic.Config._load_n6_config_files',
                   return_value=mocked_conf_from_files):
            # instantiation
            instance = SomeParser(a=sentinel.a, bb=sentinel.bb)
            self._asserts_of_proper__new__instance_adjustment(instance)
            self._asserts_of_proper_preinit_hook_instance_adjustment(instance, binding_key)
            self._basic_init_related_asserts(
                instance,
                SomeParser,
                super_mock,
                super_cls_mock,
                expected_config,
                expected_config_full)
示例#3
0
def monkey_patching():
    _skip_irrelevant_tests()
    _set_expected_rest_api_resource_limits_to_defaults()
    _patch_AuthAPILdapDataBasedMethodTestMixIn()
    _patch_TestAuthAPI__get_org_ids_to_notification_configs()
    test_auth_api.LOGGER_error_mock_factory = lambda: PlainNamespace(call_count
                                                                     =ANY)
    n6lib.config.LOGGER = MagicMock()
示例#4
0
 def stub_of__QueuedBase_run(self):
     self._connection = PlainNamespace(
         add_timeout=_add_timeout, outbound_buffer=collections.deque())
     self.output_ready = True
     try:
         try:
             self.start_publishing()
             for callback in _consume_timeout_callbacks():
                 callback()
         finally:
             _clear_timeout_callbacks()
     finally:
         self._ensure_publishing_generator_closed()
示例#5
0
 def test_ne(self):
     obj2 = PlainNamespace(a=sentinel.a, bb=sentinel.bb, self=sentinel.self)
     obj3 = PlainNamespace(a=sentinel.a, bb=sentinel.bb)
     obj_empty = PlainNamespace()
     self.assertFalse(self.obj != self.obj)
     self.assertFalse(obj2 != obj2)
     self.assertFalse(obj3 != obj3)
     self.assertFalse(obj_empty != obj_empty)
     self.assertFalse(self.obj != obj2)
     self.assertFalse(obj2 != self.obj)
     self.assertTrue(self.obj != obj3)
     self.assertTrue(obj3 != self.obj)
     self.assertTrue(self.obj != obj_empty)
     self.assertTrue(obj_empty != self.obj)
     self.assertTrue(obj2 != obj3)
     self.assertTrue(obj3 != obj2)
     self.assertTrue(obj2 != obj_empty)
     self.assertTrue(obj_empty != obj2)
     self.assertTrue(obj3 != obj_empty)
     self.assertTrue(obj_empty != obj3)
     del obj2.self
     self.assertFalse(obj2 != obj2)
     self.assertFalse(obj2 != obj3)
     self.assertFalse(obj3 != obj2)
     self.assertTrue(self.obj != obj2)
     self.assertTrue(obj2 != self.obj)
     self.assertTrue(obj2 != obj_empty)
     self.assertTrue(obj_empty != obj2)
     del obj2.a, obj2.bb
     self.assertFalse(obj2 != obj2)
     self.assertFalse(obj2 != obj_empty)
     self.assertFalse(obj_empty != obj2)
     self.assertTrue(self.obj != obj2)
     self.assertTrue(obj2 != self.obj)
     self.assertTrue(obj2 != obj3)
     self.assertTrue(obj3 != obj2)
示例#6
0
 def test__init(self):
     super_cls_mock = PlainNamespace(__init__=Mock())
     with patch_always('n6.collectors.generic.super',
                       return_value=super_cls_mock) as super_mock:
         # instantiation
         instance = BaseOneShotCollector(input_data=SAMPLE_INPUT_DATA,
                                         a=SAMPLE_ARG_A,
                                         bb=SAMPLE_ARG_B)
         # assertions
         self.assertIsInstance(instance, BaseOneShotCollector)
         super_mock.assert_called_once_with(BaseOneShotCollector, instance)
         super_cls_mock.__init__.assert_called_once_with(a=SAMPLE_ARG_A,
                                                         bb=SAMPLE_ARG_B)
         self.assertIs(instance.input_data, SAMPLE_INPUT_DATA)
         # instantiation without the `input_data` argument
         instance_2 = BaseOneShotCollector(a=SAMPLE_ARG_A, bb=SAMPLE_ARG_B)
         self.assertEqual(instance_2.input_data, {})
示例#7
0
 def test__prepare_data__rk__with_raw_format_version_tag(self):
     data = self.meth.prepare_data(
         routing_key='ham.spam.33',
         body=sentinel.body,
         properties=PlainNamespace(foo=sentinel.foo,
                                   bar=sentinel.bar,
                                   timestamp=1389348840,
                                   headers={'a': sentinel.a}))
     self.assertEqual(data, {
         'a': sentinel.a,
         'properties.foo': sentinel.foo,
         'properties.bar': sentinel.bar,
         'source': 'ham.spam',
         'properties.timestamp': '2014-01-10 10:14:00',
         'raw_format_version_tag': '33',
         'raw': sentinel.body,
     })
 def _make_inserts_memo(self):
     return PlainNamespace(
         already_inserted_ca_labels=set(),
         parent_ca_label_to_pending_attr_dicts=collections.defaultdict(
             list),
     )
示例#9
0
SAMPLE_OTHER_CONFIG_SECTION = "other_section"
SAMPLE_CONFIG_REQUIRED = ('required_opt', )
SAMPLE_REQUIRED_VALUE = "some option which is required"
SAMPLE_OTHER_REQUIRED_VALUE = "123.89"
CONFIG_WITH_NO_SECTION_DECLARED = ConfigSection('<no section declared>')
MOCKED_CONFIG = {
    'some_section': {
        'required_opt': SAMPLE_REQUIRED_VALUE,
        'some_opt': "ABc dd",
    },
    'other_section': {
        'required_opt': SAMPLE_OTHER_REQUIRED_VALUE,
        'some_opt': '[{"a": "bcd"}]',
    },
}
MOCKED_SUPER_CLS = PlainNamespace(__init__=Mock())
SAMPLE_EMAIL_MESSAGE = sentinel.email_msg
SAMPLE_INPUT_DATA = sentinel.input_data
SAMPLE_MESSAGE_ID = sentinel.message_id
SAMPLE_SOURCE = sentinel.source
SAMPLE_SOURCE_CHANNEL = sentinel.source_channel
SAMPLE_TYPE = sentinel.type
SAMPLE_CONTENT_TYPE = 'text/csv'
SAMPLE_OUTPUT_COMPONENTS = sentinel.output_components
SAMPLE_OUTPUT_RK = sentinel.output_rk
SAMPLE_OUTPUT_DATA_BODY = sentinel.output_data_body
SAMPLE_OUTPUT_PROP_KWARGS = sentinel.output_prop_kwargs

CONFIG_PATCHER = patch('n6lib.config.Config._load_n6_config_files',
                       return_value=MOCKED_CONFIG)
SUPER_PATCHER = patch('n6.collectors.generic.super',
示例#10
0
 def test_repr(self):
     self.obj.xxxx = 'xxxx'
     self.assertEqual(
         repr(self.obj), "PlainNamespace(a=sentinel.a, bb=sentinel.bb, "
         "self=sentinel.self, xxxx='xxxx')")
     self.assertEqual(repr(PlainNamespace()), "PlainNamespace()")
示例#11
0
 def setUp(self):
     self.obj = PlainNamespace(a=sentinel.a, bb=sentinel.bb)
     self.obj.self = sentinel.self