Skip to content

Commit

Permalink
Merge branch 'develop' into i899
Browse files Browse the repository at this point in the history
  • Loading branch information
ReimarBauer authored May 26, 2021
2 parents f42fa86 + 956aefc commit 926be7f
Show file tree
Hide file tree
Showing 9 changed files with 561 additions and 286 deletions.
7 changes: 7 additions & 0 deletions mslib/mscolab/_tests/test_file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ def test_is_admin(self):
project = Project.query.filter_by(path="three").first()
assert self.fm.is_admin(self.user.id, project.id) is False

def test_is_collaborator(self):
with self.app.app_context():
project = Project.query.filter_by(path="three").first()
assert self.fm.is_collaborator(self.user.id, project.id)
project = Project.query.filter_by(path="four").first()
assert self.fm.is_collaborator(self.user.id, project.id) is False

def test_auth_type(self):
with self.app.app_context():
project = Project.query.filter_by(path="three").first()
Expand Down
147 changes: 147 additions & 0 deletions mslib/mscolab/_tests/test_seed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# -*- coding: utf-8 -*-
"""
mslib.mscolab._tests.test_seed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tests for conf functionalities
This file is part of mss.
:copyright: Copyright 2019 Shivashis Padhi
:copyright: Copyright 2019-2021 by the mss team, see AUTHORS.
:license: APACHE-2.0, see LICENSE for details.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import sys
from mslib.msui.mscolab import MSSMscolabWindow
from PyQt5 import QtTest, QtWidgets
from mslib.mscolab.models import User
from mslib.mscolab.conf import mscolab_settings
from mslib._tests.utils import (mscolab_register_and_login,
mscolab_create_project, mscolab_delete_all_projects,
mscolab_delete_user, mscolab_start_server)
from mslib.mscolab.seed import add_all_users_default_project, add_user, delete_user


PORTS = list(range(19571, 19590))


class Test_Seed():
def setup(self):
mscolab_settings.enable_basic_http_authentication = False
self.process, self.url, self.app, _, self.cm, self.fm = mscolab_start_server(PORTS, mscolab_settings)
QtTest.QTest.qWait(100)
self.application = QtWidgets.QApplication(sys.argv)
self.window = MSSMscolabWindow(data_dir=mscolab_settings.MSCOLAB_DATA_DIR,
mscolab_server_url=self.url)
with self.app.app_context():
response = mscolab_register_and_login(self.app, self.url, 'UV0@uv0', 'UV0', 'uv0')
assert response.status == '200 OK'
data, response = mscolab_create_project(self.app, self.url, response,
path='XYZ', description='Template')
assert response.status == '200 OK'
data = response.get_data(as_text=True)
assert data == 'True'
mscolab_register_and_login(self.app, self.url, 'UV1@uv1', 'UV1', 'UV1')

def teardown(self):
with self.app.app_context():
mscolab_delete_user(self.app, self.url, 'UV0@uv0', 'UV0')
mscolab_delete_user(self.app, self.url, 'UV1@uv1', 'UV1')
mscolab_delete_all_projects(self.app, self.url, 'UV0@uv0', 'uv0', 'UV0')
mscolab_delete_all_projects(self.app, self.url, 'UV1@uv1', 'uv1', 'UV1')
user = User.query.filter_by(emailid="UV2@v2").first()
if user is not None:
delete_user('UV2@uv2')
if self.window.version_window:
self.window.version_window.close()
if self.window.conn:
self.window.conn.disconnect()
self.application.quit()
QtWidgets.QApplication.processEvents()
self.process.terminate()

def test_add_all_users_default_project_viewer(self):
with self.app.app_context():
# viewer
add_all_users_default_project(path='XYZ', description="Project to keep all users", access_level='viewer')
expected_result = [{'access_level': 'viewer', 'description': 'Template', 'p_id': 7, 'path': 'XYZ'}]
user = User.query.filter_by(emailid="UV1@uv1").first()
assert user is not None
result = self.fm.list_projects(user)
# we don't care here for p_id
expected_result[0]['p_id'] = result[0]['p_id']
assert result == expected_result

def test_add_all_users_default_project_collaborator(self):
with self.app.app_context():
# collaborator
add_all_users_default_project(path='XYZ', description="Project to keep all users",
access_level='collaborator')
expected_result = [{'access_level': 'collaborator', 'description': 'Template', 'p_id': 7, 'path': 'XYZ'}]
user = User.query.filter_by(emailid="UV1@uv1").first()
assert user is not None
result = self.fm.list_projects(user)
# we don't care here for p_id
expected_result[0]['p_id'] = result[0]['p_id']
assert result == expected_result

def test_add_all_users_default_project_creator(self):
with self.app.app_context():
# creator
add_all_users_default_project(path='XYZ', description="Project to keep all users",
access_level='creator')
expected_result = [{'access_level': 'creator', 'description': 'Template', 'p_id': 7, 'path': 'XYZ'}]
user = User.query.filter_by(emailid="UV1@uv1").first()
result = self.fm.list_projects(user)
# we don't care here for p_id
expected_result[0]['p_id'] = result[0]['p_id']
assert result == expected_result

def test_add_all_users_default_project_creator_unknown_project(self):
with self.app.app_context():
# creator added to new project
add_all_users_default_project(path='UVXYZ', description="Project to keep all users",
access_level='creator')
expected_result = [{'access_level': 'creator', 'description': 'Project to keep all users',
'p_id': 7, 'path': 'UVXYZ'}]
user = User.query.filter_by(emailid="UV1@uv1").first()
result = self.fm.list_projects(user)
# we don't care here for p_id
expected_result[0]['p_id'] = result[0]['p_id']
assert result == expected_result

def test_add_user(self, capsys):
self.app.app_context().push()
add_user("UV2@v2", "V2", "v2")
captured = capsys.readouterr()
assert "Userdata: UV2@v2 V2 v2" in captured.out
add_user("UV2@v2", "V2", "v2")
captured = capsys.readouterr()
assert '<User V2> already in db\n' == captured.out

def test_delete_user(self, capsys):
self.app.app_context().push()
add_user("UV2@v2", "V2", "v2")
captured = capsys.readouterr()
assert "Userdata: UV2@v2 V2 v2" in captured.out
user = User.query.filter_by(emailid="UV2@v2").first()
assert user is not None
delete_user("UV2@v2")
captured = capsys.readouterr()
assert 'User: UV2@v2 deleted from db\n' == captured.out
user = User.query.filter_by(emailid="UV2@v2").first()
assert user is None
11 changes: 10 additions & 1 deletion mslib/mscolab/_tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
import os
import sys
import pytest
from fs.tempfs import TempFS

from PyQt5 import QtWidgets, QtTest

from mslib.mscolab.models import User, MessageType
from mslib.mscolab.utils import get_recent_pid, get_session_id, get_message_dict, create_files
from mslib.mscolab.utils import get_recent_pid, get_session_id, get_message_dict, create_files, os_fs_create_dir
from mslib.mscolab.conf import mscolab_settings
from mslib.msui.mscolab import MSSMscolabWindow
from mslib._tests.utils import (mscolab_start_server, mscolab_create_project, mscolab_register_and_login,
Expand Down Expand Up @@ -136,3 +138,10 @@ def test_get_recent_pid(self):
with self.app.app_context():
p_id = get_recent_pid(self.fm, self.user)
assert p_id is None


def test_os_fs_create_dir():
_fs = TempFS(identifier="mss")
_dir = _fs.getsyspath("")
os_fs_create_dir(_dir)
assert os.path.exists(_dir)
4 changes: 3 additions & 1 deletion mslib/mscolab/sockets_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,14 @@ def handle_file_save(self, json_req):
# if permission is correct and file saved properly
if perm and self.fm.save_file(int(p_id), content, user, comment):
# send service message
message_ = "[service message] saved changes"
message_ = f"[service message] **{user.username}** saved changes"
new_message = self.cm.add_message(user, message_, str(p_id), message_type=MessageType.SYSTEM_MESSAGE)
new_message_dict = get_message_dict(new_message)
socketio.emit('chat-message-client', json.dumps(new_message_dict), room=str(p_id))
# emit file-changed event to trigger reload of flight track
socketio.emit('file-changed', json.dumps({"p_id": p_id, "u_id": user.id}), room=str(p_id))
else:
logging.debug(f'login expired for {user.username}, state unauthorized!')

def emit_file_change(self, p_id):
socketio.emit('file-changed', json.dumps({"p_id": p_id}), room=str(p_id))
Expand Down
22 changes: 15 additions & 7 deletions mslib/msui/mpl_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MapCanvas(basemap.Basemap):
automatically draw a graticule and to redraw specific map elements.
"""

