Make cypress tests run on bitbucket

This commit is contained in:
Daniel Egger 2022-08-26 18:18:32 +02:00
parent b826a44af6
commit 52632708db
8 changed files with 36 additions and 26 deletions

View File

@ -30,9 +30,12 @@ pipelines:
- pip - pip
- cypress - cypress
script: script:
- export IT_SERVE_VUE=false
- export IT_ALLOW_LOCAL_LOGIN=true
- source ./env/bitbucket/prepare_for_test.sh - source ./env/bitbucket/prepare_for_test.sh
- pip install -r server/requirements/requirements-dev.txt - pip install -r server/requirements/requirements-dev.txt
- npm install - npm install
- npm run build
- ./prepare_server_cypress.sh --start-background - ./prepare_server_cypress.sh --start-background
- npm run cypress:ci - npm run cypress:ci
# - npm run build # - npm run build

View File

@ -1,13 +1,13 @@
import {createApp} from 'vue' import {createApp} from 'vue'
import {createPinia} from 'pinia' import {createPinia} from 'pinia'
import {setupI18n} from './i18n' // import {setupI18n} from './i18n'
import App from './App.vue' import App from './App.vue'
import router from './router' import router from './router'
import '../tailwind.css' import '../tailwind.css'
const i18n = setupI18n() // const i18n = setupI18n()
const app = createApp(App) const app = createApp(App)
// todo: define lang setup // todo: define lang setup
@ -15,6 +15,6 @@ const app = createApp(App)
app.use(createPinia()) app.use(createPinia())
app.use(router) app.use(router)
app.use(i18n) // app.use(i18n)
app.mount('#app') app.mount('#app')

View File

@ -13,7 +13,7 @@ module.exports = defineConfig({
toConsole: true, toConsole: true,
}, },
e2e: { e2e: {
experimentalSessionAndOrigin: true, // experimentalSessionAndOrigin: true,
// We've imported your old cypress plugins here. // We've imported your old cypress plugins here.
// You may want to clean this up later by importing these. // You may want to clean this up later by importing these.
setupNodeEvents(on, config) { setupNodeEvents(on, config) {

View File

@ -55,7 +55,14 @@ const _ = Cypress._;
Cypress.Commands.add('manageCommand', (command, preCommand = '') => { Cypress.Commands.add('manageCommand', (command, preCommand = '') => {
const execCommand = `${preCommand} python server/manage.py ${command} --settings=config.settings.test_cypress`; const execCommand = `${preCommand} python server/manage.py ${command} --settings=config.settings.test_cypress`;
console.log(execCommand); console.log(execCommand);
return cy.exec(execCommand); return cy.exec(execCommand, { failOnNonZeroExit: false }).then(result => {
if(result.code) {
throw new Error(`Execution of "${command}" failed
Exit code: ${result.code}
Stdout:\n${result.stdout}
Stderr:\n${result.stderr}`);
}
});
}); });
Cypress.Commands.add('manageShellCommand', (command) => { Cypress.Commands.add('manageShellCommand', (command) => {

View File

@ -4,7 +4,6 @@ import os
os.environ['IT_APP_ENVIRONMENT'] = 'development' os.environ['IT_APP_ENVIRONMENT'] = 'development'
from .base import * # noqa from .base import * # noqa
from .base import env
# https://docs.djangoproject.com/en/dev/ref/settings/#test-runner # https://docs.djangoproject.com/en/dev/ref/settings/#test-runner
TEST_RUNNER = "django.test.runner.DiscoverRunner" TEST_RUNNER = "django.test.runner.DiscoverRunner"

View File

@ -1,4 +1,7 @@
# pylint: disable=unused-wildcard-import,wildcard-import,wrong-import-position # pylint: disable=unused-wildcard-import,wildcard-import,wrong-import-position
import os
os.environ['IT_APP_ENVIRONMENT'] = 'development'
from .base import * # noqa from .base import * # noqa

View File

@ -41,18 +41,14 @@ urlpatterns = [
path('learnpath/', include("vbv_lernwelt.learnpath.urls")), path('learnpath/', include("vbv_lernwelt.learnpath.urls")),
path('api/completion/', include("vbv_lernwelt.completion.urls")), path('api/completion/', include("vbv_lernwelt.completion.urls")),
re_path(r'api/core/me/$', me_user_view, name='me_user_view'), re_path(r'api/core/me/$', me_user_view, name='me_user_view'),
re_path(r'core/login/$', django_view_authentication_exempt(vue_login), name='vue_login'),
re_path(r'core/logout/$', vue_logout, name='vue_logout'), re_path(r'core/logout/$', vue_logout, name='vue_logout'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
if settings.DEBUG: if settings.DEBUG:
# Static file serving when using Gunicorn + Uvicorn for local web socket development # Static file serving when using Gunicorn + Uvicorn for local web socket development
urlpatterns += staticfiles_urlpatterns() urlpatterns += staticfiles_urlpatterns()
if settings.ALLOW_LOCAL_LOGIN:
urlpatterns += [
re_path(r'core/login/$', django_view_authentication_exempt(vue_login), name='vue_login'),
]
# API URLS # API URLS
urlpatterns += [ urlpatterns += [
# API base url # API base url
@ -112,4 +108,3 @@ if settings.DEBUG:
# serve everything else via the vue app # serve everything else via the vue app
urlpatterns += [re_path(r'^.*$', vue_home, name='home')] urlpatterns += [re_path(r'^.*$', vue_home, name='home')]

View File

@ -48,20 +48,23 @@ def vue_home(request):
@api_view(['POST']) @api_view(['POST'])
@ensure_csrf_cookie @ensure_csrf_cookie
def vue_login(request): def vue_login(request):
try: if settings.ALLOW_LOCAL_LOGIN:
username = request.data.get('username') try:
password = request.data.get('password') username = request.data.get('username')
if username and password: password = request.data.get('password')
user = authenticate(request, username=username, password=password) if username and password:
if user: user = authenticate(request, username=username, password=password)
login(request, user) if user:
logger.debug('login successful', username=username, email=user.email, label='login') login(request, user)
return Response(UserSerializer(user).data) logger.debug('login successful', username=username, email=user.email, label='login')
except Exception as e: return Response(UserSerializer(user).data)
logger.exception(e) except Exception as e:
logger.exception(e)
logger.debug('login failed', username=username, label='login') logger.debug('login failed', username=username, label='login')
return Response({'success': False}, status=401) return Response({'success': False}, status=401)
else:
return Response({'success': False, 'message': 'ALLOW_LOCAL_LOGIN=false'}, status=403)
@api_view(['GET']) @api_view(['GET'])