Skip to content

Commit

Permalink
reviewing tests, #1138 (#1139)
Browse files Browse the repository at this point in the history
* skipped test_version_name_delete

* tests skipped, because they can be biased

* ToDos added

* skipped because failing in reverse order

* test assert removed

* hanging tests skipped

* a few tests skipped which fails in (reverse) order

* skipped because: An unhandled message box popped up during your test!

* simplified tests

* removed dependency to server start

* improved tests for user object, refactored test_files

* refactored test_files_api

* Test_Init_Server refactored

* server tests partial refactored

* test_server completed

* fixed type bug in server and updated test_server

* cleanup duplicated tests

* reactored test_server

* refactored test_utils

* refactored test_chat_manager.py for test_client

* refactored to test_client

* test_file_manager refactored for test_client

* refactored test_files to test_client

* test_files_api refactored for test_client

* refactored test_seed for test_client

* refactored call of db.init_app

* used userdata

* removed duplications

* enabled skipped tests

* introduces reverse order on testing

* disabled a test, because of KeyError

* renamed the "json" parameter

* tests start with a resetted database
  • Loading branch information
ReimarBauer authored Aug 13, 2021
1 parent 36f4467 commit bbf1313
Show file tree
Hide file tree
Showing 22 changed files with 1,043 additions and 1,478 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ jobs:
run: |
source /opt/conda/bin/activate mssenv \
&& cd $GITHUB_WORKSPACE \
&& pytest -v --durations=20 --cov=mslib mslib \
&& pytest -v --durations=20 --reverse --cov=mslib mslib \
|| (for i in {1..5} \
; do pytest mslib -v --durations=0 --last-failed --lfnf=none \
; do pytest mslib -v --durations=0 --reverse --last-failed --lfnf=none \
&& break \
; done)
Expand Down
2 changes: 2 additions & 0 deletions mslib/mscolab/_tests/test_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def test_get_messages(self):
sio.connect(self.url)
sio.emit('start', response)
sio.sleep(2)
# ToDo same message gets twice emmitted, why? (use a helper function)
sio.emit("chat-message", {
"p_id": 1,
"token": response['token'],
Expand Down Expand Up @@ -148,6 +149,7 @@ def test_get_messages_api(self):
sio.connect(self.url)
sio.emit('start', response)
sio.sleep(2)
# ToDo same message gets twice emmitted, why?
sio.emit("chat-message", {
"p_id": 1,
"token": response['token'],
Expand Down
98 changes: 42 additions & 56 deletions mslib/mscolab/_tests/test_chat_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,78 +24,64 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
import os
import requests
import json
import sys
import pytest

from werkzeug.urls import url_join
from PyQt5 import QtWidgets, QtTest
from mslib.mscolab.models import User, MessageType, Message
from mslib.mscolab.conf import mscolab_settings
from mslib.mscolab.chat_manager import ChatManager
from mslib.msui.mscolab import MSSMscolabWindow
from mslib._tests.utils import mscolab_start_server


PORTS = list(range(9321, 9340))
from flask_testing import TestCase


@pytest.mark.skipif(os.name == "nt",
reason="multiprocessing needs currently start_method fork")
class Test_Chat_Manager(object):
def setup(self):
self.process, self.url, self.app, _, self.cm, self.fm = mscolab_start_server(PORTS)
QtTest.QTest.qWait(500)
self.application = QtWidgets.QApplication(sys.argv)
self.window = MSSMscolabWindow(data_dir=mscolab_settings.MSCOLAB_DATA_DIR,
mscolab_server_url=self.url)
self.cm = ChatManager()
from mslib.mscolab.conf import mscolab_settings
from mslib.mscolab.models import Message, MessageType
from mslib.mscolab.mscolab import handle_db_reset
from mslib.mscolab.server import APP
from mslib.mscolab.seed import add_user, get_user, add_project, add_user_to_project
from mslib.mscolab.sockets_manager import setup_managers


class Test_Chat_Manager(TestCase):
render_templates = False

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):
handle_db_reset()
self.userdata = 'UV10@uv10', 'UV10', 'uv10'
self.anotheruserdata = 'UV20@uv20', 'UV20', 'uv20'
self.room_name = "europe"
data = {
'email': 'a',
'password': 'a'
}
r = requests.post(self.url + '/token', data=data)
self.token = json.loads(r.text)['token']
with self.app.app_context():
self.user = User.query.filter_by(id=8).first()

data = {
"token": self.token,
"path": self.room_name,
"description": "test description"
}
url = url_join(self.url, 'create_project')
requests.post(url, data=data)

def teardown(self):
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()
socketio, self.cm, self.fm = setup_managers(self.app)
assert add_user(self.userdata[0], self.userdata[1], self.userdata[2])
assert add_project(self.room_name, "test europe")
assert add_user_to_project(path=self.room_name, emailid=self.userdata[0])
self.user = get_user(self.userdata[0])

def tearDown(self):
pass

def test_add_message(self):
with self.app.app_context():
message = self.cm.add_message(self.user, 'some message', self.room_name, message_type=MessageType.TEXT,
with self.app.test_client():
message = self.cm.add_message(self.user, 'some message',
self.room_name, message_type=MessageType.TEXT,
reply_id=None)
assert message.text == 'some message'

def test_edit_messages(self):
with self.app.app_context():
message = self.cm.add_message(self.user, 'some test message', self.room_name, message_type=MessageType.TEXT,
with self.app.test_client():
message = self.cm.add_message(self.user, 'some test message',
self.room_name, message_type=MessageType.TEXT,
reply_id=None)
new_message_text = "Wonderland"
self.cm.edit_message(message.id, new_message_text)
message = Message.query.filter_by(id=message.id).first()
assert message.text == new_message_text

def test_delete_messages(self):
with self.app.app_context():
with self.app.test_client():
message = self.cm.add_message(self.user, 'some test example message',
self.room_name, message_type=MessageType.TEXT,
reply_id=None)
Expand Down
Loading

0 comments on commit bbf1313

Please sign in to comment.