コード例 #1
0
ファイル: avatar_tests.py プロジェクト: sudhirj/boragle
 def make_boragle(self):
     boragle = Boragle(name = "Koi", 
             desc= "Boragle about koi fish", 
             slugs = ["koi","koi-fish"],
             creator = self.creator)
     boragle.put()
     return boragle
コード例 #2
0
ファイル: web_question_tests.py プロジェクト: sudhirj/boragle
class QuestionTests(base.ExtendedTestCase):
    def setUp(self):
        super(QuestionTests, self).setUp()
        self.boragle = Boragle(name='test1', slugs = ['t1'], desc = 'desc', creator = self.creator)
        self.boragle.put()
        self.avatar = Avatar(boragle = self.boragle, creator = self.creator)
        self.avatar.put()
        self.question = Question(boragle = self.boragle, text = "why ?", creator = self.avatar)
        self.question.put()
        
    def test_creation(self):
        self.app.post('/t1/ask', dict(text = 'why? why? why?', details = 'simply, maybe'))
        question = Question.find_by_slug('why-why-why')
        self.assertTrue(question)
        self.assertEqual("why? why? why?",question.text)
        self.assertEqual("simply, maybe",question.details)
        self.assertEqual(self.creator.name,question.creator.creator.name)
    

    def test_creation_security(self):
        self.logout()
        self.app.post('/t1/ask', dict(text = 'why? why? why?', details = 'simply, maybe'), 
                status = 403)
        
    def test_answering_question(self):
        self.app.post(self.question.url, dict(answer = 'zimbly'))
        question = Question.get(self.question.key())
        self.assertEqual('zimbly', question.answers[0].text)
        self.assertEqual(self.creator.name, question.answers[0].creator.name)
        self.assertEqual(1, question.answer_count)
        
    def test_answering_question_security(self):
        self.logout()
        self.app.post(self.question.url, dict(answer = 'zimbly'), status = 403)
    
    def test_smoke_question_page(self):
        self.app.get(self.question.url)
    
    def test_voting_security(self):
        answer = Answer.create(question = self.question, text= 'fake answer', creator = self.avatar)
        self.app.get(answer.voting_url+'/up', status = 302)
        answer = Answer.get(answer.key())
        self.assertEqual(answer.vote_count, 1)
        self.logout()
        self.app.get(answer.voting_url+'/down', status = 302)
        answer = Answer.get(answer.key())
        self.assertEqual(answer.vote_count, 1)        
        
    
    def test_voting_up(self):
        answer = Answer.create(question = self.question, text= 'fake answer', creator = self.avatar)
        self.app.get(answer.voting_url+'/up', status = 302)
        answer = Answer.get(answer.key())
        self.assertEqual(answer.vote_count,1)
        self.app.get(answer.voting_url+'/down', status = 302)
        answer = Answer.get(answer.key())
        self.assertEqual(answer.vote_count,-1)
        
        
        
コード例 #3
0
ファイル: web_boragle_tests.py プロジェクト: sudhirj/boragle
 def test_duplicate_urls_are_not_allowed(self):
     count = Boragle.all().count()
     self.app.post('/new', dict(name="test1", url = ".t1 tes#t", desc = 'desc'))
     self.assertEqual(count+1,Boragle.all().count())
     response = self.app.post('/new', dict(name="duplicate1", url = ".t1 tes#t", desc = 'duplicate desc'), status = 200)
     response.mustcontain("This url is already in use")
     self.assertEqual(count+1,Boragle.all().count())
コード例 #4
0
ファイル: main.py プロジェクト: sudhirj/boragle
 def post(self):
     assert self.creator
     name = self.read('name')
     if not (name and name.strip()): raise PostingError("Please enter a name for your Boragle") 
     slug = utils.slugify(self.read('url'))
     if slug == '': slug = utils.slugify(name)
     if Boragle.find_by_slug(slug): raise PostingError('This url is already in use.')
     new_boragle = Boragle(name = self.read('name'),
             slugs = [slug],
             desc = self.read('desc'),
             creator = self.creator)
     new_boragle.put()
     self.redirect(new_boragle.url)
コード例 #5
0
ファイル: main.py プロジェクト: sudhirj/boragle
 def get(self, boragle_slug, question_slug, answer_key,vote ):
     boragle = Boragle.find_by_slug(boragle_slug)
     avatar = self.get_avatar_for_boragle(boragle)
     question = boragle.find_question_by_slug(question_slug)
     answer = question.get_answer(answer_key)
     answer.vote(avatar, vote == 'up')
     self.redirect(question.url)
