Esempio n. 1
0
 def test_past_question(self):
     """Questions with a pub_date in the past are displayed on the
     index page.
     """
     create_question(question_text="Past question.", days=-30)
     response = self.client.get(reverse('polls:index'))
     self.assertContains(response, "No polls are available.")
Esempio n. 2
0
 def test_index_view_with_two_past_question(self):
     create_question(question_text="Past question 1.", days=-30)
     create_question(question_text="Past question 2.", days=-5)
     response = self.client.get(reverse('polls:index'))
     self.assertQuerysetEqual(
         response.context['latest_question_list'],
         ['<Question: Past question 2.>', '<Question: Past question 1.>'])
Esempio n. 3
0
 def test_past_question(self):
     create_question(question_text="Past question.", days=-30)
     response = self.client.get(reverse('polls:index'))
     self.assertQuerysetEqual(
         response.context['latest_question_list'],
         ['<Question: Past question.>']
     )
Esempio n. 4
0
    def test_past_question(self):

        past_question = create_question(question_text='Past Question.',
                                        days=-5)
        url = reverse('polls:detail', args=(past_question.id, ))
        response = self.client.get(url)
        self.assertContains(response, past_question.question_text)
Esempio n. 5
0
 def test_no_questions(self):
     """
     If no questions exist, an appropraite message is displayed.
     """
     repsonse = self.client.get(reverse('polls:index'))
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, "No polls are available.")
Esempio n. 6
0
 def test_two_past_questions(self):
     """ The questions index page may display multiple questions."""
     create_question(question_text="Past question 1.", days=-30)
     create_question(question_text="Past question 2.", days=-5)
     response = self.client.get(reverse('ruth:index'))
     self.assertQuerysetEqual(
         response.context['latest_question_list'],
         ['<Question: Past question 2.>', '<Question: Past question 1.>'])
Esempio n. 7
0
 def test_index_view_with_a_past_poll(self):
     """
     Polls with a pub_date in the past should be displayed on the index page.
     """
     create_poll(question="Past poll.", days=-30)
     response = self.client.get(reverse('polls:index'))
     self.assertQuerysetEqual(response.context['latest_poll_list'],
                              ['<Poll: Past poll.>'])
Esempio n. 8
0
 def test_future_question(self):
     """
     The detail view of a question with a pub_date in the future returns a 404 not found
     """
     future_question = create_question(question_text="Future question.", days=5)
     url = reverse('polls:detail', args=(future_question.id,))
     response = self.client.get(url)
     self.assertEqual(response.status_code, 404)
Esempio n. 9
0
 def test_index_view_with_no_questions(self):
     """
     If no questions exist, an appropriate message should be displayed.
     """
     response = self.client.get(reverse('polls:index'))
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, "No polls are available.")
     self.assertQuerysetEqual(response.context['latest_question_list'], [])
Esempio n. 10
0
 def test_no_questions(self):
     """
     If no questions exist, an appropriate message is displayed.
     """
     response = self.client.get(reverse('polls:index'))
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, "No polls are here :( ")
     self.assertQuerysetEqual(response.context['latest_question_list'], [])
Esempio n. 11
0
 def test_vote_with_a_future_poll(self):
     """
     Voting on a poll with with a pub_date in the future should not be allowed.
     """
     future_poll = create_poll(question="Future poll.", days=30)
     response = self.client.get(
         reverse('polls:vote', args=(future_poll.id, )))
     self.assertEqual(response.status_code, 404)
Esempio n. 12
0
    def test_future_question(self):
        """Even if both past and future questions exist, only past questions are displayed."""
        create_question(question_text="Past question.", days=-30)
        create_question(question_text="Future question.", days=30)

        response = self.client.get(reverse('ruth:index'))
        self.assertQuerysetEqual(response.context['latest_question_list'],
                                 ['<Question: Past question.>'])
