Skip to content

Commit

Permalink
Fixed user management in fixture and migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
osherdp committed Dec 22, 2017
1 parent 8ee1cf6 commit eb77568
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
27 changes: 20 additions & 7 deletions docs/intro/using_resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ First, let's initialize the database with the following Django commands:
Applying sessions.0001_initial... OK
The first command creates a migrations file, that orders changing the database
schemas or contents. The second commands changes the database according to
schemas or contents. The second command changes the database according to
those orders. If the database does not already exist, it creates it.

Let's run the Rotest server, using the ``rotest-server`` command:
Expand All @@ -184,19 +184,32 @@ Let's run the Rotest server, using the ``rotest-server`` command:
A few explanations about this command:

* If given the ``--run-django-server`` option, it runs the Django admin panel
as well. Go ahead at navigate in your browser to
`<http://127.0.0.1:8080/admin>`_, and use the following
credentials: ``username="rotest"``, ``password="rotest"``.
as well. We'll access it in the next section.

* If given the ``--django-port <port>`` option, it uses this value as the
port of the Django admin panel. If not given, it defaults to ``8000``.

* If given the ``--daemon`` or ``-D`` option, the program runs in the
background.

To sum this up, add a Calculator resource. Just enter the Django admin panel,
add a resource with the name ``calc`` for instance, and a local IP address like
``127.0.0.1``:
Adding a Resource on Django Admin Panel
=======================================

To sum this up, let's add a Calculator resource. Run the `createsuperuser`
command to get access to the admin panel:

.. code-block:: console
$ python manage.py createsuperuser
Username (leave blank to use 'user'): <choose a user in here>
Email address: <choose your email address>
Password: <type in your password>
Password (again): <type password again>
Superuser created successfully.
Now, Just enter the Django admin panel (via `<http://127.0.0.1:8080/admin>`_),
access it using the above credentials, and add a resource with the name
``calc`` and a local IP address like ``127.0.0.1``:

.. figure:: adding_resource.png
:target: ../_images/adding_resource.png
Expand Down
11 changes: 6 additions & 5 deletions src/rotest/common/django_utils/fixtures/resource_ut.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[{"pk": 1, "model": "auth.group", "fields": {"name": "QA", "permissions": []}},
{"pk": 2, "model": "auth.group", "fields": {"name": "GROUP1", "permissions": []}},
{"pk": 3, "model": "auth.group", "fields": {"name": "GROUP2", "permissions": []}},
{"pk": 1, "model": "management.resourcedata", "fields": {"reserved": "", "name": "available_resource1", "dirty": false, "owner": "", "group": 1}},
{"pk": 1, "model": "auth.user", "fields": {"username": "localhost", "first_name": "", "last_name": "", "is_active": true, "is_superuser": true, "is_staff": true, "last_login": "2015-09-21T10:29:58", "groups": [["QA"]], "user_permissions": [], "password": "pbkdf2_sha256$12000$v4L5uJ9LnwLW$cmEJ+98ncYMOJunbGyRkUFvGZe8fg1xSQZDrkI2wuys=", "email": "t@d.com", "date_joined": "2015-09-21T10:29:58"}},
{"pk": 1, "model": "management.resourcedata", "fields": {"reserved": "", "name": "available_resource1", "dirty": false, "owner": "", "group": 1}},
{"pk": 1, "model": "management.demoresourcedata", "fields": {"initialization_flag": false, "reset_flag": false, "version": 1, "mode": 0, "validate_flag": null, "ip_address": "1.1.1.1"}},
{"pk": 2, "model": "management.resourcedata", "fields": {"reserved": "", "name": "available_resource2", "dirty": false, "owner": "", "group": 1}},
{"pk": 2, "model": "management.demoresourcedata", "fields": {"initialization_flag": false, "reset_flag": false, "version": 2, "mode": 0, "validate_flag": null, "ip_address": "1.1.1.1"}},
Expand All @@ -11,11 +12,11 @@
{"pk": 4, "model": "management.demoresourcedata", "fields": {"initialization_flag": false, "reset_flag": false, "version": 4, "mode": 0, "validate_flag": null, "ip_address": "1.1.1.1"}},
{"pk": 5, "model": "management.resourcedata", "fields": {"reserved": "", "name": "complex_resource1", "dirty": false, "owner": "", "group": 1}},
{"pk": 5, "model": "management.democomplexresourcedata", "fields": {"demo2": 2, "validate_flag": null, "demo1": 1, "reset_flag": false, "initialization_flag": false}},
{"pk": 6, "model": "management.resourcedata", "fields": {"reserved": "", "name": "fail_initialize_resource", "dirty": false, "owner": "", "group": 1}},
{"pk": 6, "model": "management.resourcedata", "fields": {"reserved": "", "name": "fail_initialize_resource", "dirty": false, "owner": "", "group": 1}},
{"pk": 6, "model": "management.demoresourcedata", "fields": {"fails_on_initialize": true, "initialization_flag": false, "reset_flag": false, "version": 1, "mode": 0, "validate_flag": null, "ip_address": "1.1.1.2"}},
{"pk": 7, "model": "management.resourcedata", "fields": {"reserved": "", "name": "fail_finalize_resource", "dirty": false, "owner": "", "group": 1}},
{"pk": 7, "model": "management.resourcedata", "fields": {"reserved": "", "name": "fail_finalize_resource", "dirty": false, "owner": "", "group": 1}},
{"pk": 7, "model": "management.demoresourcedata", "fields": {"fails_on_finalize": true, "initialization_flag": false, "reset_flag": false, "version": 1, "mode": 0, "validate_flag": null, "ip_address": "1.1.1.2"}},
{"pk": 8, "model": "management.resourcedata", "fields": {"reserved": "", "name": "other_group_resource", "dirty": false, "owner": "", "group": 2}},
{"pk": 8, "model": "management.resourcedata", "fields": {"reserved": "", "name": "other_group_resource", "dirty": false, "owner": "", "group": 2}},
{"pk": 8, "model": "management.demoresourcedata", "fields": {"initialization_flag": false, "reset_flag": false, "version": 1, "mode": 0, "validate_flag": null, "ip_address": "1.1.1.3"}},
{"pk": 9, "model": "management.resourcedata", "fields": {"reserved": "", "name": "resource_with_no_group", "dirty": false, "owner": "", "group": null}},
{"pk": 9, "model": "management.resourcedata", "fields": {"reserved": "", "name": "resource_with_no_group", "dirty": false, "owner": "", "group": null}},
{"pk": 9, "model": "management.demoresourcedata", "fields": {"initialization_flag": false, "reset_flag": false, "version": 1, "mode": 0, "validate_flag": null, "ip_address": "1.1.1.4"}}]
18 changes: 5 additions & 13 deletions src/rotest/management/migrations/0002_auto_20150224_1427.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,11 @@


def create_users(apps, schema_editor):
try:
auth_models.User.objects.get(username='rotest')
except auth_models.User.DoesNotExist:
auth_models.User.objects.create_superuser('rotest',
'rotest@rotest.com',
'rotest')

try:
auth_models.User.objects.get(username='localhost')
except auth_models.User.DoesNotExist:
auth_models.User.objects.create_user('localhost',
'localhost@rotest.com',
'localhost')
qa_group, _ = auth_models.Group.objects.get_or_create(name="QA")
localhost, _ = auth_models.User.objects.get_or_create(username="localhost",
password="localhost",
email="l@l.com")
qa_group.user_set.add(localhost)


class Migration(migrations.Migration):
Expand Down

0 comments on commit eb77568

Please sign in to comment.