def test_schema_methods_get_patched(self):
        original_methods = self._get_current_methods()

        with Namespace():
            patched_methods = self._get_current_methods()

        unpatched_methods = self._get_current_methods()

        for original_method, patched_method, unpatched_method in \
                zip(original_methods, patched_methods, unpatched_methods):
            self.assertEqual(original_method, unpatched_method)
            self.assertNotEqual(original_method, patched_method)
    def test_customer_operations_outside_of_namespace(self):
        with self.assertRaises(braintree.exceptions.NotFoundError):
            braintree.Customer.find('nonexistent')

        _ensure_user_exists({
            'id': 'nonnamespaced',
        })

        with Namespace():
            pass

        try:
            braintree.Customer.find('nonnamespaced')
        except braintree.exceptions.NotFoundError:
            self.fail()
    def test_advanced_search_gets_patched(self):
        original_nodes = self._get_current_search_nodes()

        with Namespace():
            patched_nodes = self._get_current_search_nodes()

        unpatched_nodes = self._get_current_search_nodes()

        # NamespaceError is raised on __getattribute__ for patched nodes.
        for orig_node, unpatched_node in zip(original_nodes, unpatched_nodes):
            self.assertIs(orig_node, unpatched_node)
            self.assertIsNone(getattr(orig_node, 'foo', None))  # should not raise NamespaceError

        for node in patched_nodes:
            with self.assertRaises(NamespaceError):
                node.foo
 def test_omit_options_gets_empty(self):
     namespace = Namespace()
     self.assertEqual(namespace.options, {})
 def setUp(self):
     self.namespace = Namespace()
     self.namespace.__enter__()
     self.addCleanup(self.namespace.__exit__)
class NamespaceTest(TestCase):
    def setUp(self):
        self.namespace = Namespace()
        self.namespace.__enter__()
        self.addCleanup(self.namespace.__exit__)