Skip to content

Commit

Permalink
Merge branch 'develop' into MFDW
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit2p authored Apr 15, 2024
2 parents d776c0a + e71d9f3 commit a699008
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 24 deletions.
2 changes: 1 addition & 1 deletion mslib/mscolab/chat_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_messages(self, op_id, timestamp=None):
if timestamp is None:
timestamp = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc)
else:
timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%d, %H:%M:%S %z")
timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%d, %H:%M:%S.%f %z")
messages = Message.query \
.filter(Message.op_id == op_id) \
.filter(Message.reply_id.is_(None)) \
Expand Down
2 changes: 1 addition & 1 deletion mslib/mscolab/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def get_all_changes(self, op_id, user, named_version=False):
'comment': change.comment,
'version_name': change.version_name,
'username': change.user.username,
'created_at': change.created_at.strftime("%Y-%m-%d, %H:%M:%S %z")
'created_at': change.created_at.strftime("%Y-%m-%d, %H:%M:%S.%f %z")
}, changes))

def get_change_content(self, ch_id, user):
Expand Down
2 changes: 1 addition & 1 deletion mslib/mscolab/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def messages():
user = g.user
op_id = request.args.get("op_id", request.form.get("op_id", None))
if fm.is_member(user.id, op_id):
timestamp = request.args.get("timestamp", request.form.get("timestamp", "1970-01-01, 00:00:00 +00:00"))
timestamp = request.args.get("timestamp", request.form.get("timestamp", "1970-01-01, 00:00:00.000000 +00:00"))
chat_messages = cm.get_messages(op_id, timestamp)
return jsonify({"messages": chat_messages})
return "False"
Expand Down
2 changes: 1 addition & 1 deletion mslib/mscolab/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_message_dict(message):
"message_type": message.message_type,
"reply_id": message.reply_id,
"replies": [],
"time": message.created_at.strftime("%Y-%m-%d, %H:%M:%S %z")
"time": message.created_at.strftime("%Y-%m-%d, %H:%M:%S.%f %z")
}


