Skip to content
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
5 changes: 3 additions & 2 deletions launchable/commands/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from ..app import Application
from ..utils.launchable_client import LaunchableClient
from ..utils.session import parse_session, read_build, read_session
from ..utils.session import read_build, read_session, validate_session_format


def require_session(
Expand All @@ -22,7 +22,7 @@ def require_session(
See https://github.com/launchableinc/cli/pull/342
"""
if session:
parse_session(session) # make sure session is in the right format
validate_session_format(session)
return session

session = read_session(require_build())
Expand Down Expand Up @@ -89,6 +89,7 @@ def find_or_create_session(
from .record.session import session as session_command

if session:
validate_session_format(session)
_check_observation_mode_status(session, is_observation, tracking_client=tracking_client, app=context.obj)
return session

Expand Down
2 changes: 1 addition & 1 deletion launchable/commands/record/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@click.option(
'--session',
'session',
help='Test session ID',
help='In the format builds/<build-name>/test_sessions/<test-session-id>',
type=str,
)
@click.argument('attachments', nargs=-1) # type=click.Path(exists=True)
Expand Down
2 changes: 1 addition & 1 deletion launchable/commands/record/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _validate_group(ctx, param, value):
@click.option(
'--session',
'session',
help='Test session ID',
help='In the format builds/<build-name>/test_sessions/<test-session-id>',
type=str,
)
@click.option(
Expand Down
2 changes: 1 addition & 1 deletion launchable/commands/subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
@click.option(
'--session',
'session',
help='Test session ID',
help='In the format builds/<build-name>/test_sessions/<test-session-id>',
type=str,
)
@click.option(
Expand Down
6 changes: 5 additions & 1 deletion launchable/utils/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,15 @@ def clean_session_files(days_ago: int = 0) -> None:
remove_session()


def parse_session(session: str):
def validate_session_format(session: str):
# session format:
# builds/<build name>/test_sessions/<test session id>
if session.count("/") != 3:
raise ParseSessionException(session=session)


def parse_session(session: str):
validate_session_format(session)

_, build_name, _, session_id = session.split("/")
return build_name, session_id
19 changes: 17 additions & 2 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import tempfile
from unittest import TestCase

from launchable.utils.session import (SESSION_DIR_KEY, clean_session_files, parse_session, read_build,
read_session, remove_session, write_build, write_session)
from launchable.utils.exceptions import ParseSessionException
from launchable.utils.session import (SESSION_DIR_KEY, clean_session_files, parse_session, read_build, read_session,
remove_session, validate_session_format, write_build, write_session)


class SessionTestClass(TestCase):
Expand Down Expand Up @@ -44,3 +45,17 @@ def test_parse_session(self):

with self.assertRaises(Exception):
parse_session("hoge/fuga")

def test_validate_session_format(self):
# Test with a valid session format
validate_session_format("builds/build-name/test_sessions/123")

# Test with invalid session formats
invalid_sessions = [
"123", # Only id
"workspaces/mothership/builds/123/test_sessions/13" # Too many parts
]

for invalid_session in invalid_sessions:
with self.assertRaises(ParseSessionException):
validate_session_format(invalid_session)
Loading