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

Fix all unit tests to run successfully #1101

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

# VSCode
.vscode/
8 changes: 4 additions & 4 deletions TM1py/Services/AuditLogService.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from TM1py.Services.RestService import RestService
from TM1py.Utils import verify_version, deprecated_in_version, odata_track_changes_header, require_data_admin, \
format_url, \
require_version, require_ops_admin
require_version, require_ops_admin, utc_localize_time
from TM1py.Services.ConfigurationService import ConfigurationService


Expand Down Expand Up @@ -74,13 +74,13 @@ def get_entries(self, user: str = None, object_type: str = None, object_name: st
if since:
# If since doesn't have tz information, UTC is assumed
if not since.tzinfo:
since = self.utc_localize_time(since)
since = utc_localize_time(since)
log_filters.append(format_url(
"TimeStamp ge {}", since.strftime("%Y-%m-%dT%H:%M:%SZ")))
if until:
# If until doesn't have tz information, UTC is assumed
if not until.tzinfo:
until = self.utc_localize_time(until)
until = utc_localize_time(until)
log_filters.append(format_url(
"TimeStamp le {}", until.strftime("%Y-%m-%dT%H:%M:%SZ")))
url += "&$filter={}".format(" and ".join(log_filters))
Expand All @@ -93,4 +93,4 @@ def get_entries(self, user: str = None, object_type: str = None, object_name: st
@require_ops_admin
def activate(self):
config = {'Administration': {'AuditLog': {'Enable': True}}}
self.configuration.update_static(config)
self.configuration.update_static(config)
12 changes: 3 additions & 9 deletions TM1py/Services/MessageLogService.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytz
from warnings import warn

from datetime import datetime
Expand All @@ -8,7 +7,7 @@
from TM1py.Services.ObjectService import ObjectService
from TM1py.Services.RestService import RestService
from TM1py.Utils import verify_version, deprecated_in_version, odata_track_changes_header, require_ops_admin, require_data_admin, \
format_url, CaseAndSpaceInsensitiveDict, CaseAndSpaceInsensitiveSet
format_url, CaseAndSpaceInsensitiveDict, CaseAndSpaceInsensitiveSet, utc_localize_time


class MessageLogService(ObjectService):
Expand Down Expand Up @@ -74,14 +73,14 @@ def get_entries(self, reverse: bool = True, since: datetime = None,
if since:
# If since doesn't have tz information, UTC is assumed
if not since.tzinfo:
since = self.utc_localize_time(since)
since = utc_localize_time(since)
log_filters.append(format_url(
"TimeStamp ge {}", since.strftime("%Y-%m-%dT%H:%M:%SZ")))

if until:
# If until doesn't have tz information, UTC is assumed
if not until.tzinfo:
until = self.utc_localize_time(until)
until = utc_localize_time(until)
log_filters.append(format_url(
"TimeStamp le {}", until.strftime("%Y-%m-%dT%H:%M:%SZ")))

Expand Down Expand Up @@ -154,8 +153,3 @@ def get_last_process_message(self, process_name: str, **kwargs) -> Optional[str]
message_log_entry = response_as_list[0]
return message_log_entry['Message']

@staticmethod
def utc_localize_time(timestamp):
timestamp = pytz.utc.localize(timestamp)
timestamp_utc = timestamp.astimezone(pytz.utc)
return timestamp_utc
2 changes: 2 additions & 0 deletions TM1py/Services/ThreadService.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def cancel_all_running(self, **kwargs) -> list:
continue
if thread["Function"] == "GET /Threads":
continue
if thread["Function"] == "GET /api/v1/Threads":
continue
self.cancel(thread["ID"], **kwargs)
canceled_threads.append(thread)
return canceled_threads
13 changes: 3 additions & 10 deletions TM1py/Services/TransactionLogService.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import pytz
from warnings import warn

from datetime import datetime
from typing import Dict

from TM1py.Services.ObjectService import ObjectService
from TM1py.Services.RestService import RestService
from TM1py.Utils import verify_version, deprecated_in_version, odata_track_changes_header, require_data_admin, format_url
from TM1py.Utils import verify_version, deprecated_in_version, odata_track_changes_header, require_data_admin, format_url, utc_localize_time


class TransactionLogService(ObjectService):
Expand All @@ -19,12 +18,6 @@ def __init__(self, rest: RestService):
2)
self.last_delta_request = None

@staticmethod
def utc_localize_time(timestamp):
timestamp = pytz.utc.localize(timestamp)
timestamp_utc = timestamp.astimezone(pytz.utc)
return timestamp_utc

@deprecated_in_version(version="12.0.0")
@odata_track_changes_header
def initialize_delta_requests(self, filter=None, **kwargs):
Expand Down Expand Up @@ -82,13 +75,13 @@ def get_entries(self, reverse: bool = True, user: str = None, cube: str = None,
if since:
# If since doesn't have tz information, UTC is assumed
if not since.tzinfo:
since = self.utc_localize_time(since)
since = utc_localize_time(since)
log_filters.append(format_url(
"TimeStamp ge {}", since.strftime("%Y-%m-%dT%H:%M:%SZ")))
if until:
# If until doesn't have tz information, UTC is assumed
if not until.tzinfo:
until = self.utc_localize_time(until)
until = utc_localize_time(until)
log_filters.append(format_url(
"TimeStamp le {}", until.strftime("%Y-%m-%dT%H:%M:%SZ")))
url += "&$filter={}".format(" and ".join(log_filters))
Expand Down
5 changes: 5 additions & 0 deletions TM1py/Utils/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import http.client as http_client
import json
import math
import pytz
import re
import ssl
import urllib.parse as urlparse
Expand Down Expand Up @@ -1364,6 +1365,10 @@ def read_object_name_from_url(url: str, pattern: str) -> str:

return unquote(match.group(1))

def utc_localize_time(timestamp):
timestamp = pytz.utc.localize(timestamp)
timestamp_utc = timestamp.astimezone(pytz.utc)
return timestamp_utc

class HTTPAdapterWithSocketOptions(HTTPAdapter):
def __init__(self, *args, **kwargs):
Expand Down
23 changes: 14 additions & 9 deletions Tests/ServerService_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from TM1py.Exceptions import TM1pyRestException
from TM1py.Objects import Cube, Dimension, Hierarchy, Process
from TM1py.Services import TM1Service
from TM1py.Utils.Utils import lower_and_drop_spaces


@pytest.mark.skip(reason="Too slow for regular tests. Only run before releases")
Expand Down Expand Up @@ -426,20 +427,24 @@ def test_get_message_log_with_contains_filter_or_2(self):

def test_session_context_default(self):
threads = self.tm1.monitoring.get_threads()
for thread in threads:
if "GET /Threads" in thread["Function"] and thread["Name"] == self.config['tm1srv01']['user']:
self.assertTrue(thread["Context"] == "TM1py")
return
raise Exception("Did not find my own Thread")
self._test_session_context(threads, "TM1py")

def test_session_context_custom(self):
app_name = "Some Application"
with TM1Service(**self.config['tm1srv01'], session_context=app_name) as tm1:
threads = tm1.monitoring.get_threads()
for thread in threads:
if "GET /Threads" in thread["Function"] and thread["Name"] == self.config['tm1srv01']['user']:
self.assertTrue(thread["Context"] == app_name)
return
self._test_session_context(threads, app_name)

def _test_session_context(self, threads: list, app_name: str) -> None:
for thread in threads:
if (
"GET /Threads" in thread["Function"]
or "GET /api/v1/Threads" in thread["Function"]
) and lower_and_drop_spaces(thread["Name"]) == lower_and_drop_spaces(
self.config["tm1srv01"]["user"]
):
self.assertTrue(thread["Context"] == app_name)
return
raise Exception("Did not find my own Thread")

@classmethod
Expand Down