Skip to content

Commit

Permalink
Merge branch 'log' of https://github.com/Preetam-Das26/MSS into log
Browse files Browse the repository at this point in the history
  • Loading branch information
Preetam-Das26 committed Mar 18, 2024
2 parents 34cab93 + f7295d9 commit 2a695a8
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 2 deletions.
3 changes: 3 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ def generate_initial_config():
SQLALCHEMY_DB_URI = 'sqlite:///' + urljoin(DATA_DIR, 'mscolab.db')
# enable SQLALCHEMY_ECHO
SQLALCHEMY_ECHO = True
# mscolab file upload settings
UPLOAD_FOLDER = fs.path.join(DATA_DIR, 'uploads')
MAX_UPLOAD_SIZE = 2 * 1024 * 1024 # 2MB
Expand Down
3 changes: 3 additions & 0 deletions docs/samples/config/mscolab/mscolab_settings.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ GROUP_POSTFIX = "Group"
# SQLite: "sqlite:///<path_to_db>"
SQLALCHEMY_DB_URI = 'sqlite:///' + os.path.join(DATA_DIR, 'mscolab.db')

# Set to True for testing and False for production
SQLALCHEMY_ECHO = False

enable_basic_http_authentication = False

# text to be written in new mscolab based ftml files.
Expand Down
1 change: 0 additions & 1 deletion localbuild/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ requirements:
- netcdf4
- hdf4
- pillow
- pytz
- pyqt >=5.15.0
- qt >=5.15.0
- requests >=2.31.0
Expand Down
1 change: 1 addition & 0 deletions mslib/mscolab/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
APP.config['MSCOLAB_DATA_DIR'] = mscolab_settings.MSCOLAB_DATA_DIR
APP.config['SQLALCHEMY_DATABASE_URI'] = mscolab_settings.SQLALCHEMY_DB_URI
APP.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
APP.config['SQLALCHEMY_ECHO'] = mscolab_settings.SQLALCHEMY_ECHO
APP.config['UPLOAD_FOLDER'] = mscolab_settings.UPLOAD_FOLDER
APP.config['MAX_CONTENT_LENGTH'] = mscolab_settings.MAX_UPLOAD_SIZE
APP.config['SECRET_KEY'] = mscolab_settings.SECRET_KEY
Expand Down
3 changes: 3 additions & 0 deletions mslib/mscolab/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class default_mscolab_settings:
# MYSQL CONNECTION STRING: "mysql+pymysql://<username>:<password>@<host>:<port>/<db_name>?charset=utf8mb4"
SQLALCHEMY_DB_URI = 'sqlite:///' + os.path.join(DATA_DIR, 'mscolab.db')

# Set to True for testing and False for production
SQLALCHEMY_ECHO = False

# mscolab file upload settings
UPLOAD_FOLDER = os.path.join(DATA_DIR, 'uploads')
MAX_UPLOAD_SIZE = 2 * 1024 * 1024 # 2MB
Expand Down
1 change: 1 addition & 0 deletions mslib/mscolab/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

class AwareDateTime(sqlalchemy.types.TypeDecorator):
impl = sqlalchemy.types.DateTime
cache_ok = True

def process_bind_param(self, value, dialect):
if value is not None:
Expand Down
81 changes: 80 additions & 1 deletion tests/_test_mscolab/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,88 @@
limitations under the License.
"""
import pytest
import datetime
import textwrap
from zoneinfo import ZoneInfo

from mslib.mscolab.server import register_user
from mslib.mscolab.models import User
from mslib.mscolab.models import AwareDateTime, User, Permission, Operation, Message, Change


def test_aware_datetime_conversion():
aware_datetime_type = AwareDateTime()
curr_time = datetime.datetime.now(tz=datetime.timezone.utc)

result_bind = aware_datetime_type.process_bind_param(curr_time, None)
assert result_bind is not None
assert result_bind == curr_time

result_result = aware_datetime_type.process_result_value(curr_time, None)
assert result_result is not None
assert result_result == curr_time

result_none = aware_datetime_type.process_bind_param(None, None)
assert result_none is None

cet_time = datetime.datetime.now(tz=ZoneInfo("CET"))
result_cet = aware_datetime_type.process_bind_param(cet_time, None)
assert result_cet == cet_time
assert result_cet is not None


def test_permission_creation():
permission = Permission(1, 1, "admin")

assert permission.u_id == 1
assert permission.op_id == 1
assert permission.access_level == "admin"


@pytest.mark.parametrize("access_level", ["collaborator", "viewer", "creator"])
def test_permission_repr_values(access_level):
permission = Permission(1, 1, access_level)
expected_repr = textwrap.dedent(f'''\
<Permission u_id: {1}, op_id:{1}, access_level: {access_level}>''').strip()

assert repr(permission).strip() == expected_repr


def test_operation_creation():
operation = Operation("/path/to/operation", "Description of the operation", category="test_category")

assert operation.path == "/path/to/operation"
assert operation.description == "Description of the operation"
assert operation.category == "test_category"
assert operation.active is True


def test_operation_repr():
operation = Operation("/path/to/operation", "Description of the operation", category="test_category")
expected_repr = f'<Operation path: {"/path/to/operation"}, desc: {"Description of the operation"},' \
f' cat: {"test_category"}, active: True, ' \
f'last_used: {operation.last_used}> '

assert repr(operation) == expected_repr


def test_message_creation():
message = Message(1, 1, "Hello, this is a test message", "TEXT", None)

assert message.op_id == 1
assert message.u_id == 1
assert message.text == "Hello, this is a test message"
assert message.message_type == "TEXT"
assert message.reply_id is None


def test_change_creation():
change = Change(1, 1, "#abcdef123456", "v1.0", "Initial commit")

assert change.op_id == 1
assert change.u_id == 1
assert change.commit_hash == "#abcdef123456"
assert change.version_name == "v1.0"
assert change.comment == "Initial commit"


class Test_User:
Expand Down

0 comments on commit 2a695a8

Please sign in to comment.