def test_cms_module_register_blueprint_module1():
    assert admin_exists, \
        'Have you created the `admin` blueprint admin?'
    assert main_module_exists, \
        'Have do you have an `__init__.py` file in the `cms` application admin?'

    bp_import = get_imports(main_module_code(), 'cms.admin') or get_imports(
        main_module_code(), '.admin')
    bp_import_exists = bp_import is not None
    assert bp_import_exists, \
        'Do you have an import from `cms.admin` statement?'

    admin_bp_import = 'admin_bp' in bp_import
    assert admin_bp_import, \
        'Are you importing the `admin_bp` Blueprint from `cms.admin`?'

    register_bp_call = main_module_code().find('atomtrailers', lambda node: \
        node.value[0].value == 'app' and \
        node.value[1].value == 'register_blueprint' and \
        node.value[2].type == 'call')
    register_bp_call_exists = register_bp_call is not None
    assert register_bp_call_exists, \
        'Are you calling `register_blueprint` on `app`?'

    register_blueprint_args = list(register_bp_call.find_all('call_argument').map(lambda node: \
        str(node.target) + ':' + str(node.value)))
    register_count = len(register_blueprint_args) == 1
    assert register_count, \
        'Are you only passing one argument to `register_blueprint`?'
    admin_bp_registered = "None:admin_bp" in register_blueprint_args
    assert admin_bp_registered, \
        'Are you passing the Blueprint instance to should be `register_blueprint`?'
def test_admin_blueprint_move_model_classes_module1():
    assert admin_exists, \
        'Have you created the `admin` blueprint admin?'
    assert models_exists, \
        'Have you added the `models.py` file to the `admin` blueprint admin?'
    assert main_module_exists, \
        'Have do you have an `__init__.py` file in the `cms` application admin?'

    model_classes = list(
        models_code().find_all('class').map(lambda node: node.name))
    class_count = len(model_classes) == 4
    type_class = 'Type' in model_classes
    content_class = 'Content' in model_classes
    setting_class = 'Setting' in model_classes
    user_class = 'User' in model_classes
    assert class_count, \
        'Have you moved the four models from `cms/__init__.py` to `cms/admin/models.py`'
    assert type_class, \
        'Have you moved the `Type` model from `cms/__init__.py` to `cms/admin/models.py`'
    assert content_class, \
        'Have you moved the `Content` model from `cms/__init__.py` to `cms/admin/models.py`'
    assert setting_class, \
        'Have you moved the `Setting` model from `cms/__init__.py` to `cms/admin/models.py`'
    assert user_class, \
        'Have you moved the `User` model from `cms/__init__.py` to `cms/admin/models.py`'

    main_module_classes = list(
        main_module_code().find_all('class').map(lambda node: node.name))
    main_module_class_count = len(main_module_classes) == 0
    assert main_module_class_count, \
        'Have you removed the four models from `cms/__init__.py`?'

    models_import = get_imports(main_module_code(),
                                'cms.admin.models') or get_imports(
                                    main_module_code(), '.admin.models')
    models_import_exists = models_import is not None
    assert models_import_exists, \
        'Do you have an import from `cms.admin.models` statement?'

    models_import_content = 'Content' in models_import
    assert models_import_content, \
        'Are you importing the `Content` model class from `cms.admin.models` in `cms/__init__.py`?'

    models_import_type = 'Type' in models_import
    assert models_import_type, \
        'Are you importing the `Type` model class from `cms.admin.models` in `cms/__init__.py`?'

    models_import_setting = 'Setting' in models_import
    assert models_import_setting, \
        'Are you importing the `Setting` model class from `cms.admin.models` in `cms/__init__.py`?'

    models_import_user = '******' in models_import
    assert models_import_user, \
        'Are you importing the `User` model class from `cms.admin.models` in `cms/__init__.py`?'
def test_admin_blueprint_imports_module1():
    assert admin_exists, \
        'Have you created the `admin` blueprint admin?'
    assert module_exists, \
        'Have you added the `__init__.py` file to the `admin` blueprint admin?'

    flask_import = get_imports(module_code(), 'flask')
    flask_import_exits = flask_import is not None
    assert flask_import_exits, \
        'Are you importing the correct methods and classes from `flask`?'
    render_template_import = 'render_template' in flask_import
    assert render_template_import, \
        'Are you importing `render_template` from `flask` in `cms/admin/__init__.py`?'
    abort_import = 'abort' in flask_import
    assert abort_import, \
        'Are you importing `abort` from `flask` in `cms/admin/__init__.py`?'

    module_import = get_imports(module_code(),
                                'cms.admin.models') or get_imports(
                                    module_code(), '.models')
    module_import_exists = module_import is not None
    assert module_import_exists, \
        'Are you importing the correct methods and classes from `cms.admin.models` in `cms/admin/__init__.py`?'

    name_as_name_content = 'Content' in module_import
    assert name_as_name_content, \
        'Are you importing the `Content` model class from `cms.admin.models` in `cms/admin/__init__.py`?'

    name_as_name_type = 'Type' in module_import
    assert name_as_name_type, \
        'Are you importing the `Type` model class from `cms.admin.models` in `cms/admin/__init__.py`?'

    name_as_name_setting = 'Setting' in module_import
    assert name_as_name_setting, \
        'Are you importing the `Setting` model class from `cms.admin.models` in `cms/admin/__init__.py`?'

    name_as_name_user = '******' in module_import
    assert name_as_name_user, \
        'Are you importing the `User` model class from `cms.admin.models` in `cms/admin/__init__.py`?'
def test_cms_module_import_db_module1():
    assert admin_exists, \
        'Have you created the `admin` blueprint admin?'
    assert main_module_exists, \
        'Have do you have an `__init__.py` file in the `cms` application admin?'

    db_assignment = main_module_code().find('atomtrailers', lambda node: \
        node.value[0].value == 'SQLAlchemy' and \
        node.value[1].type == 'call' and \
        node.parent.type == 'assignment' and \
        node.parent.target.value == 'db') is None
    assert db_assignment, \
        'Have you removed the `SQLAlchemy` instance named `db` from `cms/__init__.py`?'

    models_import = get_imports(main_module_code(),
                                'cms.admin.models') or get_imports(
                                    main_module_code(), '.admin.models')
    models_import_exists = models_import is not None
    assert models_import_exists, \
        'Do you have an import from `cms.admin.models` statement?'

    db_import_exists = 'db' in models_import
    assert db_import_exists, \
        'Are you importing the `db` SQLAlchemy instance from `cms.admin.models` in `cms/__init__.py`?'

    init_app_call = main_module_code().find('name', lambda node: \
        node.value == 'init_app' and \
        node.parent.value[0].value == 'db' and \
        node.parent.value[2].type == 'call')
    init_app_call_exists = init_app_call is not None
    assert init_app_call_exists, \
        'Are you calling the `init_app` method on `db`?'
    init_app_arg = init_app_call.parent.find(
        'call_argument').value.value == 'app'
    assert init_app_arg, \
        'Are you passing `app` to the `init_app` method?'