Skip to content

Commit

Permalink
Merge pull request #167 from gregoil/config_using_django_settings
Browse files Browse the repository at this point in the history
Config using django settings module
  • Loading branch information
osherdp committed Oct 22, 2019
2 parents 12b315d + 85863a2 commit 27ebeb4
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 67 deletions.
1 change: 0 additions & 1 deletion .rotest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
rotest:
workdir: ~/.rotest
host: localhost
django_settings: rotest.common.django_utils.settings
69 changes: 39 additions & 30 deletions docs/configurations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Configurations

Rotest behaviour can be configured in the following ways:

* A configuration file called :file:`rotest.yml` in YAML format.
* Defining variables in the Django settings module.

* *DEPRECATED:* A configuration file called :file:`rotest.yml` in YAML format.

* Environment variables.

Expand All @@ -25,6 +27,8 @@ session-based, and command line arguments are relevant for a specific run.

* Environment variables take precedence over the configuration file.

* Configuration file take precedence over the Django settings module.

* Some configuration attributes have default values, in case there's no
answer.

Expand Down Expand Up @@ -55,7 +59,7 @@ and this way in Windows:
.. code-block:: console
$ set ENVIRONMENT_VARIABLE=value
$ setx ENVIRONMENT_VARIABLE=value # Set it permanently (reopen the shell)
$ setx ENVIRONMENT_VARIABLE value # Set it permanently (reopen the shell)
Working Directory
-----------------
Expand All @@ -69,6 +73,8 @@ use the following methods:

* Define :envvar:`ROTEST_WORK_DIR` to point to the path.

* Define variable `ROTEST_WORK_DIR` in the Django settings module.

* Define ``workdir`` in the configuration file:

.. code-block:: yaml
Expand All @@ -91,6 +97,8 @@ that the client should contact with, use the following methods:

* Define :envvar:`ROTEST_HOST` to point to the server DNS or IP address.

* Define variable `ROTEST_HOST` in the Django settings module.

* Define ``host`` in the configuration file:

.. code-block:: yaml
Expand All @@ -112,6 +120,8 @@ will communicate with, use the following methods:

* Define :envvar:`ROTEST_SERVER_PORT` with the desired port.

* Define variable `ROTEST_SERVER_PORT` in the Django settings module.

* Define ``port`` in the configuration file:

.. code-block:: yaml
Expand All @@ -136,6 +146,8 @@ via the following methods:
* Define :envvar:`ROTEST_RESOURCE_REQUEST_TIMEOUT` with the number of seconds
to wait before giving up on waiting for resources.

* Define variable `ROTEST_RESOURCE_REQUEST_TIMEOUT` in the Django settings module.

* Define ``resource_request_timeout`` in the configuration file:

.. code-block:: yaml
Expand All @@ -145,28 +157,6 @@ via the following methods:
* Use the default, which is ``0`` (not waiting at all).

Django Settings Module
----------------------

.. envvar:: DJANGO_SETTINGS_MODULE

Django configuration path, in a module syntax.

Rotest is a Django library, and as such needs its configuration module, in
order to write and read data about the resources from the database. Define it
in the following ways:

* Define :envvar:`DJANGO_SETTINGS_MODULE`.

* Define ``django_settings`` in the configuration file:

.. code-block:: yaml
rotest:
django_settings: package1.package2.settings
* There is no default value.

Smart client
------------

Expand All @@ -178,6 +168,8 @@ To define smart client behavior, use the following methods:

* Define :envvar:`ROTEST_SMART_CLIENT` with to be 'True' or 'False'.

* Define variable `ROTEST_SMART_CLIENT` in the Django settings module.

* Define ``smart_client`` in the configuration file:

.. code-block:: yaml
Expand All @@ -200,6 +192,8 @@ in the following ways:

* Define :envvar:`ARTIFACTS_DIR`.

* Define variable `ARTIFACTS_DIR` in the Django settings module.

* Define ``artifact_dir`` in the configuration file:

.. code-block:: yaml
Expand All @@ -216,6 +210,9 @@ Shell Startup Commands
to write them every time. The commands must be simple one-liners.
Define it in the following ways:

* Define variable `SHELL_STARTUP_COMMANDS` in the Django settings module
that points to a list of strings to execute as commands.

* Define ``shell_startup_commands`` in the configuration file:

.. code-block:: yaml
Expand All @@ -229,19 +226,31 @@ Shell Output Handlers
----------------------

``rotest shell`` enables defining output handlers for components run in it,
(see :ref:`output_handlers`). The default value is ``["logdebug"]``.
(see :ref:`output_handlers`).

* Define variable `SHELL_OUTPUT_HANDLERS` in the Django settings module
that points to a list of output handler names.

* Define ``shell_output_handlers`` in the configuration file:

.. code-block:: yaml
rotest:
shell_output_handlers: ["loginfo"]
* Use the default, which is ``["logdebug"]``.

Discoverer Blacklist
--------------------

Rotest enables loading resources from an app, a thing that happens automatically
when running ``rotest shell``, but some files can / must be skipped when searching
for the resources.

Also, tests discovering (via ``rotest <some_dir>``) takes this blacklist into consideration.
Rotest enables discovering tests by running ``rotest <path to search>``,
but sometimes some files can / must be skipped when searching for tests.
The patterns are in fnmatch syntax.

Define it in the following ways:

* Define variable `DISCOVERER_BLACKLIST` in the Django settings module.

* Define ``discoverer_blacklist`` in the configuration file:

.. code-block:: yaml
Expand Down
14 changes: 7 additions & 7 deletions docs/intro/basic_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ You'll end up with the following tree:
├── urls.py
└── wsgi.py
Don't forget to set the Django settings to point to your new project:
(use ``setx`` instead of ``export`` on Windows machines)

.. code-block:: console
$ export DJANGO_SETTINGS_MODULE=rotest_demo.settings
Now add an end-point for rotest urls in the :file:`urls.py` file:

.. code-block:: python
Expand All @@ -112,8 +119,6 @@ Inside it, create a file in the root directory of the project called
rotest:
host: localhost
api_base_url: rotest/api/
django_settings: rotest_demo.settings
Pay attention to the following:

Expand All @@ -122,11 +127,6 @@ Pay attention to the following:
* The `host` key is how the client should contact the server. It's an IP
address, or a DNS of the server. For now, both the client and server are
running on the same machine., but it doesn't have to be that way.
* The `api_base_url` key is the end-point url of the rotest urls file,
it must be configured for the resource management to work - default is "rotest/api/".
* The `django_settings` key is directing to the settings of the Django app,
that defines all relevant Django configuration (DB configuration, installed
Django applications, and so on).

Note that in the next section (:ref:`adding_resources`) you'll change the
`settings.py` file to enable using Rotest infrastructure over Django.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup, find_packages


__version__ = "7.14.0"
__version__ = "8.0.0"

result_handlers = [
"db = rotest.core.result.handlers.db_handler:DBHandler",
Expand Down
4 changes: 2 additions & 2 deletions src/rotest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""Rotest testing framework, based on Python unit-test and Django."""
# pylint: disable=unused-import
# pylint: disable=unused-import, wrong-import-position
from __future__ import absolute_import
from unittest import skip, SkipTest, skipIf as skip_if

import django
import colorama

from .common import config
if not hasattr(django, 'apps'): # noqa
django.setup()

from .common import config

# Enable color printing on screen.
colorama.init()

0 comments on commit 27ebeb4

Please sign in to comment.