Skip to content

Commit

Permalink
Merge pull request #66 from diggyk/master
Browse files Browse the repository at this point in the history
Fixed host rename to allow merging
  • Loading branch information
jathanism committed Oct 5, 2015
2 parents ad2a322 + 4d06248 commit 34761ed
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
7 changes: 1 addition & 6 deletions hermes/handlers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,7 @@ def put(self, hostname):
"Missing Required Argument: {}".format(err.message)
)

try:
host = host.update(
hostname=new_hostname,
)
except IntegrityError as err:
raise exc.Conflict(str(err.orig))
host = host.update_name(new_hostname);

json = host.to_dict(self.href_prefix)

Expand Down
23 changes: 22 additions & 1 deletion hermes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,28 @@ def get_open_labors(self):
.order_by(desc(Labor.creation_time))
)

def update_name(self, new_name):
"""Rename an existing host. If the new name exists, merge the entries.
Args:
new_name: the new name for the host
Returns:
either the renamed host or the existing host that was merged
"""
existing_host = (
self.session.query(Host).filter(Host.hostname == new_name).scalar()
)

if not existing_host:
self.update(hostname=new_name)
return self
else:
for event in self.events:
event.update(host_id=existing_host.id)
for labor in self.labors:
labor.update(host_id=existing_host.id)
return existing_host

def href(self, base_uri):
"""Create an HREF value for this object
Expand Down Expand Up @@ -1338,7 +1360,6 @@ def email_quest_updates(cls, quests_updated):
msg
)


def href(self, base_uri):
"""Create an HREF value for this object
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.4.13"
__version__ = "0.4.14"
6 changes: 3 additions & 3 deletions hermes/webapp/src/js/directives/questProgressChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@
var title = raphael.text(0, titleFontSize, "Quest " + data[0].id)
.attr('text-anchor', 'start')
.attr('font-size', titleFontSize)
.attr('font-family', "Montserrat");
.attr('font-family', "Noto Sans");

// add the quest description
var desc = raphael.text(0, legendY)
.attr('text-anchor', 'start')
.attr('font-size', legendFontSize)
.attr('font-family', "Montserrat");
.attr('font-family', "Noto Sans");
wrapText(data[0].description, desc, width *.25);

// draw out the legend on the right
Expand All @@ -105,7 +105,7 @@
var y = legendY + (i * legendSpacing * 1.1);
var text = raphael.text(
x, y, type
).attr('font-size', legendFontSize).attr('font-family', "Montserrat").attr('text-anchor', 'start')
).attr('font-size', legendFontSize).attr('font-family', "Noto Sans").attr('text-anchor', 'start')

var boxX = x - legendSpacing- (legendSpacing/4);
var boxY = y - legendSpacing/2;
Expand Down
18 changes: 17 additions & 1 deletion tests/api_tests/test_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,20 @@ def test_update(tornado_server):
}
)

assert_error(client.update("/hosts/newname"), 400)
assert_error(client.update("/hosts/newname"), 400)


def test_merging(tornado_server):
"""When renaming a server to an existing servername, just merge them"""
client = Client(tornado_server)

client.create("/hosts", hostname="testname")
client.create("/hosts", hostname="newname")

assert_success(
client.update("/hosts/testname", hostname="newname"),
{
"id": 2,
"hostname": "newname"
}
)

0 comments on commit 34761ed

Please sign in to comment.