Skip to content

Commit

Permalink
verifying by tests that operation dir gets removed on delete (#1449)
Browse files Browse the repository at this point in the history
* skyfield_data updated

* tests for handle_db_seed

* improved UI delete operation test
  • Loading branch information
ReimarBauer authored May 21, 2022
1 parent f54cfcc commit 690fe58
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
90 changes: 90 additions & 0 deletions mslib/mscolab/_tests/test_mscolab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# -*- coding: utf-8 -*-
"""
mslib.mscolab._tests.test_mscolab
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tests for mscolab functionalities
This file is part of mss.
:copyright: Copyright 2019 Shivashis Padhi
:copyright: Copyright 2019-2022 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 os
from flask_testing import TestCase

from mslib.mscolab.conf import mscolab_settings
from mslib.mscolab.models import db, Operation, User, Permission
from mslib.mscolab.mscolab import handle_db_init, handle_db_reset, handle_db_seed
from mslib.mscolab.server import APP
from mslib.mscolab.seed import add_operation


class Test_Mscolab(TestCase):
def create_app(self):
app = APP
app.config['SQLALCHEMY_DATABASE_URI'] = mscolab_settings.SQLALCHEMY_DB_URI
app.config['MSCOLAB_DATA_DIR'] = mscolab_settings.MSCOLAB_DATA_DIR
app.config['UPLOAD_FOLDER'] = mscolab_settings.UPLOAD_FOLDER
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config["TESTING"] = True
app.config['LIVESERVER_TIMEOUT'] = 10
app.config['LIVESERVER_PORT'] = 0
return app

def setUp(self):
db.init_app(self.app)
handle_db_init()
assert Operation.query.all() == []
assert User.query.all() == []
assert Permission.query.all() == []

def test_handle_db_reset(self):
assert os.path.isdir(mscolab_settings.UPLOAD_FOLDER)
assert os.path.isdir(mscolab_settings.MSCOLAB_DATA_DIR)
all_operations = Operation.query.all()
assert all_operations == []
operation_name = "Example"
assert add_operation(operation_name, "Test Example")
assert os.path.isdir(os.path.join(mscolab_settings.MSCOLAB_DATA_DIR, operation_name))
operation = Operation.query.filter_by(path=operation_name).first()
assert operation.description == "Test Example"
all_operations = Operation.query.all()
assert len(all_operations) == 1
handle_db_reset()
# check operation dir name removed
assert os.path.isdir(os.path.join(mscolab_settings.MSCOLAB_DATA_DIR, operation_name)) is False
assert os.path.isdir(mscolab_settings.MSCOLAB_DATA_DIR)
assert os.path.isdir(mscolab_settings.UPLOAD_FOLDER)
# query db for operation_name
operation = Operation.query.filter_by(path=operation_name).first()
assert operation is None
all_operations = Operation.query.all()
assert all_operations == []

def test_handle_db_seed(self):
handle_db_reset()
all_operations = Operation.query.all()
assert all_operations == []
handle_db_seed()
all_operations = Operation.query.all()
assert len(all_operations) == 6
assert all_operations[0].path == "one"
all_users = User.query.all()
assert len(all_users) == 10
all_permissions = Permission.query.all()
assert len(all_permissions) == 17
7 changes: 6 additions & 1 deletion mslib/msui/_tests/test_mscolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,10 @@ def test_handle_delete_operation(self, mocktext, mockbox):
assert self.window.usernameLabel.text() == 'berta'
assert self.window.connectBtn.isVisible() is False
assert self.window.listOperationsMSC.model().rowCount() == 0
self._create_operation("flight7", "Description flight7")
operation_name = "flight7"
self._create_operation(operation_name, "Description flight7")
# check for operation dir is created on server
assert os.path.isdir(os.path.join(mscolab_settings.MSCOLAB_DATA_DIR, operation_name))
assert self.window.mscolab.active_op_id is None
self._activate_operation_at_index(0)
op_id = self.window.mscolab.get_recent_op_id()
Expand All @@ -475,6 +478,8 @@ def test_handle_delete_operation(self, mocktext, mockbox):
assert op_id is None
QtWidgets.QApplication.processEvents()
QtTest.QTest.qWait(0)
# check operation dir name removed
assert os.path.isdir(os.path.join(mscolab_settings.MSCOLAB_DATA_DIR, operation_name)) is False
assert mockbox.call_count == 1

def test_get_recent_op_id(self):
Expand Down

0 comments on commit 690fe58

Please sign in to comment.