forked from axnsan12/drf-yasg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create testproj default user in data migration
- Loading branch information
Showing
8 changed files
with
39 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
release: python testproj/manage.py migrate && python testproj/manage.py shell -c "import createsuperuser" | ||
release: python testproj/manage.py migrate | ||
web: gunicorn --chdir testproj testproj.wsgi --log-file - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Generated by Django 2.1.3 on 2018-12-19 08:07 | ||
import sys | ||
|
||
from django.conf import settings | ||
from django.contrib.auth.hashers import make_password | ||
from django.db import migrations, IntegrityError | ||
|
||
|
||
def add_default_user(apps, schema_editor): | ||
username = 'admin' | ||
email = '[email protected]' | ||
password = 'passwordadmin' | ||
User = apps.get_model(settings.AUTH_USER_MODEL) | ||
|
||
try: | ||
admin = User( | ||
username=username, | ||
email=email, | ||
password=make_password(password), | ||
is_superuser=True, | ||
is_staff=True | ||
) | ||
admin.save() | ||
except IntegrityError: | ||
sys.stdout.write(" User '%s <%s>' already exists..." % (username, email)) | ||
else: | ||
sys.stdout.write(" Created superuser '%s <%s>' with password '%s'!" % (username, email, password)) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(add_default_user) | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,16 +6,13 @@ | |
from collections import OrderedDict | ||
|
||
import pytest | ||
from django.contrib.auth.models import User | ||
|
||
from drf_yasg import openapi | ||
from drf_yasg.codecs import yaml_sane_load | ||
from drf_yasg.generators import OpenAPISchemaGenerator | ||
|
||
|
||
def test_reference_schema(call_generate_swagger, db, reference_schema): | ||
User.objects.create_superuser('admin', '[email protected]', 'blabla') | ||
|
||
output = call_generate_swagger(format='yaml', api_url='http://test.local:8002/', user='admin') | ||
output_schema = yaml_sane_load(output) | ||
assert output_schema == reference_schema | ||
|