Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCode Raguet <ignacio.code@gmail.com>2013-09-04 15:07:39 (GMT)
committer Code Raguet <ignacio.code@gmail.com>2013-09-04 15:07:39 (GMT)
commitd3764dbd7faf3d5974767e5cb1787fbee43dd47a (patch)
tree04e7ae5531166d0718e45a542b7684a072fa4f36
parent1f1f8be5a65dfd19eb38a04a2561f1569a7b6854 (diff)
add set_upload_timestamp for PollResultFile
-rw-r--r--webapp/polls/models.py13
-rw-r--r--webapp/polls/tests/poll_result_file_tests.py24
2 files changed, 37 insertions, 0 deletions
diff --git a/webapp/polls/models.py b/webapp/polls/models.py
index a461041..77a45dd 100644
--- a/webapp/polls/models.py
+++ b/webapp/polls/models.py
@@ -1534,6 +1534,19 @@ class PollResultFile(object):
time_string = self.data['upload_timestamp']
return time_string
+ def set_upload_timestamp(self, time_string):
+ data = self.data
+ data['upload_timestamp'] = time_string
+ self._save()
+
+ def _save(self):
+ data = self.data
+ with open(self.file_path, 'w') as file_:
+ j = json.dumps(data, sort_keys=True, indent=4,
+ separators=(',', ': '))
+ file_.seek(0)
+ file_.write(j)
+
def save(self):
name = self.get_file_name()
file_path = self.file_path
diff --git a/webapp/polls/tests/poll_result_file_tests.py b/webapp/polls/tests/poll_result_file_tests.py
index fd0885d..8342443 100644
--- a/webapp/polls/tests/poll_result_file_tests.py
+++ b/webapp/polls/tests/poll_result_file_tests.py
@@ -69,6 +69,30 @@ class PollResultFileTest(MongoTestCase):
result = PollResultFile(file_path)
self.assertEqual(time_string, result.get_upload_timestamp())
+ def test_it_should_set_the_upload_timestamp(self):
+ data = self.data
+ file_path = self.make_temp_file(data)
+ result = PollResultFile(file_path)
+ expected_time_string = "31/12/1999 23:59hs"
+
+ result.set_upload_timestamp(expected_time_string)
+
+ time_string = result.get_upload_timestamp()
+ self.assertEqual(expected_time_string, time_string)
+
+ def test_the_upload_timestamp_should_be_persistent(self):
+ expected_time_string = "31/12/1999 23:59hs"
+ data = self.data
+ file_path = self.make_temp_file(data)
+
+ result = PollResultFile(file_path)
+ result.set_upload_timestamp(expected_time_string)
+ del(result)
+
+ new_result_same_file = PollResultFile(file_path)
+ time_string = new_result_same_file.get_upload_timestamp()
+ self.assertEqual(expected_time_string, time_string)
+
def test_it_should_be_available_for_his_related_poll_when_it_saves(self):
poll = Poll({'name': 'poll'})
poll_id = str(poll.save())