From b9408dc8ef173a15ec58adf99a899db390d58067 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Thu, 21 Jan 2021 11:13:37 +1300 Subject: [PATCH] Django integration tests (#1607) * added integration test for module django_manage * Initial attempt at integration tests for django_manage * added ignore lines for django python code * added more ignore lines for django python code * removed a couple of extraneous files and ignore lines * also removed urls.py, as it is not required for testing * added test group to aliases file * Adding a few lines attempting to remove py2 from the equation. * restricted integration tests platforms * restricted integration tests platforms (moving to aliases) * foce using a virtualenv for the test, to avoid differences in different OSes * Adding urls.py back to the test project * Adding ignore lines for urls.py * Updated aliases for the testing --- .../integration/targets/django_manage/aliases | 6 + .../single_app_project/core/settings.py | 2 + .../single_app_project/manage.py | 12 ++ .../base_test/simple_project/p1/manage.py | 22 ++++ .../simple_project/p1/p1/__init__.py | 0 .../simple_project/p1/p1/settings.py | 120 ++++++++++++++++++ .../base_test/simple_project/p1/p1/urls.py | 21 +++ .../files/base_test/startproj/.keep | 0 .../targets/django_manage/tasks/main.yaml | 50 ++++++++ tests/sanity/ignore-2.10.txt | 13 ++ tests/sanity/ignore-2.11.txt | 13 ++ tests/sanity/ignore-2.9.txt | 13 ++ 12 files changed, 272 insertions(+) create mode 100644 tests/integration/targets/django_manage/aliases create mode 100644 tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/core/settings.py create mode 100755 tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py create mode 100755 tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py create mode 100644 tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/__init__.py create mode 100644 tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/settings.py create mode 100644 tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/urls.py create mode 100644 tests/integration/targets/django_manage/files/base_test/startproj/.keep create mode 100644 tests/integration/targets/django_manage/tasks/main.yaml diff --git a/tests/integration/targets/django_manage/aliases b/tests/integration/targets/django_manage/aliases new file mode 100644 index 0000000000..fcd92e1a91 --- /dev/null +++ b/tests/integration/targets/django_manage/aliases @@ -0,0 +1,6 @@ +shippable/posix/group2 +skip/python2 +skip/freebsd +skip/macos +skip/osx +skip/rhel8.2 diff --git a/tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/core/settings.py b/tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/core/settings.py new file mode 100644 index 0000000000..62107209ba --- /dev/null +++ b/tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/core/settings.py @@ -0,0 +1,2 @@ +# single_app_project/core/settings.py +SECRET_KEY = 'testtesttesttesttest' diff --git a/tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py b/tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py new file mode 100755 index 0000000000..979a04d8dd --- /dev/null +++ b/tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py @@ -0,0 +1,12 @@ +#! /usr/bin/env python3 +# single_app_project/manage.py +import os +import sys + +def main(): + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'single_app_project.core.settings') + from django.core.management import execute_from_command_line + execute_from_command_line(sys.argv) + +if __name__ == '__main__': + main() diff --git a/tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py b/tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py new file mode 100755 index 0000000000..475ed1dd5d --- /dev/null +++ b/tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'p1.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/__init__.py b/tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/settings.py b/tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/settings.py new file mode 100644 index 0000000000..9655a45337 --- /dev/null +++ b/tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/settings.py @@ -0,0 +1,120 @@ +""" +Django settings for p1 project. + +Generated by 'django-admin startproj' using Django 3.1.5. + +For more information on this file, see +https://docs.djangoproject.com/en/3.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.1/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '%g@gyhl*q@@g(_ab@t^76dao^#b9-v8mw^50)x_bv6wpl+mukj' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'p1.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'p1.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.1/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.1/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.1/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/urls.py b/tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/urls.py new file mode 100644 index 0000000000..83774947c3 --- /dev/null +++ b/tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/urls.py @@ -0,0 +1,21 @@ +"""p1 URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/tests/integration/targets/django_manage/files/base_test/startproj/.keep b/tests/integration/targets/django_manage/files/base_test/startproj/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/integration/targets/django_manage/tasks/main.yaml b/tests/integration/targets/django_manage/tasks/main.yaml new file mode 100644 index 0000000000..ed305ca96b --- /dev/null +++ b/tests/integration/targets/django_manage/tasks/main.yaml @@ -0,0 +1,50 @@ +# Test code for django_manage module +# +# Copyright: (c) 2020, Alexei Znamensky +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +- name: Create temporary test directory + tempfile: + state: directory + suffix: .django_manage + register: tmp_django_root + +- name: Install required library + pip: + name: django + state: present + virtualenv: "{{ tmp_django_root.path }}/venv" + +- name: Copy files + copy: + src: base_test/ + dest: "{{ tmp_django_root.path }}" + mode: preserve + +- name: Create project + command: + chdir: "{{ tmp_django_root.path }}/startproj" + cmd: "{{ tmp_django_root.path }}/venv/bin/django-admin startproject test_django_manage_1" + +- name: Create app + command: + chdir: "{{ tmp_django_root.path }}/startproj" + cmd: "{{ tmp_django_root.path }}/venv/bin/django-admin startapp app1" + +- name: Check + community.general.django_manage: + project_path: "{{ tmp_django_root.path }}/startproj/test_django_manage_1" + command: check + virtualenv: "{{ tmp_django_root.path }}/venv" + +- name: Check simple_project + community.general.django_manage: + project_path: "{{ tmp_django_root.path }}/simple_project/p1" + command: check + virtualenv: "{{ tmp_django_root.path }}/venv" + +- name: Check custom project + community.general.django_manage: + project_path: "{{ tmp_django_root.path }}/1045-single-app-project/single_app_project" + pythonpath: "{{ tmp_django_root.path }}/1045-single-app-project/" + command: check + virtualenv: "{{ tmp_django_root.path }}/venv" diff --git a/tests/sanity/ignore-2.10.txt b/tests/sanity/ignore-2.10.txt index 8ac5e6b445..6f8f385f59 100644 --- a/tests/sanity/ignore-2.10.txt +++ b/tests/sanity/ignore-2.10.txt @@ -376,5 +376,18 @@ plugins/modules/system/xfconf.py validate-modules:parameter-state-invalid-choice plugins/modules/system/xfconf.py validate-modules:return-syntax-error plugins/modules/web_infrastructure/jenkins_plugin.py use-argspec-type-path plugins/modules/web_infrastructure/rundeck_acl_policy.py pylint:blacklisted-name +tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py metaclass-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py future-import-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py pep8:E302 # django generated code +tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py pep8:E305 # django generated code +tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py shebang # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py compile-2.6 # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py compile-2.7 # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py metaclass-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py future-import-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/settings.py metaclass-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/settings.py future-import-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/urls.py metaclass-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/urls.py future-import-boilerplate # django generated code tests/utils/shippable/check_matrix.py replace-urlopen tests/utils/shippable/timing.py shebang diff --git a/tests/sanity/ignore-2.11.txt b/tests/sanity/ignore-2.11.txt index 8ac5e6b445..6f8f385f59 100644 --- a/tests/sanity/ignore-2.11.txt +++ b/tests/sanity/ignore-2.11.txt @@ -376,5 +376,18 @@ plugins/modules/system/xfconf.py validate-modules:parameter-state-invalid-choice plugins/modules/system/xfconf.py validate-modules:return-syntax-error plugins/modules/web_infrastructure/jenkins_plugin.py use-argspec-type-path plugins/modules/web_infrastructure/rundeck_acl_policy.py pylint:blacklisted-name +tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py metaclass-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py future-import-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py pep8:E302 # django generated code +tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py pep8:E305 # django generated code +tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py shebang # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py compile-2.6 # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py compile-2.7 # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py metaclass-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py future-import-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/settings.py metaclass-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/settings.py future-import-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/urls.py metaclass-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/urls.py future-import-boilerplate # django generated code tests/utils/shippable/check_matrix.py replace-urlopen tests/utils/shippable/timing.py shebang diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index 0d3e45c1ba..09195db571 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -324,5 +324,18 @@ plugins/modules/web_infrastructure/jenkins_plugin.py use-argspec-type-path plugins/modules/web_infrastructure/nginx_status_facts.py validate-modules:deprecation-mismatch plugins/modules/web_infrastructure/nginx_status_facts.py validate-modules:invalid-documentation plugins/modules/web_infrastructure/rundeck_acl_policy.py pylint:blacklisted-name +tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py metaclass-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py future-import-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py pep8:E302 # django generated code +tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py pep8:E305 # django generated code +tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/manage.py shebang # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py compile-2.6 # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py compile-2.7 # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py metaclass-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/manage.py future-import-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/settings.py metaclass-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/settings.py future-import-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/urls.py metaclass-boilerplate # django generated code +tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/urls.py future-import-boilerplate # django generated code tests/utils/shippable/check_matrix.py replace-urlopen tests/utils/shippable/timing.py shebang