deploy: Add mailpit to test *sent* emails
All checks were successful
/ test (push) Successful in 52s
All checks were successful
/ test (push) Successful in 52s
This commit is contained in:
parent
f7fda52fd0
commit
94c7e31e4b
4 changed files with 127 additions and 35 deletions
|
@ -124,19 +124,12 @@ TEMPLATES = [
|
|||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'core.wsgi.application'
|
||||
ASGI_APPLICATION = 'core.asgi.application'
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
||||
|
||||
if 'test' in sys.argv:
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': ':memory:',
|
||||
}
|
||||
}
|
||||
else:
|
||||
if os.getenv('DB_HOST') is not None:
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
|
@ -149,6 +142,20 @@ else:
|
|||
'charset': 'utf8mb4',
|
||||
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"
|
||||
}
|
||||
},
|
||||
}
|
||||
elif os.getenv('DB_FILE') is not None:
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.getenv('DB_FILE', 'local.db'),
|
||||
}
|
||||
}
|
||||
else:
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': ':memory:',
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,20 +3,15 @@ services:
|
|||
build:
|
||||
context: ../../core
|
||||
dockerfile: ../deploy/dev/Dockerfile.backend
|
||||
command: bash -c 'python manage.py migrate && python manage.py runserver 0.0.0.0:8000'
|
||||
command: bash -c 'python manage.py migrate && python testdata.py && python manage.py runserver 0.0.0.0:8000'
|
||||
environment:
|
||||
- HTTP_HOST=core
|
||||
- DB_HOST=db
|
||||
- DB_PORT=3306
|
||||
- DB_NAME=system3
|
||||
- DB_USER=system3
|
||||
- DB_PASSWORD=system3
|
||||
- DB_FILE=dev.db
|
||||
volumes:
|
||||
- ../../core:/code
|
||||
- ../testdata.py:/code/testdata.py
|
||||
ports:
|
||||
- "8000:8000"
|
||||
depends_on:
|
||||
- db
|
||||
|
||||
frontend:
|
||||
build:
|
||||
|
@ -30,19 +25,4 @@ services:
|
|||
ports:
|
||||
- "8080:8080"
|
||||
depends_on:
|
||||
- core
|
||||
|
||||
db:
|
||||
image: mariadb
|
||||
environment:
|
||||
MARIADB_RANDOM_ROOT_PASSWORD: true
|
||||
MARIADB_DATABASE: system3
|
||||
MARIADB_USER: system3
|
||||
MARIADB_PASSWORD: system3
|
||||
volumes:
|
||||
- mariadb_data:/var/lib/mysql
|
||||
ports:
|
||||
- "3306:3306"
|
||||
|
||||
volumes:
|
||||
mariadb_data:
|
||||
- core
|
88
deploy/testdata.py
Normal file
88
deploy/testdata.py
Normal file
|
@ -0,0 +1,88 @@
|
|||
import os
|
||||
|
||||
|
||||
def setup():
|
||||
from authentication.models import ExtendedUser, EventPermission
|
||||
from inventory.models import Event
|
||||
from django.contrib.auth.models import Permission, Group
|
||||
permissions = ['add_item', 'view_item', 'view_file', 'delete_item', 'change_item']
|
||||
if not ExtendedUser.objects.filter(username='admin').exists():
|
||||
admin = ExtendedUser.objects.create_superuser('admin', 'admin@example.com', 'admin')
|
||||
admin.set_password('admin')
|
||||
admin.user_permissions.add(*Permission.objects.all())
|
||||
admin.save()
|
||||
|
||||
if not ExtendedUser.objects.filter(username='testuser').exists():
|
||||
testuser = ExtendedUser.objects.create_user('testuser', 'testuser@example.com', 'testuser')
|
||||
testuser.set_password('testuser')
|
||||
testuser.user_permissions.add(*Permission.objects.all())
|
||||
testuser.save()
|
||||
|
||||
team = Group.objects.get(name='Team')
|
||||
team.permissions.add(
|
||||
*Permission.objects.all()
|
||||
)
|
||||
|
||||
if not ExtendedUser.objects.filter(username='testuser2').exists():
|
||||
testuser2 = ExtendedUser.objects.create_user('testuser2', 'testuser2@example.com', 'testuser2')
|
||||
testuser2.set_password('testuser2')
|
||||
testuser2.groups.add(team)
|
||||
testuser2.save()
|
||||
|
||||
event1 = Event.objects.get_or_create(id=1, name='first test event', slug='TEST1',
|
||||
start='2023-12-18 00:00:00.000000', end='2023-12-27 00:00:00.000000',
|
||||
pre_start='2023-12-31 00:00:00.000000', post_end='2024-01-04 00:00:00.000000')[
|
||||
0]
|
||||
|
||||
event2 = Event.objects.get_or_create(id=2, name='second test event', slug='TEST2',
|
||||
start='2024-12-18 00:00:00.000000', end='2024-12-27 00:00:00.000000',
|
||||
pre_start='2024-12-31 00:00:00.000000', post_end='2025-01-04 00:00:00.000000')[
|
||||
0]
|
||||
|
||||
# for permission in permissions:
|
||||
# EventPermission.objects.create(event=event_37c3, user=foo,
|
||||
# permission=Permission.objects.get(codename=permission))
|
||||
|
||||
from tickets.models import IssueThread
|
||||
|
||||
from mail.models import Email
|
||||
|
||||
issue_thread = IssueThread.objects.get_or_create(
|
||||
id=1,
|
||||
name="test",
|
||||
event=Event.objects.get(slug='TEST1')
|
||||
)[0]
|
||||
mail1 = Email.objects.get_or_create(
|
||||
id=1,
|
||||
subject='test subject',
|
||||
body='test',
|
||||
sender='test1@test',
|
||||
recipient='test2@test',
|
||||
issue_thread=issue_thread,
|
||||
)[0]
|
||||
mail1_reply = Email.objects.get_or_create(
|
||||
id=2,
|
||||
subject='Message received',
|
||||
body='Thank you for your message.',
|
||||
sender='test2@test',
|
||||
recipient='test1@test',
|
||||
in_reply_to=mail1.reference,
|
||||
issue_thread=issue_thread,
|
||||
)[0]
|
||||
|
||||
|
||||
def main():
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
|
||||
import django
|
||||
|
||||
django.setup()
|
||||
|
||||
from django.core.management import call_command
|
||||
call_command('migrate')
|
||||
|
||||
setup()
|
||||
print('testdata initialised')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -20,7 +20,7 @@ services:
|
|||
build:
|
||||
context: ../../core
|
||||
dockerfile: ../deploy/testing/Dockerfile.backend
|
||||
command: bash -c 'python manage.py migrate && python /code/server.py'
|
||||
command: bash -c 'python manage.py migrate && python testdata.py && python /code/server.py'
|
||||
environment:
|
||||
- HTTP_HOST=core
|
||||
- REDIS_HOST=redis
|
||||
|
@ -29,13 +29,16 @@ services:
|
|||
- DB_NAME=system3
|
||||
- DB_USER=system3
|
||||
- DB_PASSWORD=system3
|
||||
- MAIL_DOMAIN=mail:1025
|
||||
volumes:
|
||||
- ../../core:/code
|
||||
- ../testdata.py:/code/testdata.py
|
||||
ports:
|
||||
- "8000:8000"
|
||||
depends_on:
|
||||
- db
|
||||
- redis
|
||||
- mail
|
||||
|
||||
frontend:
|
||||
build:
|
||||
|
@ -51,5 +54,19 @@ services:
|
|||
depends_on:
|
||||
- core
|
||||
|
||||
mail:
|
||||
image: docker.io/axllent/mailpit
|
||||
volumes:
|
||||
- mailpit_data:/data
|
||||
ports:
|
||||
- 8025:8025
|
||||
- 1025:1025
|
||||
environment:
|
||||
MP_MAX_MESSAGES: 5000
|
||||
MP_DATABASE: /data/mailpit.db
|
||||
MP_SMTP_AUTH_ACCEPT_ANY: 1
|
||||
MP_SMTP_AUTH_ALLOW_INSECURE: 1
|
||||
|
||||
volumes:
|
||||
mariadb_data:
|
||||
mariadb_data:
|
||||
mailpit_data:
|
Loading…
Add table
Reference in a new issue