def __init__(self, identifier=None, CRS=None, BBOX_UNITS=None,
def __init__(self, identifier=None, CRS=None, BBOX_UNITS=None, PROJECT_NAME=None,
appearance=None, **kwargs):
"""
New constructor automatically adds coastlines, continents, and
Expand All @@ -64,6 +64,7 @@ def __init__(self, identifier=None, CRS=None, BBOX_UNITS=None,
Additional arguments:
CRS -- string describing the coordinate reference system of the map.
BBOX_UNITS -- string describing the units of the map coordinates.
PROJECT_NAME -- string with project name
"""
# Coordinate reference system identifier and coordinate system units.
Expand All @@ -73,6 +74,9 @@ def __init__(self, identifier=None, CRS=None, BBOX_UNITS=None,
else:
self.bbox_units = getattr(self, "bbox_units", None)

self.project_name = PROJECT_NAME if PROJECT_NAME is not None else self.project_name \
if hasattr(self, "project_name") else None

# Dictionary containing map appearance settings.
if appearance is not None:
param_appearance = appearance
Expand Down Expand Up @@ -129,12 +133,16 @@ def __init__(self, identifier=None, CRS=None, BBOX_UNITS=None,

self.image = None

# Print CRS identifier into the figure.
if self.crs is not None:
if hasattr(self, "crs_text"):
self.crs_text.set_text(self.crs)
else:
self.crs_text = self.ax.figure.text(0, 0, self.crs)
# Print CRS identifier and project name into figure.
if self.crs is not None and self.project_name is not None:
self.crs_text = self.ax.figure.text(0, 0, f"{self.project_name}\n{self.crs}")
else:
# Print only CRS identifier into the figure.
if self.crs is not None:
if hasattr(self, "crs_text"):
self.crs_text.set_text(self.crs)
else:
self.crs_text = self.ax.figure.text(0, 0, self.crs)

if self.appearance["draw_graticule"]:
try:
Expand Down
Loading

0 comments on commit 926be7f

Please sign in to comment.