Skip to content

Commit

Permalink
Merge pull request #26 from diggyk/master
Browse files Browse the repository at this point in the history
Add a column that tracks the id of the original labor
  • Loading branch information
gmjosack committed Jul 20, 2015
2 parents bea8f8f + 2791d7f commit 3447067
Show file tree
Hide file tree
Showing 6 changed files with 390 additions and 24 deletions.
12 changes: 11 additions & 1 deletion hermes/handlers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import random
import re
import sqlalchemy
from sqlalchemy import desc
from sqlalchemy import desc, or_
from sqlalchemy.exc import IntegrityError
import string
import time
Expand Down Expand Up @@ -1493,6 +1493,7 @@ def get(self):
"labors": [
{
"id": 23,
"startingLaborId": null,
"href": "/api/v1/labors/23",
"questId": 5,
"hostId": 26,
Expand All @@ -1509,6 +1510,7 @@ def get(self):
}
:query string hostname: (*optional*) filter Labors by a particular hostname
:query string startingLaborId: (*optional*) get Labors by the Id or the Id of the starting labor
:query string hostQuery: (*optional*) the query to send to the plugin to come up with the list of hostnames
:query string userQuest: (*optional*) the user quest to send to the plugin to come up with the list of hostnames
:query boolean open: if true, filter Labors to those still open
Expand All @@ -1521,6 +1523,7 @@ def get(self):
:statuscode 401: The request was made without being logged in.
"""
hostname = self.get_argument("hostname", None)
starting_labor_id = self.get_argument("startingLaborId", None)
open_flag = self.get_argument("open", None)
quest_id = self.get_argument("questId", None)
host_query = self.get_argument("hostQuery", None)
Expand All @@ -1536,6 +1539,12 @@ def get(self):
if quest_id:
labors = labors.filter(Labor.quest_id == quest_id)

if starting_labor_id:
labors = labors.filter(or_(
Labor.id == starting_labor_id,
Labor.starting_labor_id == starting_labor_id
))

if hostname is not None:
try:
host = (
Expand Down Expand Up @@ -1647,6 +1656,7 @@ def get(self, id):
{
"status": "ok",
"id": 23,
"startingLaborId": null,
"questId": 5,
"hostId": 26,
"creationTime": timestamp,
Expand Down
9 changes: 8 additions & 1 deletion hermes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ def question_the_fates(cls, session, events, quest=None):
if fate["creation_type_id"] == event_type.id:
new_labor_dict = {
"host_id": host.id,
"starting_labor_id": (
labor.starting_labor_id
if labor.starting_labor_id
else labor.id
),
"creation_event_id": event.id,
"quest_id": (
labor.quest.id if labor.quest else None
Expand Down Expand Up @@ -1218,6 +1223,7 @@ class Labor(Model):
Attributes:
id: the unique database id
starting_labor_id: the database id of the labor that started chain of intermediate labors
quest: the Quest to this this Labor belongs
host: the Host to which this Labor pertains
creation_time: when this Labor was created
Expand All @@ -1235,6 +1241,7 @@ class Labor(Model):
__tablename__ = "labors"

id = Column(Integer, primary_key=True)
starting_labor_id = Column(Integer, nullable=True, index=True)
quest_id = Column(
Integer, ForeignKey("quests.id"), nullable=True, index=True
)
Expand Down Expand Up @@ -1333,7 +1340,6 @@ def achieve_many(cls, session, labor_dicts):
)
)


if labor.quest:
# If this labor was part of a quest, let's sort it into the
# quests_updated dict so we can more easily generate emails
Expand Down Expand Up @@ -1425,6 +1431,7 @@ def to_dict(self, base_uri=None):
"""
out = {
"id": self.id,
"startingLaborId": self.starting_labor_id,
"questId": self.quest_id,
"hostId": self.host_id,
"creationTime": str(self.creation_time),
Expand Down
2 changes: 1 addition & 1 deletion hermes/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.2"
__version__ = "0.2.3"
7 changes: 6 additions & 1 deletion tests/api_tests/test_labors.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def test_creation(sample_data1_server):
"hostId": 1,
"href": "/api/v1/labors/1",
"id": 1,
"startingLaborId": None,
"questId": 1},
{"ackTime": None,
"ackUser": None,
Expand All @@ -88,6 +89,7 @@ def test_creation(sample_data1_server):
"hostId": 2,
"href": "/api/v1/labors/2",
"id": 2,
"startingLaborId": None,
"questId": 1},
{"ackTime": None,
"ackUser": None,
Expand All @@ -97,6 +99,7 @@ def test_creation(sample_data1_server):
"hostId": 3,
"href": "/api/v1/labors/3",
"id": 3,
"startingLaborId": None,
"questId": 1}],
},
strip=["creationTime", "completionTime"]
Expand All @@ -118,7 +121,7 @@ def test_update(sample_data1_server):
"/api/v1/quests/1"
)

# make sure a labor was created for this quest
# make sure 3 labors was created for this quest
assert_success(
client.get("/labors"),
{
Expand Down Expand Up @@ -154,6 +157,7 @@ def test_update(sample_data1_server):
"creationEventId": 6,
"hostId": 1,
"id": 4,
"startingLaborId": None,
"questId": None
},
strip=["creationTime"]
Expand All @@ -178,6 +182,7 @@ def test_update(sample_data1_server):
"targetTime": None,
"hostId": 1,
"id": 4,
"startingLaborId": None,
"questId": 1
},
strip=["creationTime", "ackTime"]
Expand Down

0 comments on commit 3447067

Please sign in to comment.