Skip to content

Commit

Permalink
Fixed fate creation cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Digant C Kasundra committed May 19, 2015
1 parent 33ff8c8 commit 588c781
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
13 changes: 9 additions & 4 deletions bin/hermes
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def create_fate(args):
session, args.cc, args.cs
)
else:
creation_event_type = EventType.query().get(args.ct)
creation_event_type = session.query(EventType).get(args.ct)

if not creation_event_type:
print "Creation event type not found."
Expand All @@ -110,14 +110,15 @@ def create_fate(args):
session, args.xc, args.xs
)
else:
completion_event_type = EventType.query().get(args.xt)
completion_event_type = session.query(EventType).get(args.xt)

if not completion_event_type:
print "Completion event type not found."
return

fate = Fate.create(
session, creation_event_type, completion_event_type,
intermediate=args.intermediate,
description=args.description
)

Expand Down Expand Up @@ -398,11 +399,11 @@ def parse_cli_args():
# event type create command line parser
event_type_create_parser = event_type_subparser.add_parser("create")
event_type_create_parser.add_argument(
"-c", "--category", required=True,
"category",
help="Category of the new event type"
)
event_type_create_parser.add_argument(
"-s", "--state", required=True,
"state",
help="State of the new event type"
)
event_type_create_parser.add_argument(
Expand Down Expand Up @@ -446,6 +447,10 @@ def parse_cli_args():
"-xt", "--completion-type", help="The ID of the completion event type",
dest="xt", type=str
)
fate_create_subparser.add_argument(
"-i", "--intermediate", action="store_true",
help="When flagged, this fate only creates a new labor if closing an existing one"
)
fate_create_subparser.add_argument(
"--description", help="The human readable description of this fate",
required=True
Expand Down
5 changes: 4 additions & 1 deletion hermes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ class Fate(Model):
@classmethod
def create(
cls, session,
creation_event_type, completion_event_type, description=None
creation_event_type, completion_event_type, intermediate=False,
description=None
):
"""Create a Fate
Expand All @@ -408,6 +409,7 @@ def create(
an labor creation
completion_event_type: an EventType that will trigger
an labor completion
intermediate: if True, this is a mid-workflow Fate
description: optional description for display
Returns:
Expand All @@ -422,6 +424,7 @@ def create(
obj = cls(
creation_event_type=creation_event_type,
completion_event_type=completion_event_type,
intermediate=intermediate,
description=description
)
obj.add(session)
Expand Down
8 changes: 6 additions & 2 deletions tests/model_tests/test_fates.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def test_creation(sample_data1):
event_type6 = event_types[5]
event_type7 = event_types[6]

models.Fate.create(sample_data1, event_type6, event_type7, "New fate")
models.Fate.create(
sample_data1, event_type6, event_type7, description="New fate"
)
sample_data1.commit()

fates = sample_data1.query(models.Fate).all()
Expand Down Expand Up @@ -44,4 +46,6 @@ def test_duplicate(sample_data1):
event_type2 = event_types[1]

with pytest.raises(IntegrityError):
models.Fate.create(sample_data1, event_type1, event_type2, "Dup fate")
models.Fate.create(
sample_data1, event_type1, event_type2, description="Dup fate"
)

0 comments on commit 588c781

Please sign in to comment.