Skip to content

Commit

Permalink
Merge pull request #182 from launchableinc/ST-872-flavor-option
Browse files Browse the repository at this point in the history
[ST-872] add flavor option for create test session
  • Loading branch information
Konboi authored Apr 2, 2021
2 parents c7f34d1 + 98357ea commit 493d3d1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
22 changes: 19 additions & 3 deletions launchable/commands/record/session.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import click
import os
import json

from ...utils.http_client import LaunchableClient
from ...utils.token import parse_token
Expand All @@ -26,7 +27,15 @@
default=True,
metavar='SESSION_FILE'
)
def session(build_name: str, save_session_file: bool, print_session: bool = True):
@click.option(
"--flavor",
"flavor",
help='flavors',
nargs=2,
type=(str, str),
multiple=True,
)
def session(build_name: str, save_session_file: bool, print_session: bool = True, flavor=[]):
"""
print_session is for barckward compatibility.
If you run this `record session` standalone, the command should print the session ID because v1.1 users expect the beheivior. That is why the flag is default True.
Expand All @@ -38,12 +47,19 @@ def session(build_name: str, save_session_file: bool, print_session: bool = True
"Content-Type": "application/json",
}

client = LaunchableClient(token)
# TODO: check duplicate keys
flavor_dict = {}
for f in flavor:
flavor_dict[f[0]] = f[1]

client = LaunchableClient(token)
try:
session_path = "/intake/organizations/{}/workspaces/{}/builds/{}/test_sessions".format(
org, workspace, build_name)
res = client.request("post", session_path, headers=headers)
res = client.request("post", session_path,
headers=headers, data=json.dumps({
"flavors": flavor_dict,
}))
res.raise_for_status()
session_id = res.json()['id']

Expand Down
13 changes: 11 additions & 2 deletions launchable/commands/subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,16 @@
help='output the rest of subset',
type=str,
)
@click.option(
"--flavor",
"flavor",
help='flavors',
nargs=2,
type=(str, str),
multiple=True,
)
@click.pass_context
def subset(context, target, session_id, base_path: str, build_name: str, rest: str, duration):
def subset(context, target, session_id, base_path: str, build_name: str, rest: str, duration, flavor=[]):
token, org, workspace = parse_token()

if session_id and build_name:
Expand All @@ -68,7 +76,8 @@ def subset(context, target, session_id, base_path: str, build_name: str, rest: s
if build_name:
session_id = read_session(build_name)
if not session_id:
context.invoke(session, build_name=build_name, save_session_file=True, print_session=False)
context.invoke(session, build_name=build_name,
save_session_file=True, print_session=False, flavor=flavor)
session_id = read_session(build_name)
else:
raise click.UsageError(
Expand Down
26 changes: 26 additions & 0 deletions tests/commands/record/test_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from tests.cli_test_case import CliTestCase
import responses # type: ignore
import json


class SessionTest(CliTestCase):

@responses.activate
def test_run_session_without_flavor(self):
result = self.cli("record", "session", "--build", self.build_name)
self.assertEqual(result.exit_code, 0)

payload = json.loads(responses.calls[0].request.body)
self.assert_json_orderless_equal({"flavors": {}}, payload)

@responses.activate
def test_run_session_with_flavor(self):
result = self.cli("record", "session", "--build", self.build_name,
"--flavor", "key", "value", "--flavor", "k", "v")
self.assertEqual(result.exit_code, 0)

payload = json.loads(responses.calls[0].request.body)
self.assert_json_orderless_equal({"flavors": {
"key": "value",
"k": "v",
}}, payload)

0 comments on commit 493d3d1

Please sign in to comment.