Esempio n. 13
0
 def test_detail_view_with_a_past_poll(self):
     """
     The detail view of a poll with a pub_date in the past should display
     the poll's question.
     """
     past_poll = create_poll(question='Past Poll.', days=-5)
     response = self.client.get(
         reverse('polls:detail', args=(past_poll.id, )))
     self.assertContains(response, past_poll.question, status_code=200)
Esempio n. 14
0
 def test_detail_view_with_a_future_poll(self):
     """
     The detail view of a poll with a pub_date in the future should
     return a 404 not found.
     """
     future_poll = create_poll(question='Future poll.', days=5)
     response = self.client.get(
         reverse('polls:detail', args=(future_poll.id, )))
     self.assertEqual(response.status_code, 404)
Esempio n. 15
0
 def test_two_past_tweets(self):
     """the tweet index page may display multiple tweets"""
     create_tweet(tweet_text="Past tweet 1.", days=-30)
     create_tweet(tweet_text="Past tweet 2.", days=-5)
     response = self.client.get(reverse('twitter:index'))
     self.assertQuerysetEqual(
         response.context['latest_tweet_list'],
         ['<Tweet: Past tweet 2.>', '<Tweet: Past tweet 1.>']
     )
Esempio n. 16
0
 def test_future_tweet_and_past_tweet(self):
     """if both future and past tweets exist, only past tweets are displayed"""
     create_tweet(tweet_text="Past tweet.", days=-30)
     create_tweet(tweet_text="Future tweet.", days=30)
     response = self.client.get(reverse('twitter:index'))
     self.assertQuerysetEqual(
         response.context['latest_tweet_list'],
         ['<Tweet: Past tweet.>']
     )
Esempio n. 17
0
 def test_future_question(self):
     """
     Questions with a pub_date in the future aren't displayed on
     the index page.
     """
     create_question(question_text="Future question.", days=30)
     response = self.client.get(reverse('polls:index'))
     self.assertContains(response, "No polls are available.")
     self.assertQuerysetEqual(response.context['latest_question_list'], [])
Esempio n. 18
0
 def test_past_question(self):
     """
     The detail view of a question with a pub_date in the past
     displays the question's text.
     """
     past_question = create_question(question_text='Past Question.', days=-5)
     url = reverse('polls:detail', args=(past_question.id,))
     response = self.client.get(url)
     self.assertContains(response, past_question.question_text)
Esempio n. 19
0
 def test_past_question(self):
     """
     Questions with a pub_date in the past are displayed on the
     index page.
     """
     create_question(question_text="Past question.", days=-30)
     response = self.client.get(reverse('polls:index'))
     self.assertQuerysetEqual(response.context['latest_question_list'],
                              ['<Question: Past question.>'])
Esempio n. 20
0
 def test_past_question(self):
     """
     Questions with a pub_date in the past are displayed on the
     index page.
     """
     past_question = create_question(
         question_text="A question of the past?", days=-5)
     url = reverse('polls:detail', args=(future_question.id, ))
     response = self.client.get(url)
     self.assertEqual(response, past_question.question_text)
Esempio n. 21
0
 def test_future_question(self):
     """
     Questions with a pub_date in the future aren't displayed on
     the index page.
     """
     future_question = create_question(
         question_text="I'll see you in the future!", days=5)
     url = reverse('polls:detail', args=(future_question.id, ))
     response = self.client.get(url)
     self.assertEqual(response.status_code, 404)
Esempio n. 22
0
 def test_future_question_and_past_question(self):
     """
     Even if both past and future questions exist, only past questions
     are displayed.
     """
     create_question(question_text="A question of the past?", days=-30)
     create_question(question_text="I'll see you in the future!", days=30)
     response = self.client.get(reverse('polls:index'))
     self.assertQuerysetEqual(response.context['latest_question_list'],
                              ['<Question: A question of the past?>'])
Esempio n. 23
0
 def test_index_view_with_two_past_polls(self):
     """
     The polls index page may display multiple polls.
     """
     create_poll(question="Past poll 1.", days=-30)
     create_poll(question="Past poll 2.", days=-5)
     response = self.client.get(reverse('polls:index'))
     self.assertQuerysetEqual(
         response.context['latest_poll_list'],
         ['<Poll: Past poll 2.>', '<Poll: Past poll 1.>'])
