Skip to content

Commit

Permalink
Tidied up question API.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahume committed Nov 24, 2012
1 parent ba5e3db commit 66c8dee
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/data/__init__.py
Expand Up @@ -30,7 +30,7 @@ def import_users():
u.put()
print row['username']

def import_mp_votes(subset=True):
def import_mp_votes(subset=False):

if MPVote.all().count() > 0:
print "Import already complete"
Expand Down
5 changes: 2 additions & 3 deletions app/main_router.py
Expand Up @@ -10,15 +10,15 @@
from views.constituencies import ConstituencyHandler, ConstituencyListHandler
from views.questions import QuestionHandler, QuestionListHandler, UserUnanwseredQuestionsListHandler
from views.votes import UserVoteListHandler, MPVoteListHandler, UserVoteHandler
from views.importer import ImportQuestionsHandler, ImportMPVotesHandler, ImportUsersHandler, DeleteHandler
from views.importer import ImportMPVotesHandler, ImportUsersHandler

def main():

logging.getLogger().setLevel(logging.DEBUG)
application = webapp.WSGIApplication([

('/users/(.*)/votes/(.*)', UserVoteHandler),
('/users/(.*)/questions/unanwsered', UserUnanwseredQuestionsListHandler),
('/users/(.*)/questions', UserUnanwseredQuestionsListHandler),
('/users/(.*)/votes', UserVoteListHandler),
('/users/(.*)', UserProfileHandler),
('/users', UserListHandler),
Expand All @@ -36,7 +36,6 @@ def main():
# Admin importing tools
('/import/mpvotes', ImportMPVotesHandler),
('/import/users', ImportUsersHandler),
('/import/delete', DeleteHandler),


], debug=True)
Expand Down
9 changes: 0 additions & 9 deletions app/views/importer.py
Expand Up @@ -9,11 +9,6 @@
from data import import_mp_votes, import_users


class ImportQuestionsHandler(webapp.RequestHandler):
def get(self):
import_questions()
self.response.out.write("Done")

class ImportMPVotesHandler(webapp.RequestHandler):
def get(self):
import_mp_votes()
Expand All @@ -24,7 +19,3 @@ def get(self):
import_users()
self.response.out.write("Done")

class DeleteHandler(webapp.RequestHandler):
def get(self):
pass

3 changes: 2 additions & 1 deletion app/views/questions.py
Expand Up @@ -40,7 +40,8 @@ def get(self, username):
if q not in anwsered_ids:
filtered_ids.append(q)

response['questions'] = [utils.question_to_dict(q) for q in Question.get(filtered_ids)]
response['answered_questions'] = [utils.question_to_dict(q) for q in Question.get(anwsered_ids)]
response['unanswered_questions'] = [utils.question_to_dict(q) for q in Question.get(filtered_ids)]

self.returnJSON(200, response)

Expand Down
7 changes: 4 additions & 3 deletions test/test.py
Expand Up @@ -2,7 +2,8 @@
import json
import urllib2

hostname = 'http://localhost:8085'
#hostname = 'http://localhost:8085'
hostname = 'http://politmus-api.appspot.com'

class PolitmusAPITest(unittest.TestCase):

Expand Down Expand Up @@ -55,7 +56,7 @@ def test_count(self):
data = self.get_data('/mps?count=2')

self.assertEqual(data['status'], 200)
self.assertEqual(data['total'], 8)
self.assertTrue(data['total'] > 2)
self.assertEqual(data['count'], 2)
self.assertEqual(len(data['mps']), 2)

Expand Down Expand Up @@ -173,4 +174,4 @@ def test_matching_data(self):


if __name__ == '__main__':
unittest.main()
unittest.main()

0 comments on commit 66c8dee

Please sign in to comment.