Skip to content

Commit

Permalink
Added modified_on updating to counters.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean O'Connor committed Feb 20, 2012
1 parent 2a59e01 commit f020b9d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion albertson/base.py
Expand Up @@ -210,8 +210,11 @@ def refresh(self):
def increment(self, amount=1):
item = self.dynamo_item
item.add_attribute('count', amount)
item.put_attribute(
'modified_on',
datetime.utcnow().replace(microsecond=0).isoformat()
)
result = item.save(return_values='UPDATED_NEW')
print result
item.update(result['Attributes'])

return self.count
4 changes: 4 additions & 0 deletions tests/base.py
Expand Up @@ -352,11 +352,15 @@ def test_counter_increment(self):
self.assertEqual(item, counter.dynamo_item)
old_count = counter.count

now = datetime.utcnow().replace(microsecond=0)
counter.increment()

expected_count = old_count + 1
self.assertEqual(expected_count, counter.count)

fetched_item = table.get_item(item.hash_key)
modified_offset = datetime.strptime(fetched_item['modified_on'], ISO_FORMAT) - now
self.assertEqual(expected_count, fetched_item['count'])
self.assertEqual(fetched_item, counter.dynamo_item)
self.assertLess(modified_offset.seconds, 2)
self.assertGreaterEqual(modified_offset.seconds, 0)

0 comments on commit f020b9d

Please sign in to comment.