コード例 #6
0
ファイル: web_question_tests.py プロジェクト: sudhirj/boragle
 def setUp(self):
     super(QuestionTests, self).setUp()
     self.boragle = Boragle(name='test1', slugs = ['t1'], desc = 'desc', creator = self.creator)
     self.boragle.put()
     self.avatar = Avatar(boragle = self.boragle, creator = self.creator)
     self.avatar.put()
     self.question = Question(boragle = self.boragle, text = "why ?", creator = self.avatar)
     self.question.put()
コード例 #7
0
ファイル: boragle_tests.py プロジェクト: sudhirj/boragle
 def test_get_latest_boragles(self):
     koi_boragle = self.make_boragle()
     koi_boragle.put()
     Boragle(name = "Koi2", desc= "Boragle about koi fish2", slugs = ["koi2"], creator = self.creator).put()
     Boragle(name = "Koi3", desc= "Boragle about koi fish3", slugs = ["koi3"], creator = self.creator).put()
     boragles = Boragle.get_latest(count = 2)
     self.assertEqual(2,len(boragles))
     self.assertEqual(boragles[0].slug,"koi3")
     self.assertEqual(boragles[1].slug,"koi2")
コード例 #8
0
ファイル: web_boragle_tests.py プロジェクト: sudhirj/boragle
 def test_leaving_url_empty_slugs_the_name(self):
     import utils
     name="test1 is the new thing"
     slug = utils.slugify(name)
     self.app.post('/new', dict(name=name, url = "  ", desc = 'desc'))
     new_boragle = Boragle.find_by_slug(slug)
     self.assertTrue(new_boragle)
     self.assertEqual(name,new_boragle.name)
     self.assertEqual("desc",new_boragle.desc)
コード例 #9
0
ファイル: main.py プロジェクト: sudhirj/boragle
 def get(self, boragle_slug):
     boragle = Boragle.find_by_slug(boragle_slug)
     avatar = Avatar.find_or_create(boragle=boragle, creator=self.creator) if self.creator else None
     start = self.read('start') or None
     questions = boragle.get_latest_questions(count = settings.question_page_size + 1, start = start)
     next = questions.pop().sort_date if len(questions) == settings.question_page_size + 1 else None
     self.render_template('boragle', dict(boragle=boragle,
                                             questions = questions,
                                             authdetails = utils.authdetails(boragle.url),
                                             creator = avatar,
                                             next = next))
コード例 #10
0
ファイル: main.py プロジェクト: sudhirj/boragle
 def post(self, boragle_slug):
     boragle = Boragle.find_by_slug(boragle_slug)
     avatar = self.get_avatar_for_boragle(boragle)
     text = self.read('text')
     if not text or not text.strip(): raise PostingError('Please enter a question.')
     assert avatar
     new_question = Question(text = text,
             details = self.read('details'),
             boragle = boragle,
             creator = avatar)
     new_question.put()
     self.redirect(new_question.url)
コード例 #11
0
ファイル: main.py プロジェクト: sudhirj/boragle
 def get(self):
     self.render_template('main', dict(boragles = Boragle.get_latest(count = 5),
                             authdetails = utils.authdetails(),
                             creator = self.creator))
コード例 #12
0
ファイル: main.py プロジェクト: sudhirj/boragle
 def get(self, boragle_slug):
     boragle = Boragle.find_by_slug(boragle_slug)
     avatar = self.get_avatar_for_boragle(boragle)
     self.render_template('ask-question', dict(boragle = boragle,
                         authdetails = utils.authdetails(boragle.url+'/'+settings.urls['ask']),
                         creator = avatar))
コード例 #13
0
ファイル: boragle_tests.py プロジェクト: sudhirj/boragle
 def test_finder_returns_none_no_match(self):
     self.assertEqual(None,Boragle.find_by_slug('blah'))
コード例 #14
0
ファイル: boragle_tests.py プロジェクト: sudhirj/boragle
 def test_boragle_saves_vitals(self):
     koi_boragle = self.make_boragle()
     koi_boragle.put()
     boragle = Boragle.find_by_slug('koi')
     self.assertEqual(koi_boragle.name,boragle.name)
     self.assertEqual(koi_boragle.desc,boragle.desc)
コード例 #15
0
ファイル: web_boragle_tests.py プロジェクト: sudhirj/boragle
 def test_creation(self):
     self.app.post('/new', dict(name="test1", url = "t1", desc = 'desc'))
     new_boragle = Boragle.find_by_slug('t1')
     self.assertTrue(new_boragle)
     self.assertEqual("test1",new_boragle.name)
     self.assertEqual("desc",new_boragle.desc)
コード例 #16
0
ファイル: web_boragle_tests.py プロジェクト: sudhirj/boragle
 def test_url_is_slugified_before_save(self):
     self.app.post('/new', dict(name="test1", url = ".t45 tes#t", desc = 'desc'))
     new_boragle = Boragle.find_by_slug('t45-test')
     self.assertTrue(new_boragle)