Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/webapp
diff options
context:
space:
mode:
authorRogelio Mita <rogeliomita@activitycentral.com>2013-10-03 14:50:05 (GMT)
committer Rogelio Mita <rogeliomita@activitycentral.com>2013-10-03 14:50:05 (GMT)
commit6726b1a581f5483ed8512fdd2aa91af9e3a69d9a (patch)
treeca0598274a459d32ea903bdfbfddf5cdbec24065 /webapp
parentf18e20e4a22eb5e5f31bc22602a2950ced294af9 (diff)
Remove validate method and move the logic to exists method
Diffstat (limited to 'webapp')
-rw-r--r--webapp/polls/models.py13
-rw-r--r--webapp/polls/tests/poll_result_file_tests.py4
2 files changed, 8 insertions, 9 deletions
diff --git a/webapp/polls/models.py b/webapp/polls/models.py
index f4689ed..103feee 100644
--- a/webapp/polls/models.py
+++ b/webapp/polls/models.py
@@ -1551,13 +1551,6 @@ class PollResultFile(object):
file_path = self.file_path
os.remove(file_path)
- def validate(self):
- poll_id = self.data['poll_id']
- poll = Poll.get(poll_id)
- results = poll.get_result_files()
- hashes = [result.hash for result in results]
- return self.hash not in hashes
-
@property
def hash(self):
data = self.get_data()
@@ -1572,4 +1565,10 @@ class PollResultFile(object):
poll = Poll.get(poll_id)
result_path = os.path.join(poll.results_path, self.get_file_name())
exists = os.path.exists(result_path)
+
+ if not exists:
+ results = poll.get_result_files()
+ hashes = [result.hash for result in results]
+ exists = self.hash in hashes
+
return exists
diff --git a/webapp/polls/tests/poll_result_file_tests.py b/webapp/polls/tests/poll_result_file_tests.py
index d19c364..281e44c 100644
--- a/webapp/polls/tests/poll_result_file_tests.py
+++ b/webapp/polls/tests/poll_result_file_tests.py
@@ -185,7 +185,7 @@ class ExistenceTest(MongoTestCase):
result_file.save()
self.assertTrue(result_file.exists())
- def test_it_should_respond_False_when_content_exists_already(self):
+ def test_it_should_respond_True_when_content_exists_already(self):
poll = self.poll
poll_id = poll.id.__str__()
self.assertEqual(0, len(poll.get_result_files()))
@@ -201,7 +201,7 @@ class ExistenceTest(MongoTestCase):
file_path = make_temp_file(data)
duplicated_result_file = PollResultFile(file_path)
- self.assertFalse(duplicated_result_file.validate())
+ self.assertTrue(duplicated_result_file.exists())
class RueeTest(MongoTestCase):