Expand Down
3 changes: 2 additions & 1 deletion mslib/msui/mscolab_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ def load_all_messages(self):
data = {
"token": self.token,
"op_id": self.op_id,
"timestamp": datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S %z")
"timestamp": datetime.datetime(1970, 1, 1,
tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z")
}
# returns an array of messages
url = urljoin(self.mscolab_server_url, "messages")
Expand Down
2 changes: 1 addition & 1 deletion mslib/msui/mscolab_version_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def load_all_changes(self):
changes = json.loads(r.text)["changes"]
self.changes.clear()
for change in changes:
created_at = datetime.strptime(change["created_at"], "%Y-%m-%d, %H:%M:%S %z")
created_at = datetime.strptime(change["created_at"], "%Y-%m-%d, %H:%M:%S.%f %z")
local_time = utc_to_local_datetime(created_at)
date = local_time.strftime('%d/%m/%Y')
time = local_time.strftime('%I:%M %p')
Expand Down
5 changes: 1 addition & 4 deletions mslib/msui/topview.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ def __init__(self, parent=None, mainwindow=None, model=None, _id=None,
self.mainwindow_signal_permission_revoked = mainwindow.signal_permission_revoked
self.mainwindow_signal_render_new_permission = mainwindow.signal_render_new_permission
self.mainwindow_signal_activate_flighttrack = mainwindow.signal_activate_flighttrack
self.mainwindow_signal_activate_operation = mainwindow.signal_activate_operation
self.mainwindow_signal_login_mscolab = mainwindow.signal_login_mscolab
self.mainwindow_signal_logout_mscolab = mainwindow.signal_logout_mscolab
self.mainwindow_listFlightTracks = mainwindow.listFlightTracks
self.mainwindow_filterCategoryCb = mainwindow.filterCategoryCb
self.mainwindow_listOperationsMSC = mainwindow.listOperationsMSC
Expand Down Expand Up @@ -362,7 +359,7 @@ def openTool(self, index):
mscolab_server_url=self.mscolab_server_url,
token=self.token)

self.mainwindow_signal_logout_mscolab.connect(lambda: self.signal_logout_mscolab.emit())
self.mainwindow_signal_logout_mscolab.connect(self.signal_logout_mscolab.emit)
self.mainwindow_signal_listFlighttrack_doubleClicked.connect(
lambda: self.signal_listFlighttrack_doubleClicked.emit())
self.mainwindow_signal_permission_revoked.connect(
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ omit =
norecursedirs = .git .idea .cache

[flake8]
ignore = E124,E125,E402,W504
ignore = E124,E125,E402,W504,A005
max-line-length = 120
exclude = mslib/msui/qt5/*.py, mslib/mscolab/migrations/*.py
5 changes: 0 additions & 5 deletions tests/_test_mscolab/test_files_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
import time
import fs
import pytest

Expand Down Expand Up @@ -172,8 +171,6 @@ def test_get_all_changes(self):
with self.app.test_client():
flight_path, operation = self._create_operation(flight_path="V11")
assert self.fm.save_file(operation.id, "content1", self.user)
# we need to wait to get an updated created_at
time.sleep(1)
assert self.fm.save_file(operation.id, "content2", self.user)
all_changes = self.fm.get_all_changes(operation.id, self.user)
# the newest change is on index 0, because it has a recent created_at time
Expand All @@ -186,9 +183,7 @@ def test_get_change_content(self):
with self.app.test_client():
flight_path, operation = self._create_operation(flight_path="V12", content='initial')
assert self.fm.save_file(operation.id, "content1", self.user)
time.sleep(1)
assert self.fm.save_file(operation.id, "content2", self.user)
time.sleep(1)
assert self.fm.save_file(operation.id, "content3", self.user)
all_changes = self.fm.get_all_changes(operation.id, self.user)
previous_change = self.fm.get_change_content(all_changes[2]["id"], self.user)
Expand Down
4 changes: 0 additions & 4 deletions tests/_test_mscolab/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
import time
import pytest
import json
import io
Expand Down Expand Up @@ -234,7 +233,6 @@ def test_get_all_changes(self):
with self.app.test_client() as test_client:
operation, token = self._create_operation(test_client, self.userdata)
fm, user = self._save_content(operation, self.userdata)
time.sleep(1)
fm.save_file(operation.id, "content2", user)
# the newest change is on index 0, because it has a recent created_at time
response = test_client.get('/get_all_changes', data={"token": token,
Expand All @@ -252,8 +250,6 @@ def test_get_change_content(self):
with self.app.test_client() as test_client:
operation, token = self._create_operation(test_client, self.userdata)
fm, user = self._save_content(operation, self.userdata)
# we need to wait to get an updated created_at
time.sleep(1)
fm.save_file(operation.id, "content2", user)
all_changes = fm.get_all_changes(operation.id, user)
response = test_client.get('/get_change_content', data={"token": token,
Expand Down
11 changes: 7 additions & 4 deletions tests/_test_mscolab/test_sockets_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,12 @@ def test_get_messages(self):
assert messages[0]["text"] == "message from 1"
assert len(messages) == 2
assert messages[0]["u_id"] == self.user.id
timestamp = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S %z")
timestamp = datetime.datetime(1970, 1, 1,
tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z")
messages = self.cm.get_messages(1, timestamp)
assert len(messages) == 2
assert messages[0]["u_id"] == self.user.id
timestamp = datetime.datetime.now(tz=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S %z")
timestamp = datetime.datetime.now(tz=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z")
messages = self.cm.get_messages(1, timestamp)
assert len(messages) == 0

Expand All @@ -221,7 +222,8 @@ def test_get_messages_api(self):
data = {
"token": token,
"op_id": self.operation.id,
"timestamp": datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S %z")
"timestamp": datetime.datetime(1970, 1, 1,
tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z")
}
# returns an array of messages
url = urljoin(self.url, 'messages')
Expand Down Expand Up @@ -257,7 +259,8 @@ def test_edit_message(self):
data = {
"token": token,
"op_id": self.operation.id,
"timestamp": datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S %z")
"timestamp": datetime.datetime(1970, 1, 1,
tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z")
}
# returns an array of messages
url = urljoin(self.url, 'messages')
Expand Down
68 changes: 68 additions & 0 deletions tests/_test_msui/test_mscolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,74 @@ def assert_logout_text():
assert self.window.usernameLabel.text() == "User"
qtbot.wait_until(assert_logout_text)

def test_multiple_flightpath_switching_to_flighttrack_and_logout(self, qtbot):
"""
checks that we can switch in topviews with the multiple flightpath dockingwidget
between local flight track and operations, and we are able to cycle a login/logout
"""
# more operations for the user
for op_name in ["second", "third"]:
assert add_operation(op_name, "description")
assert add_user_to_operation(path=op_name, emailid=self.userdata[0])

self._connect_to_mscolab(qtbot)
modify_config_file({"MSS_auth": {self.url: self.userdata[0]}})
self._login(qtbot, emailid=self.userdata[0], password=self.userdata[2])

# test after activating operation
self._activate_operation_at_index(0)
self.window.actionTopView.trigger()

def assert_active_views():
# check 1 view opened
assert len(self.window.get_active_views()) == 1
qtbot.wait_until(assert_active_views)
topview_0 = self.window.listViews.item(0)
assert topview_0.window.tv_window_exists is True
topview_0.window.setAttribute(QtCore.Qt.WA_DeleteOnClose)

def assert_attribute():
assert topview_0.window.testAttribute(QtCore.Qt.WA_DeleteOnClose)
qtbot.wait_until(assert_attribute)

# open multiple flightpath first window
topview_0.window.cbTools.currentIndexChanged.emit(6)

def assert_dock_loaded():
assert topview_0.window.docks[5] is not None
qtbot.wait_until(assert_dock_loaded)

# activate all operation, this enables them in the docking widget too
self._activate_operation_at_index(1)
self._activate_operation_at_index(2)
self._activate_operation_at_index(0)
# ToDo refactor to be able to activate/deactivate by the docking widget and that it can be checked

self._activate_flight_track_at_index(0)
with mock.patch("PyQt5.QtWidgets.QMessageBox.warning", return_value=QtWidgets.QMessageBox.Yes):
topview_0.window.close()

def assert_window_closed():
assert topview_0.window.tv_window_exists is False
qtbot.wait_until(assert_window_closed)

def assert_label_text():
# verify logged in
assert self.window.usernameLabel.text() == self.userdata[1]
qtbot.wait_until(assert_label_text)

self.window.mscolab.logout()

def assert_logout_text():
assert self.window.usernameLabel.text() == "User"
qtbot.wait_until(assert_logout_text)

self._connect_to_mscolab(qtbot)
self._login(qtbot, emailid=self.userdata[0], password=self.userdata[2])
# verify logged in again
qtbot.wait_until(assert_label_text)
# ToDo verify all operations disabled again without a visual check

@mock.patch("PyQt5.QtWidgets.QFileDialog.getSaveFileName",
return_value=(fs.path.join(mscolab_settings.MSCOLAB_DATA_DIR, 'test_export.ftml'),
"Flight track (*.ftml)"))
Expand Down

0 comments on commit a699008

Please sign in to comment.