Run black over entire codebase

This commit is contained in:
2019-08-19 23:37:32 +02:00
parent fc7a9621a7
commit e3e3f6d5db
112 changed files with 8240 additions and 3214 deletions

View File

@ -23,110 +23,113 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv(
'SECRET_KEY',
'r3vwfrawmnwh3kzp4(p#sg0!y%!jg80k06(j@p!y(q^h@5y*lw'
)
"SECRET_KEY", "r3vwfrawmnwh3kzp4(p#sg0!y%!jg80k06(j@p!y(q^h@5y*lw"
)
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = bool(int(os.getenv('DEBUG', False)))
DEBUG = bool(int(os.getenv("DEBUG", False)))
if DEBUG:
ALLOWED_HOSTS = ['*']
ALLOWED_HOSTS = ["*"]
else:
ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', 'localhost').split()
ALLOWED_HOSTS = os.getenv("ALLOWED_HOSTS", "localhost").split()
# Application definition
INSTALLED_APPS = [
'apps.contact',
'apps.files',
'apps.map',
'apps.profiles',
'avatar',
'bootstrap3',
'cas_server',
'compressor',
'crispy_forms',
'dal',
'dal_select2',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.flatpages',
'django.contrib.gis',
'django.contrib.humanize',
'django.contrib.messages',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
'django_extensions',
'envelope',
'leaflet',
'raven.contrib.django.raven_compat',
'registration',
'rest_framework',
'rest_framework_gis',
'storages',
'whitenoise.runserver_nostatic',
'anymail',
"apps.contact",
"apps.files",
"apps.map",
"apps.profiles",
"avatar",
"bootstrap3",
"cas_server",
"compressor",
"crispy_forms",
"dal",
"dal_select2",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.flatpages",
"django.contrib.gis",
"django.contrib.humanize",
"django.contrib.messages",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.staticfiles",
"django_extensions",
"envelope",
"leaflet",
"raven.contrib.django.raven_compat",
"registration",
"rest_framework",
"rest_framework_gis",
"storages",
"whitenoise.runserver_nostatic",
"anymail",
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.locale.LocaleMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django.contrib.flatpages.middleware.FlatpageFallbackMiddleware",
]
ROOT_URLCONF = 'ojusomap.urls'
ROOT_URLCONF = "ojusomap.urls"
SITE_ID = 1
SITE_URL = 'https://map.ojuso.org'
SITE_URL = "https://map.ojuso.org"
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'ojusomap/templates/')],
'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',
],
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(BASE_DIR, "ojusomap/templates/")],
"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 = 'ojusomap.wsgi.application'
WSGI_APPLICATION = "ojusomap.wsgi.application"
# E-Mail
# https://docs.djangoproject.com/en/1.11/topics/email/
ADMINS = [('Autonomic','autonomic-coop@posteo.net')]
DEFAULT_FROM_EMAIL = os.getenv('DEFAULT_FROM_EMAIL', 'webmaster@localhost')
EMAIL_HOST = os.getenv('EMAIL_HOST', 'localhost')
EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD')
EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER')
EMAIL_PORT = os.getenv('EMAIL_PORT', 25)
EMAIL_USE_TLS = bool(int(os.getenv('EMAIL_USE_TLS', False)))
ADMINS = [("Autonomic", "autonomic-coop@posteo.net")]
DEFAULT_FROM_EMAIL = os.getenv("DEFAULT_FROM_EMAIL", "webmaster@localhost")
EMAIL_HOST = os.getenv("EMAIL_HOST", "localhost")
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD")
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER")
EMAIL_PORT = os.getenv("EMAIL_PORT", 25)
EMAIL_USE_TLS = bool(int(os.getenv("EMAIL_USE_TLS", False)))
EMAIL_SUBJECT_PREFIX = "Ojuso Platform"
SERVER_EMAIL = os.getenv('SERVER_EMAIL', 'root@localhost')
SERVER_EMAIL = os.getenv("SERVER_EMAIL", "root@localhost")
DATABASE_EMAIL = os.getenv('DATABASE_EMAIL', 'autonomic-coop@posteo.net')
DATABASE_EMAIL = os.getenv("DATABASE_EMAIL", "autonomic-coop@posteo.net")
EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend"
ANYMAIL = {
"MAILGUN_API_KEY": os.getenv("MAILGUN_API_KEY", "key-e82f77942478d2892b4faf51fc88ce45"),
"MAILGUN_SENDER_DOMAIN": os.getenv("MAILGUN_SENDER_DOMAIN", "sandbox35a5ee2a4dfc4f3aaf76d4672e4497ae.mailgun.org"),
"MAILGUN_API_KEY": os.getenv(
"MAILGUN_API_KEY", "key-e82f77942478d2892b4faf51fc88ce45"
),
"MAILGUN_SENDER_DOMAIN": os.getenv(
"MAILGUN_SENDER_DOMAIN", "sandbox35a5ee2a4dfc4f3aaf76d4672e4497ae.mailgun.org"
),
}
@ -134,13 +137,13 @@ ANYMAIL = {
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'HOST': os.getenv('DATABASE_HOST', 'localhost'),
'PORT': os.getenv('DATABASE_PORT', '5432'),
'NAME': os.getenv('DATABASE_NAME', 'postgres'),
'USER': os.getenv('DATABASE_USER', 'postgres'),
'PASSWORD': os.getenv('DATABASE_PASSWORD', 'postgres'),
"default": {
"ENGINE": "django.contrib.gis.db.backends.postgis",
"HOST": os.getenv("DATABASE_HOST", "localhost"),
"PORT": os.getenv("DATABASE_PORT", "5432"),
"NAME": os.getenv("DATABASE_NAME", "postgres"),
"USER": os.getenv("DATABASE_USER", "postgres"),
"PASSWORD": os.getenv("DATABASE_PASSWORD", "postgres"),
}
}
@ -149,17 +152,11 @@ DATABASES = {
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',
"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"},
]
# Registration (Redux)
@ -168,9 +165,9 @@ ACCOUNT_ACTIVATION_DAYS = 3
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'en-gb'
LANGUAGE_CODE = "en-gb"
TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"
USE_I18N = True
@ -179,19 +176,17 @@ USE_L10N = True
USE_TZ = True
LANGUAGES = [
('en-gb', _('English (British)')),
('fr', _('French')),
('es', _('Spanish')),
("en-gb", _("English (British)")),
("fr", _("French")),
("es", _("Spanish")),
]
LOCALE_PATHS = [
os.path.join(BASE_DIR, 'support/locale')
]
LOCALE_PATHS = [os.path.join(BASE_DIR, "support/locale")]
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
AWS_S3_ENDPOINT_URL = "https://ojuso-media.nyc3.digitaloceanspaces.com"
if DEBUG:
@ -205,35 +200,31 @@ AWS_ACCESS_KEY_ID = "RUZTFVKPCNJIWCVUVJFW"
AWS_SECRET_ACCESS_KEY = "pTZAnmtvGzFBdI/jwtwRoFW5eK7eJ8FLFxr1/Jb+Yq4"
AWS_DEFAULT_ACL = None
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
STATIC_URL = os.getenv("STATIC_URL", '/static/')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "assets")
]
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
STATIC_URL = os.getenv("STATIC_URL", "/static/")
STATICFILES_DIRS = [os.path.join(BASE_DIR, "assets")]
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
]
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
MEDIA_URL = os.getenv("MEDIA_URL", "https://ojuso-media.nyc3.digitaloceanspaces.com/ojuso-media/")
MEDIA_ROOT = os.path.join(BASE_DIR, "media/")
MEDIA_URL = os.getenv(
"MEDIA_URL", "https://ojuso-media.nyc3.digitaloceanspaces.com/ojuso-media/"
)
# Cache
# https://docs.djangoproject.com/en/1.11/topics/cache/
if DEBUG:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}
CACHES = {"default": {"BACKEND": "django.core.cache.backends.dummy.DummyCache"}}
else:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': 'cache:11211',
"default": {
"BACKEND": "django.core.cache.backends.memcached.MemcachedCache",
"LOCATION": "cache:11211",
}
}
@ -242,111 +233,94 @@ else:
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
"DEFAULT_PERMISSION_CLASSES": [
"rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly"
],
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
),
'DEFAULT_PARSER_CLASSES': (
'rest_framework.parsers.JSONParser',
)
"DEFAULT_RENDERER_CLASSES": ("rest_framework.renderers.JSONRenderer",),
"DEFAULT_PARSER_CLASSES": ("rest_framework.parsers.JSONParser",),
}
# Django Crispy Forms
# http://django-crispy-forms.readthedocs.io/en/latest/
CRISPY_TEMPLATE_PACK = 'bootstrap3'
CRISPY_TEMPLATE_PACK = "bootstrap3"
# Django-Leaflet
# https://django-leaflet.readthedocs.io/en/latest/
LEAFLET_CONFIG = {
'MIN_ZOOM': 2,
'MAX_ZOOM': 16,
'TILES': [
('Default', 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {
'maxZoom': 17,
'attribution': 'Map data: &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, <a href="http://viewfinderpanoramas.org">SRTM</a> | Map style: &copy; <a href="https://opentopomap.org">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)'
}),
('English', 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png', {
'attribution': '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> &copy; <a href="https://carto.com/attributions">CARTO</a>',
'subdomains': 'abcd',
'maxZoom': 19
}),
('Français', 'http://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', {}),
"MIN_ZOOM": 2,
"MAX_ZOOM": 16,
"TILES": [
(
"Default",
"https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png",
{
"maxZoom": 17,
"attribution": 'Map data: &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, <a href="http://viewfinderpanoramas.org">SRTM</a> | Map style: &copy; <a href="https://opentopomap.org">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)',
},
),
(
"English",
"https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png",
{
"attribution": '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> &copy; <a href="https://carto.com/attributions">CARTO</a>',
"subdomains": "abcd",
"maxZoom": 19,
},
),
("Français", "http://a.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png", {}),
],
'PLUGINS': {
'forms': {
'auto-include': True
}
},
"PLUGINS": {"forms": {"auto-include": True}},
}
# Error reporting & logging
RAVEN_CONFIG = {
'dsn': os.getenv("RAVEN_DSN", ''),
"dsn": os.getenv("RAVEN_DSN", ""),
# If you are using git, you can also automatically configure the
# release based on the git info.
'release': raven.fetch_git_sha(os.path.dirname(os.pardir)),
"release": raven.fetch_git_sha(os.path.dirname(os.pardir)),
}
LOGGING = {
'version': 1,
'disable_existing_loggers': not DEBUG,
'root': {
'level': 'WARNING',
'handlers': ['sentry'],
},
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
},
'handlers': {
'null': {
'level': 'DEBUG',
'class': 'logging.NullHandler',
},
'sentry': {
'level': 'ERROR',
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
"version": 1,
"disable_existing_loggers": not DEBUG,
"root": {"level": "WARNING", "handlers": ["sentry"]},
"formatters": {
"verbose": {
"format": "%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s"
}
},
'loggers': {
"handlers": {
"null": {"level": "DEBUG", "class": "logging.NullHandler"},
"sentry": {
"level": "ERROR",
"class": "raven.contrib.django.raven_compat.handlers.SentryHandler",
},
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "verbose",
},
},
"loggers": {
# Silence SuspiciousOperation.DisallowedHost exception ('Invalid
# HTTP_HOST' header messages). Set the handler to 'null' so we don't
# get those annoying emails.
# https://www.calazan.com/how-to-disable-the-invalid-http_host-header-emails-in-django/
'django.security.DisallowedHost': {
'handlers': ['null'],
'propagate': False,
"django.security.DisallowedHost": {"handlers": ["null"], "propagate": False},
"django.db.backends": {
"level": "ERROR",
"handlers": ["console"],
"propagate": False,
},
'django.db.backends': {
'level': 'ERROR',
'handlers': ['console'],
'propagate': False,
},
'raven': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
'sentry.errors': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
'apps.map': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
"raven": {"level": "DEBUG", "handlers": ["console"], "propagate": False},
"sentry.errors": {
"level": "DEBUG",
"handlers": ["console"],
"propagate": False,
},
"apps.map": {"level": "DEBUG", "handlers": ["console"], "propagate": False},
},
}
@ -356,9 +330,8 @@ AVATAR_CLEANUP_DELETED = True
# Messages
from django.contrib.messages import constants as messages
MESSAGE_TAGS = {
messages.ERROR: 'danger'
}
MESSAGE_TAGS = {messages.ERROR: "danger"}
# Feature flags
FF_CAN_EDIT = False

View File

@ -8,7 +8,8 @@ from selenium import webdriver
from selenium.common import exceptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support.expected_conditions import (
staleness_of, visibility_of_element_located
staleness_of,
visibility_of_element_located,
)
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.select import Select
@ -29,11 +30,11 @@ class SeleniumTest(LiveServerTestCase):
# profile.set_preference("dom.forms.number", False)
# cls.sl = webdriver.Firefox(profile)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument("--no-sandbox")
# comment out this next line in order to see the tests running in a browser.
# But be sure to put it back before comitting, or gitlab CI will fail.
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
cls.sl = webdriver.Chrome(options=chrome_options)
cls.sl.implicitly_wait(TIMEOUT)
super(SeleniumTest, cls).setUpClass()
@ -44,23 +45,22 @@ class SeleniumTest(LiveServerTestCase):
super(SeleniumTest, cls).tearDownClass()
def setUp(self):
self.user = User.objects.create_superuser(username='test', password='test',
email='test@example.com')
self.user = User.objects.create_superuser(
username="test", password="test", email="test@example.com"
)
def _open(self, url):
self.sl.get('%s%s' % (self.live_server_url, url))
self.sl.get("%s%s" % (self.live_server_url, url))
@contextmanager
def wait_for_page_load(self, timeout=30):
old_page = self.sl.find_element_by_tag_name('html')
old_page = self.sl.find_element_by_tag_name("html")
yield
WebDriverWait(self.sl, timeout).until(
staleness_of(old_page)
)
WebDriverWait(self.sl, timeout).until(staleness_of(old_page))
def _select_option(self, select, option, optgroup=''):
def _select_option(self, select, option, optgroup=""):
if optgroup:
optgroup = '/optgroup'
optgroup = "/optgroup"
self.sl.find_element_by_xpath(
"//select[@id='%s']%s/option[text()='%s']" % (select, optgroup, option)
).click()
@ -70,115 +70,146 @@ class MapTest(SeleniumTest):
def setUp(self):
self.case_study = CaseStudy(
approved=True,
entry_name='test',
entry_name="test",
location='{"type": "Point", "coordinates": [0, 0]}',
sector_of_economy='RN',
positive_or_negative='P',
country='NZ',
area_of_land='100',
land_ownership='PRI',
location_context='URB',
describe_ecosystem='test',
project_status='EXSTNG',
synopsis='test',
full_description='test',
media_coverage_mainstream='test',
media_coverage_independent='test'
sector_of_economy="RN",
positive_or_negative="P",
country="NZ",
area_of_land="100",
land_ownership="PRI",
location_context="URB",
describe_ecosystem="test",
project_status="EXSTNG",
synopsis="test",
full_description="test",
media_coverage_mainstream="test",
media_coverage_independent="test",
)
self.case_study.save()
def login(self):
self.user = User.objects.create_superuser(username='test', password='test', email='test@example.com');
self.sl.find_element_by_id('id_username').send_keys('test');
self.sl.find_element_by_id('id_password').send_keys('test');
self.user = User.objects.create_superuser(
username="test", password="test", email="test@example.com"
)
self.sl.find_element_by_id("id_username").send_keys("test")
self.sl.find_element_by_id("id_password").send_keys("test")
self.sl.find_element_by_css_selector('input[type="submit"]').click()
def place_marker(self):
# click the zoom out button enough to bring up the thing to draw marker then use it.
# the headless browser needs time between each click or it does not show the draw-marker control.
for i in range(0, 15):
self.sl.find_element_by_class_name('leaflet-control-zoom-in').click()
time.sleep(0.2)
self.sl.find_element_by_class_name('leaflet-draw-draw-marker').click()
self.sl.find_element_by_id('id_location-map').click()
self.sl.find_element_by_class_name("leaflet-control-zoom-in").click()
time.sleep(0.2)
self.sl.find_element_by_class_name("leaflet-draw-draw-marker").click()
self.sl.find_element_by_id("id_location-map").click()
def test_form_will_show_error(self):
self._open('/en-gb/case-study/create/long');
self.login();
self._open("/en-gb/case-study/create/long")
self.login()
# navigate to the last tab, where the submit button is
self.sl.find_element_by_css_selector('a[href="#uploads"]').click()
# click submit without filling in any fields
self.sl.find_element_by_id('submit-id-submit').click()
error_message = self.sl.find_element_by_class_name('has-error')
self.sl.find_element_by_id("submit-id-submit").click()
error_message = self.sl.find_element_by_class_name("has-error")
self.assertTrue(error_message.is_displayed())
def test_short_form_will_submit(self):
self._open('/en-gb/case-study/create/short');
self._open("/en-gb/case-study/create/short")
self.login()
self.place_marker()
self.sl.find_element_by_id('id_entry_name').send_keys('Short Entry');
Select(self.sl.find_element_by_id('id_country')).select_by_visible_text('Albania');
self.sl.find_element_by_id('id_area_of_land').send_keys('123');
Select(self.sl.find_element_by_id('id_land_ownership')).select_by_visible_text('Private land');
Select(self.sl.find_element_by_id('id_location_context')).select_by_visible_text('Urban');
self.sl.find_element_by_id('id_describe_ecosystem').send_keys('test');
Select(self.sl.find_element_by_id('id_project_status')).select_by_visible_text('In planning and design');
self.sl.find_element_by_css_selector('[name=sector_of_economy][value=ST]').click()
self.sl.find_element_by_id('id_synopsis').send_keys('test');
self.sl.find_element_by_id('id_full_description').send_keys('test');
Select(self.sl.find_element_by_id('id_positive_or_negative')).select_by_visible_text('There is/was an organising process in favour of the project');
self.sl.find_element_by_id("id_entry_name").send_keys("Short Entry")
Select(self.sl.find_element_by_id("id_country")).select_by_visible_text(
"Albania"
)
self.sl.find_element_by_id("id_area_of_land").send_keys("123")
Select(self.sl.find_element_by_id("id_land_ownership")).select_by_visible_text(
"Private land"
)
Select(
self.sl.find_element_by_id("id_location_context")
).select_by_visible_text("Urban")
self.sl.find_element_by_id("id_describe_ecosystem").send_keys("test")
Select(self.sl.find_element_by_id("id_project_status")).select_by_visible_text(
"In planning and design"
)
self.sl.find_element_by_css_selector(
"[name=sector_of_economy][value=ST]"
).click()
self.sl.find_element_by_id("id_synopsis").send_keys("test")
self.sl.find_element_by_id("id_full_description").send_keys("test")
Select(
self.sl.find_element_by_id("id_positive_or_negative")
).select_by_visible_text(
"There is/was an organising process in favour of the project"
)
# you can submit the form on any field. Using this one because the submit button sometimes isn't visible
self.sl.find_element_by_id('id_area_of_land').submit();
self.sl.find_element_by_id("id_area_of_land").submit()
self.assertTrue("Thanks!" in self.sl.page_source, "Success message not shown")
self._open('/admin/map/casestudy/');
self._open("/admin/map/casestudy/")
self.assertTrue("Short Entry" in self.sl.page_source, "Case study not saved")
def test_long_form_will_submit(self):
self._open('/en-gb/case-study/create/long');
self._open("/en-gb/case-study/create/long")
self.login()
self.place_marker()
self.sl.find_element_by_id('id_entry_name').send_keys('Long Entry');
Select(self.sl.find_element_by_id('id_country')).select_by_visible_text('Albania');
self.sl.find_element_by_id('id_area_of_land').send_keys('123');
Select(self.sl.find_element_by_id('id_land_ownership')).select_by_visible_text('Private land');
Select(self.sl.find_element_by_id('id_location_context')).select_by_visible_text('Urban');
self.sl.find_element_by_id('id_describe_ecosystem').send_keys('test');
Select(self.sl.find_element_by_id('id_project_status')).select_by_visible_text('In planning and design');
self.sl.find_element_by_id('id_synopsis').send_keys('test');
self.sl.find_element_by_id('id_full_description').send_keys('test');
self.sl.find_element_by_id('id_project_owners').send_keys('test');
self.sl.find_element_by_id('id_shareholders').send_keys('test');
self.sl.find_element_by_css_selector('a[href="#technical-and-economic-analysis"]').click()
self.sl.find_element_by_css_selector('[name=sector_of_economy][value=ST]').click()
self.sl.find_element_by_css_selector('a[href="#socio-environmental-analysis"]').click()
Select(self.sl.find_element_by_id('id_positive_or_negative')).select_by_visible_text('There is/was an organising process in favour of the project');
self.sl.find_element_by_id("id_entry_name").send_keys("Long Entry")
Select(self.sl.find_element_by_id("id_country")).select_by_visible_text(
"Albania"
)
self.sl.find_element_by_id("id_area_of_land").send_keys("123")
Select(self.sl.find_element_by_id("id_land_ownership")).select_by_visible_text(
"Private land"
)
Select(
self.sl.find_element_by_id("id_location_context")
).select_by_visible_text("Urban")
self.sl.find_element_by_id("id_describe_ecosystem").send_keys("test")
Select(self.sl.find_element_by_id("id_project_status")).select_by_visible_text(
"In planning and design"
)
self.sl.find_element_by_id("id_synopsis").send_keys("test")
self.sl.find_element_by_id("id_full_description").send_keys("test")
self.sl.find_element_by_id("id_project_owners").send_keys("test")
self.sl.find_element_by_id("id_shareholders").send_keys("test")
self.sl.find_element_by_css_selector(
'a[href="#technical-and-economic-analysis"]'
).click()
self.sl.find_element_by_css_selector(
"[name=sector_of_economy][value=ST]"
).click()
self.sl.find_element_by_css_selector(
'a[href="#socio-environmental-analysis"]'
).click()
Select(
self.sl.find_element_by_id("id_positive_or_negative")
).select_by_visible_text(
"There is/was an organising process in favour of the project"
)
self.sl.find_element_by_css_selector('a[href="#uploads"]').click()
# you can submit the form on any field. Using this one because the submit button sometimes isn't visible
self.sl.find_element_by_id('id_name_of_territory_or_area').submit();
self.sl.find_element_by_id("id_name_of_territory_or_area").submit()
self.assertTrue("Thanks!" in self.sl.page_source, "Success message not shown")
self._open('/admin/map/casestudy/');
self._open("/admin/map/casestudy/")
self.assertTrue("Long Entry" in self.sl.page_source, "Case study not saved")
def test_map(self):
self._open('/')
self._open("/")
WebDriverWait(self.sl, 5).until(
visibility_of_element_located(
(By.CSS_SELECTOR, '.hello--hide')
)
visibility_of_element_located((By.CSS_SELECTOR, ".hello--hide"))
)
self.sl.find_element_by_css_selector('.hello--hide').click()
self.sl.find_element_by_css_selector(".hello--hide").click()
WebDriverWait(self.sl, 5).until(
visibility_of_element_located(
(By.CSS_SELECTOR, '.leaflet-marker-icon')
)
visibility_of_element_located((By.CSS_SELECTOR, ".leaflet-marker-icon"))
)
self.sl.find_element_by_css_selector('.leaflet-marker-icon').click()
self.sl.find_element_by_css_selector(".leaflet-marker-icon").click()
details_link = self.sl.find_element_by_css_selector('.leaflet-popup-content a.btn')
details_link = self.sl.find_element_by_css_selector(
".leaflet-popup-content a.btn"
)
self.assertTrue(details_link.is_displayed())
details_link.click()
self.assertTrue(self.sl.current_url.endswith('case-study/test'))
self.assertTrue(self.sl.current_url.endswith("case-study/test"))

View File

@ -12,17 +12,17 @@ from .views import LanguageDropdownView
urlpatterns = [
url(r'^api/', include("apps.api.urls")),
url(r'^admin/', admin.site.urls),
url(r'^avatar/', include('avatar.urls')),
url(r'^cas/', include('cas_server.urls', namespace='cas_server')),
url(r'^files/', include('apps.files.urls')),
url(r'^set_language/(?P<language>[^/]+)$', LanguageDropdownView.as_view()),
url(r"^api/", include("apps.api.urls")),
url(r"^admin/", admin.site.urls),
url(r"^avatar/", include("avatar.urls")),
url(r"^cas/", include("cas_server.urls", namespace="cas_server")),
url(r"^files/", include("apps.files.urls")),
url(r"^set_language/(?P<language>[^/]+)$", LanguageDropdownView.as_view()),
# url(r'^contact/', include('apps.contact.urls'), name="contact"),
]
urlpatterns += i18n_patterns(
url(r'^accounts/profile/', include('apps.profiles.urls', namespace="profile")),
url(r'^accounts/', include('registration.backends.default.urls')),
url(r'', include('apps.map.urls'), name="map"),
url(r"^accounts/profile/", include("apps.profiles.urls", namespace="profile")),
url(r"^accounts/", include("registration.backends.default.urls")),
url(r"", include("apps.map.urls"), name="map"),
)

View File

@ -5,9 +5,9 @@ from django.views.generic import View
class LanguageDropdownView(View):
def get(self, request, *args, **kwargs):
lang_code = kwargs.get('language', None)
lang_code = kwargs.get("language", None)
if lang_code is not None and translation.check_for_language(lang_code):
request.POST = request.POST.copy()
request.POST['language'] = lang_code
request.method = 'POST'
request.POST["language"] = lang_code
request.method = "POST"
return set_language(request)