Example #1
0
 def test_preload_databases(self):
     db_name = Configuration.get('db_name')
     with DBTestCase.Configuration(db_names=[db_name]):
         with LogCapture('anyblok_pyramid.common', level=INFO) as handler:
             preload_databases()
             messages = handler.get_info_messages()
             self.assertTrue(messages)
             self.assertIn('The database %r is preloaded' % db_name,
                           messages)
Example #2
0
 def test_preload_unexisting_databases(self):
     db_name = 'wrong_db_name'
     with DBTestCase.Configuration(db_names=[db_name]):
         with LogCapture('anyblok_pyramid.common',
                         level=WARNING) as handler:
             preload_databases()
             messages = handler.get_warning_messages()
             self.assertTrue(messages)
             self.assertIn('The database %r does not exist' % db_name,
                           messages)
Example #3
0
    def test_example_patch_with_errors(self):
        """Example PATCH /examples/with/error/{id}"""
        ex = self.create_example()
        with LogCapture() as logs:
            self.webserver.patch_json('/examples/with/error/%s' % ex.id,
                                      {'name': 'plip'},
                                      status=500)

        assert ('Request error found: rollback the registry'
                in logs.get_debug_messages())
Example #4
0
    def test_example_delete_with_errors(self):
        """Example DELETE /examples/with/error/{id}"""
        ex = self.create_example()
        with LogCapture() as logs:
            response = self.webserver.delete('/examples/with/error/%s' % ex.id,
                                             status=500)

        assert response.status_code == 500
        assert ('Request error found: rollback the registry'
                in logs.get_debug_messages())
Example #5
0
    def test_example_collection_patch_with_errors(self):
        """Example PATCH /examples/with/errors"""
        ex = self.create_example()
        with LogCapture() as logs:
            response = self.webserver.patch_json('/examples/with/errors',
                                                 [{
                                                     'id': ex.id,
                                                     'name': 'plip'
                                                 }],
                                                 status=500)

        assert response.status_code == 500
        assert ex.name != "plip"
        assert ('Request error found: rollback the registry'
                in logs.get_debug_messages())
Example #6
0
    def test_example_collection_post_with_errors(self):
        """Example POST /examples/with/errors"""
        with LogCapture() as logs:
            fail = self.webserver.post_json('/examples/with/errors',
                                            [{
                                                'name': 'plip'
                                            }],
                                            status=500)

        assert fail.status_code == 500
        assert fail.json_body.get('status') == 'error'
        assert fail.json_body.get('errors')[0].get('location') == 'body'
        assert fail.json_body.get('errors')[0].get('description') == 'test'

        assert ('Request error found: rollback the registry'
                in logs.get_debug_messages())
Example #7
0
    def test_postcommit_hook_with_exception(self):
        def add_in_registry():

            from anyblok import Declarations

            @Declarations.register(Declarations.Model)
            class Test:
                @classmethod
                def _postcommit_hook(cls):
                    raise Exception('Here one exception')

        registry = self.init_registry(add_in_registry)
        registry.Test.postcommit_hook('_postcommit_hook')
        with LogCapture('anyblok.registry', level=ERROR) as logs:
            registry.commit()
            messages = logs.get_error_messages()
            message = messages[0]
            self.assertIn('Here one exception', message)
Example #8
0
 def test_model_is_initialized(self):
     with LogCapture('anyblok.registry', DEBUG) as logs:
         self.init_registry(None)
         messages = logs.get_debug_messages()
         self.assertIn("Initialize 'Model' entry", messages)
Example #9
0
 def test_model_is_assembled(self):
     with LogCapture('anyblok.registry', level=DEBUG) as logs:
         self.init_registry(None)
         messages = logs.get_debug_messages()
         self.assertIn("Assemble 'Model' entry", messages)