ome / omero-figure

An OMERO.web app for creating Figures from images in OMERO
http://figure.openmicroscopy.org
GNU Affero General Public License v3.0
15 stars 31 forks source link

Django tests #270

Closed will-moore closed 6 years ago

will-moore commented 6 years ago

Looked at adding Django-based tests but this will clearly take a lot more setup than I am familiar with just now. E.g. need to do similar to https://github.com/openmicroscopy/openmicroscopy/blob/develop/components/tools/OmeroWeb/setup.py#L24

    sys.path.insert(0, os.path.join("..", "target", "lib", "fallback"))
    LIB = os.path.join("..", "target", "lib", "python")
    sys.path.insert(0, LIB)
    OMEROWEB_LIB = os.path.join(LIB, "omeroweb")
    sys.path.insert(1, OMEROWEB_LIB)

Currently failing locally with

ImproperlyConfigured: Requested setting ROOT_URLCONF, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
joshmoore commented 6 years ago
./test/integration/test_figure_files.py:57:29: W292 no newline at end of file
will-moore commented 6 years ago
========================== 5 failed in 11.61 seconds ===========================

Scripts tests are failing because scripts are not being copied over

        id = super(TestFigureScripts, self).get_script_by_name(path, name)
>       assert id > 0
E       assert -1 > 0

My Django test is failing with

        rsp = get(django_client, request_url, data, status_code, csrf)
>       assert rsp.get('Content-Type') == 'application/json'
E       AssertionError

but as I mentioned at https://github.com/will-moore/figure/pull/4#issuecomment-364456120 debugging this isn't so straight-forward given this test setup...

jburel commented 6 years ago
joshmoore commented 6 years ago

@jburel : will splitting the tests into subdirectories (or adding a @pytest.mark) help?

jburel commented 6 years ago

@joshmoore that was my next step to see what can be done at the tests level

joshmoore commented 6 years ago

This looks like it's working. One test still failing but I think that's for @will-moore :


django_client = <django.test.client.Client object at 0x6e66310>
request_url = '/figure/list_web_figures/', data = None, status_code = 200
csrf = False

    def get_json(django_client, request_url, data=None, status_code=200,
                 csrf=False):
        """
        Performs a GET request and returns the JSON response as a dict.

        :param django_client:   Django test Client
        :param request_url:     The url to request
        :param data:            A dictionary of data, used to build a query string
        :param status_code:     Verify that the response has this status
        :param csrf:            If true, add csrf token to query string

        """
        rsp = get(django_client, request_url, data, status_code, csrf)
>       assert rsp.get('Content-Type') == 'application/json'
E       AssertionError

/opt/omero/web/OMERO.web/lib/python/omeroweb/testlib/__init__.py:362: AssertionError
------------------------------ Captured log setup ------------------------------
views.py                   104 INFO     INIT '455'
settings.py                885 INFO     Processing custom settings for module omeroweb.api.api_settings
__init__.py               2209 INFO     created connection (uuid=c52a8abf-68e3-4362-a20a-e00789e895f1)
connector.py               229 INFO     Client version: '['5', '4', '3']'; Server version: '['5', '4', '3']'
__init__.py               2209 INFO     created connection (uuid=64a0d3c6-5c72-4381-a5e9-9702e201f98c)
upgrade_check.py           148 INFO     no update needed
__init__.py               2209 INFO     created connection (uuid=53a44b34-cb35-4ad5-8631-fdf97de12c99)
connector.py               229 INFO     Client version: '['5', '4', '3']'; Server version: '['5', '4', '3']'
__init__.py               2209 INFO     created connection (uuid=a09ce5b0-f17d-4ac3-92c6-7297b69e70b8)
upgrade_check.py           148 INFO     no update needed
------------------------------ Captured log call -------------------------------
__init__.py               2209 INFO     created connection (uuid=854bf328-dbf0-4170-a9c6-59545f969836)
connector.py               229 INFO     Client version: '['5', '4', '3']'; Server version: '['5', '4', '3']'
__init__.py               2209 INFO     created connection (uuid=a320847d-fa01-469b-ba66-1d1d2aaea9b9)
upgrade_check.py           148 INFO     no update needed
__init__.py               2209 INFO     created connection (uuid=a320847d-fa01-469b-ba66-1d1d2aaea9b9)
---------------------------- Captured log teardown -----------------------------
__init__.py               2209 INFO     created connection (uuid=64a0d3c6-5c72-4381-a5e9-9702e201f98c)
__init__.py               1922 INFO     closed connecion (uuid=64a0d3c6-5c72-4381-a5e9-9702e201f98c)
__init__.py               2209 INFO     created connection (uuid=a09ce5b0-f17d-4ac3-92c6-7297b69e70b8)
__init__.py               1922 INFO     closed connecion (uuid=a09ce5b0-f17d-4ac3-92c6-7297b69e70b8)
__init__.py               2209 INFO     created connection (uuid=a320847d-fa01-469b-ba66-1d1d2aaea9b9)
__init__.py               1922 INFO     closed connecion (uuid=a320847d-fa01-469b-ba66-1d1d2aaea9b9)
===================== 1 failed, 4 passed in 27.40 seconds ======================
jburel commented 6 years ago

Travis is now green. Suggested merging workflow