Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django tests #270

Merged
merged 11 commits into from
Mar 4, 2018
Merged
5 changes: 0 additions & 5 deletions .omeroci/app-build

This file was deleted.

18 changes: 18 additions & 0 deletions .omeroci/app-srv
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -e
set -u
set -x

yum -y install python-reportlab python-markdown
rm -rf $OMERO_DIST/lib/scripts/omero

cd $TARGET
cd omero_figure/scripts
cp -r omero $OMERO_DIST/lib/scripts/

export ICE_CONFIG=${OMERO_DIST}/etc/ice.config
export ROOTPASS=$(cat $ICE_CONFIG | grep omero.rootpass | cut -f2 -d=)
export PATH=$PATH:$OMERO_DIST/bin
omero login -w $ROOTPASS root@omero
omero script list
11 changes: 0 additions & 11 deletions .omeroci/scripts-copy

This file was deleted.

3 changes: 0 additions & 3 deletions .omeroci/scripts-deps

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ before_install:
- git clone git://github.com/openmicroscopy/omero-test-infra .omero

script:
- .omero/docker app scripts
- .omero/docker app
4 changes: 2 additions & 2 deletions omero_figure/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def list_web_figures(request, conn=None, **kwargs):
}
rsp.append(fig_file)

return HttpResponse(json.dumps(rsp), content_type='json')
return HttpResponse(json.dumps(rsp), content_type='application/json')


def default_thumbnail(size=(120, 120)):
Expand Down Expand Up @@ -421,7 +421,7 @@ def unit_conversion(request, value, from_unit, to_unit, conn=None, **kwargs):
'unit': str(to_value.getUnit()),
'symbol': to_value.getSymbol()}

return HttpResponse(json.dumps(rsp), content_type='json')
return HttpResponse(json.dumps(rsp), content_type='application/json')


@login_required()
Expand Down
8 changes: 8 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class PyTest(test_command):
('test-no-capture', 's', "don't suppress test output"),
('test-failfast', 'x', "Exit on first error"),
('test-verbose', 'v', "more verbose output"),
('test-string=', 'k', "filter tests by string"),
('test-quiet', 'q', "less verbose output"),
('junitxml=', None, "create junit-xml style report file at 'path'"),
('pdb', None, "fallback to pdb on error"),
Expand Down Expand Up @@ -94,11 +95,18 @@ def finalize_options(self):
def run_tests(self):
if self.test_pythonpath is not None:
sys.path.insert(0, self.test_pythonpath)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "omeroweb.settings")

# import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(self.test_args)
sys.exit(errno)

import django
if django.VERSION > (1, 7):
django.setup()


cmdclass['test'] = PyTest

Expand Down
57 changes: 57 additions & 0 deletions test/integration/test_figure_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

#
# Copyright (C) 2018 University of Dundee & Open Microscopy Environment.
# All rights reserved. Use is subject to license terms supplied in LICENSE.txt
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

"""Integration tests for testing saving and loading figure files."""

from omeroweb.testlib import IWebTest, get_json
import pytest
from django.core.urlresolvers import reverse
from omero.gateway import BlitzGateway


def get_connection(user, group_id=None):
"""Get a BlitzGateway connection for the given user's client."""
connection = BlitzGateway(client_obj=user[0])
# Refresh the session context
connection.getEventContext()
if group_id is not None:
connection.SERVICE_OPTS.setOmeroGroup(group_id)
return connection


class TestSaveAndLoadFigures(IWebTest):
"""Tests saving, listing and loading OMERO.figure json files."""

@pytest.fixture()
def user1(self):
"""Return a new user in a read-annotate group."""
group = self.new_group(perms='rwra--')
user = self.new_client_and_user(group=group)
return user

def test_list_figures(self, user1):
"""Test create and update are rejected for unsupported types."""
conn = get_connection(user1)
user_name = conn.getUser().getName()
django_client = self.new_django_client(user_name, user_name)
list_files_url = reverse('list_web_figures')
rsp = get_json(django_client, list_files_url)
assert len(rsp) == 0
2 changes: 1 addition & 1 deletion test/integration/test_figure_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

#
# Copyright (C) 2016 University of Dundee & Open Microscopy Environment.
# Copyright (C) 2018 University of Dundee & Open Microscopy Environment.
# All rights reserved. Use is subject to license terms supplied in LICENSE.txt
#
# This program is free software; you can redistribute it and/or modify
Expand Down