def testQueries(self):
        # log in user one
        self.loginUser('*****@*****.**')

        # create two Questions
        Question1 = Question(title="Question 1")
        Question1.put()
        Question2 = Question(title="Question 2")
        Question2.put()

        # log in user two
        self.loginUser('*****@*****.**')

        # create two more Questions
        Question3 = Question(title="Question 3")
        Question3.put()
        Question4 = Question(title="Question 4")
        Question4.put()

        # Get all Questions
        all_Questions = list(Question.all_questions())

        # Make sure there are 4 Questions in total
        assert len(all_Questions) == 4 

        # Make sure they're in the right order
        assert all_Questions == [Question4, Question3, Question2, Question1]

        # Make sure we only get two for user2, and that they're the right Questions
        user2_Questions = list(Question.all_questions_by_user())

        assert len(user2_Questions) == 2
        assert user2_Questions == [Question4, Question3]

        # Test all Questions shown up
        resp = self.testapp.get('/questions')
        assert 'Question 1' in resp.body
        assert 'Question 2' in resp.body
        assert 'Question 3' in resp.body
        assert 'Question 4' in resp.body
         
        # Test Questions_created_by_user
        resp = self.testapp.get('/questions?=mine')
#         assert 'Question 1' not in resp.body
#         assert 'Question 2' not in resp.body
#         assert 'Question 3' in resp.body
#         assert 'Question 4' in resp.body
         
        # Test 'edit' link exists
        assert 'Edit' in resp.body
示例#2
0
class QuestionModelTests(GaeTestCase):
    def setUp(self):
        super(QuestionModelTests, self).setUp()

        self.question1 = Question()
        self.question1.text = 'Fake text'
        self.question1.category = 'adm'
        self.question1.question_number = 120
        self.question1.put()
        self.question2 = Question()
        self.question2.text = 'Fake text'
        self.question2.category = 'fai'
        self.question2.question_number = 121
        self.question2.put()
        self.question3 = Question()
        self.question3.text = 'Fake text'
        self.question3.category = 'int'
        self.question3.question_number = 122
        self.question3.put()

    def test_pretty_category_returns_properly(self):
        self.assertEqual('Administration (Leadership)', self.question1.pretty_category)

    def test_get_all_questions_returns_all_questions(self):
        self.assertEqual(3, len(Question.get_all_questions()))

    def test_get_all_questions_ordered_returns_ascending_order(self):
        questions = Question.get_all_questions(True)
        self.assertEqual(120, questions[0].question_number)
        self.assertEqual(121, questions[1].question_number)
        self.assertEqual(122, questions[2].question_number)
示例#3
0
    def testQueries(self):
        # log in user one
        self.loginUser('*****@*****.**')

        # create two Questions
        Question1 = Question(title="Question 1")
        Question1.put()
        Question2 = Question(title="Question 2")
        Question2.put()

        # log in user two
        self.loginUser('*****@*****.**')

        # create two more Questions
        Question3 = Question(title="Question 3")
        Question3.put()
        Question4 = Question(title="Question 4")
        Question4.put()

        # Get all Questions
        all_Questions = list(Question.all_questions())

        # Make sure there are 4 Questions in total
        assert len(all_Questions) == 4

        # Make sure they're in the right order
        assert all_Questions == [Question4, Question3, Question2, Question1]

        # Make sure we only get two for user2, and that they're the right Questions
        user2_Questions = list(Question.all_questions_by_user())

        assert len(user2_Questions) == 2
        assert user2_Questions == [Question4, Question3]

        # Test all Questions shown up
        resp = self.testapp.get('/questions')
        assert 'Question 1' in resp.body
        assert 'Question 2' in resp.body
        assert 'Question 3' in resp.body
        assert 'Question 4' in resp.body

        # Test Questions_created_by_user
        resp = self.testapp.get('/questions?=mine')
        #         assert 'Question 1' not in resp.body
        #         assert 'Question 2' not in resp.body
        #         assert 'Question 3' in resp.body
        #         assert 'Question 4' in resp.body

        # Test 'edit' link exists
        assert 'Edit' in resp.body