Esempio n. 24
0
 def test_index_view_with_future_poll_and_past_poll(self):
     """
     Even if both past and future polls exist, only past polls should be
     displayed.
     """
     create_poll(question="Past poll.", days=-30)
     create_poll(question="Future poll.", days=30)
     response = self.client.get(reverse('polls:index'))
     self.assertQuerysetEqual(response.context['latest_poll_list'],
                              ['<Poll: Past poll.>'])
Esempio n. 25
0
 def test_index_view_with_a_future_poll(self):
     """
     Polls with a pub_date in the future should not be displayed on the
     index page.
     """
     create_poll(question="Future poll.", days=30)
     response = self.client.get(reverse('polls:index'))
     self.assertContains(response,
                         "No polls are available.",
                         status_code=200)
     self.assertQuerysetEqual(response.context['latest_poll_list'], [])
Esempio n. 26
0
 def test_two_past_questions(self):
     """
     The questions index page may display multiple questions.
     """
     create_question(question_text="A question of the past?", days=-30)
     create_question(
         question_text="The beginning is the end is the beginning", days=-6)
     response = self.client.get(reverse('polls:index'))
     self.assertQuerysetEqual(response.context['latest_question_list'], [
         '<Question: A question of the past?>, <Question: The beginning is the end is the beginning>'
     ])
Esempio n. 27
0
 def test_vote_with_a_past_poll(self):
     """
     Voting on a poll with with a pub_date in the past should be allowed.
     """
     past_poll = create_poll(question="Past poll.", days=-30)
     choice = create_choice(past_poll)
     response = self.client.post(
         reverse('polls:vote', args=(past_poll.id, )),
         {'choice': choice.id},
     )
     self.assertEqual(response.status_code, 302)
     self.assertEqual(past_poll.choice_set.get(pk=choice.id).votes, 1)
     self.assertEqual(str(past_poll.choice_set.get(pk=choice.id)), "choice")
Esempio n. 28
0
 def test_vote_with_a_past_poll_and_a_non_existent_choice(self):
     """
     Voting on a poll with with a pub_date in the past and a non-existent choice
     should return a 404 not found.
     """
     past_poll = create_poll(question="Past poll.", days=-30)
     choice = create_choice(past_poll)
     response = self.client.post(
         reverse('polls:vote', args=(past_poll.id, )),
         {'choice': choice.id + 1},
     )
     self.assertContains(response,
                         "You didn&#39;t select a choice.",
                         status_code=200)
Esempio n. 29
0
class QuestionIndexViewTests(TestCase):
    def test_no_question(self):
        response = self.client.get(reverse('polls:index'))
        self.assertEqual(response.status_code,200)
        self.assertContains(response,"No polls are available.")
        self.assertQuerysetEqual(response.context['latest_question_list'],[])
    def test_past_question(self):
         def test_past_question(self):
        """
        Questions with a pub_date in the past are displayed on the
        index page.
        """
        create_question(question_text="Past question.", days=-30)
        response = self.client.get(reverse('polls:index'))
        self.assertQuerysetEqual(
            response.context['latest_question_list'],
            ['<Question: Past question.>']
        )
Esempio n. 30
0
def profile_edit(request):
    profile = Profile.objects.get(user=request.user)
    if request.method == 'POST':
        userform = UserForm(request.POST, instance=request.user)
        profileform = ProfileForm(request.POST,
                                  request.FILES,
                                  instance=profile)
        if userform.is_valid() and profileform.is_valid():
            userform.save()
            myprofile = profileform.save(commit=False)
            myprofile.user = request.user
            myprofile.save()
            return redirect(reverse('accounts:profile'))
    else:
        userform = UserForm(instance=request.user)
        profileform = ProfileForm(instance=profile)
    return render(request, 'accounts/profile_edit.html', {
        'userform': userform,
        'profileform': profileform
    })