コード例 #1
0
ファイル: test.py プロジェクト: ProX666/django_tut
    def test_was_published_recently_with_future_question(self):
        """
        was_published_recently() should return False for questions whose
        pub_date is in the future
        """
        time = timezone.now() + datetime.timedelta(days=30)
        future_question = Question(pub_date=time)
        self.assertEqual(future_question.was_published_recently(), False)

	def test_was_published_recently_with_old_question(self):
		"""
		was_published_recently() should return False for questions whose
		pub_date is older than 1 day
		"""
		time = timezone.now() - datetime.timedelta(days=30)
		old_question = Question(pub_date=time)
		self.assertEqual(old_question.was_published_recently(), False)

	def test_was_published_recently_with_recent_question(self):
		"""
		was_published_recently() should return True for questions whose
		pub_date is within the last day
		"""
		time = timezone.now() - datetime.timedelta(hours=1)
		recent_question = Question(pub_date=time)
		self.assertEqual(recent_question.was_published_recently(), True)
コード例 #2
0
ファイル: tests.py プロジェクト: AprilWZhao/pollsApp
 def test_was_published_recently_with_future_question(self):
     """
     was_published_recently() should return False for questions whose pub_date is in the future.
     """
     time = timezone.now()+datetime.timedelta(days=30)
     future_question = Question(pub_date=time)
     self.assertEqual(future_question.was_published_recently(), False)
コード例 #3
0
ファイル: tests.py プロジェクト: grdavis/django_tutorial
 def test_was_published_recently_with_old_question(self):
 	"""
 	should return False if the question is older than a day
 	"""
 	time = timezone.now() - datetime.timedelta(days=1)
 	past_question = Question(pub_date=time)
 	self.assertEqual(past_question.was_published_recently(), False)
コード例 #4
0
ファイル: tests.py プロジェクト: aldraco/django-app
 def test_was_published_recently_with_recent_question(self):
     """
 was_published_recently() should return True for q's whose pub_dates are within the last day
 """
     one_hour_ago = timezone.now() - datetime.timedelta(hours=1)  # one hour ago
     recent_question = Question(pub_date=one_hour_ago)
     self.assertEqual(recent_question.was_published_recently(), True)
コード例 #5
0
ファイル: tests.py プロジェクト: philmui/django-poll
class QuestionModelTest(TestCase):

    def setUp(self):
        self.q1 = Question()
        self.q1.question_text = "What is your question?"
        self.q1.pub_date = timezone.now()
        self.q1.save()

        self.q2 = Question()
        self.q2.question_text = "What is your next question?"
        self.q2.pub_date = timezone.now()
        self.q2.save()

    def tearDown(self):
        pass

    def test_save_and_retrieve_Question(self):
        saved_items = Question.objects.all()
        self.assertEqual(saved_items.count(), 2)
        self.assertEqual(saved_items[0].question_text, self.q1.question_text)
        self.assertEqual(saved_items[1].question_text, self.q2.question_text)

    def test_save_and_retrieve_Choice(self):
        self.q1.choice_set.create(choice_text = 'Choice 1', votes=0)
        self.q1.choice_set.create(choice_text = "Choice 2", votes=1)

        saved_items = Choice.objects.all()
        self.assertEqual(saved_items.count(), 2)
        self.assertEqual(saved_items[0].choice_text, "Choice 1")
        self.assertEqual(saved_items[1].choice_text, "Choice 2")
コード例 #6
0
	def test_was_published_recently_with_old_question(self):
		"""
		was_published_recently should return False for questions whose pub_date is older than 1 day
		"""
		time = timezone.now() - datetime.timedelta(days=30)
		old_question = Question(pub_date=time)
		self.assertEqual(old_question.was_published_recently(), False)
コード例 #7
0
ファイル: test_views.py プロジェクト: leifos/tango_with_tests
    def test_view_can_handle_votes_via_POST(self):
        # set up a poll with choices
        poll1 = Question(question_text='6 times 7', pub_date=timezone.now())
        poll1.save()
        choice1 = Choice(question=poll1, choice_text='42', votes=1)
        choice1.save()
        choice2 = Choice(question=poll1, choice_text='The Ultimate Answer', votes=3)
        choice2.save()

        # set up our POST data - keys and values are strings
        post_data = {'choice': str(choice2.id)}

        # make our request to the view
        poll_url = '/polls/%d/vote/' % (poll1.id,)
        response = self.client.post(poll_url, data=post_data)

        #URL to redirect
        redirect_url = '/polls/%d/results/' % (poll1.id,)

        # retrieve the updated choice from the database
        choice_in_db = Choice.objects.get(pk=choice2.id)

        # check it's votes have gone up by 1
        self.assertEquals(choice_in_db.votes, 4)

        # always redirect after a POST - even if, in this case, we go back
        # to the same page.
        self.assertRedirects(response, redirect_url)
コード例 #8
0
	def test_was_published_recently_with_recent_question(self):
		"""
		was_published_recently() shoudl return True for questions whose pub_date is within a day old.
		"""
		time = timezone.now()
		current_question = Question(pub_date=time)
		self.assertEqual(current_question.was_published_recently(), True)
コード例 #9
0
ファイル: views.py プロジェクト: kimshangyup/zip
def write_new(request, methods=['POST']):
	if request.POST['question'] and request.POST['choice1'] and request.POST['choice2']:
		q=Question()
		q.title=request.POST['question']
		q.save()
		c1=Choice()
		c1.questions=q
		c1.options=request.POST['choice1']
		c1.save()
		c2=Choice()
		c2.questions=q
		c2.options=request.POST['choice2']
		c2.save()
		if request.POST['choice3']:
			c3=Choice()
			c3.questions=q
			c3.options=request.POST['choice3']
			c3.save()
			if request.POST['choice4']:
				c4=Choice()
				c4.questions=q
				c4.options=request.POST['choice4']
				c4.save()
				if request.POST['choice5']:
					c5=Choice()
					c5.questions=q
					c5.options=request.POST['choice5']
					c5.save()
	return HttpResponseRedirect('/poll/')
コード例 #10
0
	def test_was_published_recently_with_old_question(self):
		"""
		was_published_recently() should return False for questions whose pub_date is over a day in the past
		"""
		time = timezone.now() - datetime.timedelta(days=2)
		past_question = Question(pub_date=time)
		self.assertEqual(past_question.was_published_recently(), False)
コード例 #11
0
ファイル: views.py プロジェクト: marsxn/bb
def create_question(request):
    """
    Create Question
    """
    if request.method == 'POST':
        form = CreateQuestionForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data

            # Get Question Text (Required)
            question_text = data.get('question_text')

            # Create a empty list to group the choice text
            choices = []
            for k, v in data.iteritems():
                if k != 'question_text' and v != '':
                    choices.append(v)

            # Instance and save a Question 
            question = Question(question_text=question_text)
            question.save()

            # Create choices for question
            for choice_text in choices:
                question.choice_set.create(choice_text=choice_text)

            return HttpResponseRedirect(reverse('polls:index'))
    else:
        form = CreateQuestionForm()

    context = {'form': form}
    return render(request, 'polls/create.html', context)
コード例 #12
0
ファイル: tests.py プロジェクト: stefsy/djroku
 def test_was_published_recently_with_recent_question(self):
     """
     should return true
     """
     time = timezone.now() - datetime.timedelta(hours=1)
     recent_question = Question(pub_date=time)
     self.assertEqual(recent_question.was_published_recently(), True)
コード例 #13
0
ファイル: tests.py プロジェクト: Betrezen/Projects
 def test_was_published_recently_with_future_poll(self):
     """
     was_published_recently() should return False for polls whose
     pub_date is in the future
     """
     future_poll = Question(pub_date=timezone.now() + datetime.timedelta(days=30))
     self.assertEqual(future_poll.was_published_recently(), False)
コード例 #14
0
ファイル: test_models.py プロジェクト: Spaghet/django_study
 def test_was_published_recently_with_old_questions(self):
     """
     was_published_recently() should return False for questions more than a day old.
     """
     time = timezone.now() - datetime.timedelta(days=30)
     old_question = Question(pub_date=time)
     self.assertIs(old_question.was_published_recently(), False)
コード例 #15
0
	def test_was_published_recently_with_recent_questions(self):
		""" was_published_recently() should return True for questions whose
		pub_date is within the last day
		"""
		time = timezone.now() - datetime.timedelta(hours=1)
		recent_question = Question(pub_date=time)
		self.assertEqual(recent_question.was_published_recently(), True)
コード例 #16
0
ファイル: fill.py プロジェクト: Poehavshiy/ask_chizhikov
def randomQuestionGenerator(users, tags):
    user = User.objects.get(id=random.randint(1, users - 1))
    filename = "/home/nikita/web/ask_chizhikov/polls/management/commands/" + "q" + str(random.randint(1, 5)) + ".txt"
    f = open(filename, 'r')
    title = ""
    text = ""
    help = 0

    for line in f:
        if line == "\n":
            help = 1
        if help == 0:
            title += line
        else:
            text += line
    added_at = parse_datetime("2012-02-21 10:28:45")

    #####
    q = Question(author=user, text=text, title=title, rating=random.randint(0, 50), added_at=added_at,
                 answers=random.randint(0, 1000))
    q.save()
    for i in range(0, 5):
        random_tag_id = random.randint(1, tags-1)
        q.tag.add(Tag.objects.get(id=random_tag_id))

    q.save()
コード例 #17
0
ファイル: test_models.py プロジェクト: Spaghet/django_study
 def test_was_published_recently_with_recent_question(self):
     """
     was_published_recently() should return true for questions less than a day old in the past.
     """
     time = timezone.now() - datetime.timedelta(hours=1)
     recent_question = Question(pub_date=time)
     self.assertIs(recent_question.was_published_recently(), True)
コード例 #18
0
def generate_elements(count=1):
    """
    this guy generates db elements for testing
    """
    for k in range(count):
        question = ""

        for i in range(choice((2, 3, 4, 5, 6, 7))):
            question = " ".join((question, choice(WORDS)))

        question = question[1:] + "?"
        question = question[0].upper() + question[1:]
        q = Question(question_text=question, pub_date=timezone.now())
        q.save()
        print(q.id, q.question_text)

        for choicecount in range(choice((2, 3))):
            choicetxt = ""

            for choicewords in range(choice((2, 3, 4, 5))):
                choicetxt = " ".join((choicetxt, choice(WORDS)))

            choicetxt = choicetxt[1:]
            choicetxt = choicetxt[0].upper() + choicetxt[1:] + "."
            # print('\t', choicetxt)

            ch = Choice(question=q, choice_text=choicetxt, votes=choice((0, 1, 2, 3, 4, 5)))
            ch.save()

            print("\t", ch.question.id, ch.choice_text)
コード例 #19
0
def add_question(request):
    if 'Submit' in request.POST:
        new_question_title = request.POST['question_title']
        new_question_text = request.POST['question_text']
        new_question = Question(question_text=new_question_text, pub_date=timezone.now(), author=request.user,
                                modification_time=timezone.now(), question_title=new_question_title)
        tag_string = request.POST['tags']
        tags = tag_string.split(',')

        new_question.save()
        for new_tag in tags:
            new_tag_object = Tags(tag=new_tag)
            #new_tag_object.save()
            if Tags.objects.filter(tag=new_tag):
                new_question.tags.add(Tags.objects.get(tag=new_tag))
            else:
                #print "not exists"
                #print Tags.objects.get(tag=new_tag)
                # print Tags.objects.get(tag=new_tag)
                # new_tag_object = Tags.objects.get(tag=new_tag)
                # print "get successfully"
                # new_question.tags.add(new_tag_object)
                # print "add successfully"
                new_tag_object.save()
                new_question.tags.add(new_tag_object)

        print "out of for"
        new_question.save()

        #print new_question.tags.all()
        return HttpResponseRedirect(reverse('polls:index'))
    elif 'Cancel' in request.POST:
        return HttpResponseRedirect(reverse('polls:ask'))
    else:
        return HttpResponse("Submit new question error")
コード例 #20
0
ファイル: tests.py プロジェクト: ntmagda93/pollsApplication
 def test_was_publishsed_recently_with_future_question(self):
     """
     was_published_recently() should return false for future questions
     """
     time = timezone.now() + timezone.timedelta(days=30)
     future_question = Question(pub_date=time)
     self.assertEqual(future_question.was_published_recently(), False)
コード例 #21
0
ファイル: tests.py プロジェクト: Markwaardig/Assessment
	def test_was_published_recently_with_old_question(self):
    	"""
    	was_published_recently() should return False for questions whose
    	pub_date is older than 1 day
    	"""
    	time = timezone.now() - datetime.timedelta(days=30)
    	old_question = Question(pub_date=time)
    	self.assertEqual(old_question.was_published_recently(), False)

	def test_was_published_recently_with_recent_question(self):
    	"""
    	was_published_recently() should return True for questions whose
    	pub_date is within the last day
    	"""
    	time = timezone.now() - datetime.timedelta(hours=1)
    	recent_question = Question(pub_date=time)
    	self.assertEqual(recent_question.was_published_recently(), True)

        ### inserted

    def create_question(question_text, days):
        """
        Creates a question with the given `question_text` published the given
        number of `days` offset to now (negative for questions published
        in the past, positive for questions that have yet to be published).
        """
        time = timezone.now() + datetime.timedelta(days=days)
        return Question.objects.create(question_text=question_text,
                                       pub_date=time)
コード例 #22
0
def get_question(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = QuestionForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            question_body = request.POST.get('your_question', '')
            new_question = Question(question_text=question_body, pub_date=timezone.now())
            new_question.save()

            characters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w',
                          'x','y','z']
            for i in range(0, 5):
                answer_text = 'your_answer_' + characters[i]
                new_answer = request.POST.get(answer_text, '')
                if new_answer != '':
                    new_choice = Choice(question=new_question, choice_text=new_answer, votes=0)
                    new_choice.save()
            # process the data in form.cleansed_data as required
            # ...
            # redirect to a new URL:
            return HttpResponseRedirect('/polls/')

    # if a GET (or any other method) we'll create a blank form
    else:
        form = QuestionForm()

    return render(request, 'polls/question.html', {'form': form})
コード例 #23
0
ファイル: tests.py プロジェクト: 99ballons/django_tutorial
 def test_was_published_recently_with_old_question(self):
     """
     was_published_recently() should return false if the pub_date is
     older than 1 day
     """
     time = timezone.now() - datetime.timedelta(days=2)
     old_question = Question(pub_date=time)
     self.assertEquals(old_question.was_published_recently(), False, "Question posted 2 days ago")
コード例 #24
0
 def test_was_published_recently_with_old_question(self):
     """
     was_published_recently should return False if its pub_date is
     not within the last day.
     """
     time = timezone.now() - datetime.timedelta(days = 5)
     old_question = Question(pub_date = time)
     self.assertEqual(old_question.was_published_recently(), False)
コード例 #25
0
ファイル: views.py プロジェクト: IwanJaya/polls-api
    def create_question(self, question_text, choice_texts):
        question = Question(question_text=question_text)
        question.save()

        for choice_text in choice_texts:
            Choice(question=question, choice_text=choice_text).save()

        return question
コード例 #26
0
ファイル: tests.py プロジェクト: 99ballons/django_tutorial
 def test_was_published_recently_with_recent_question(self):
     """
     was_published_recently() should return true if the pub_date is 
     within 1 Day
     """
     time = timezone.now() - datetime.timedelta(hours=1)
     recent_question = Question(pub_date=time)
     self.assertEqual(recent_question.was_published_recently(), True, "Question posted 1 hour ago")
コード例 #27
0
ファイル: tests.py プロジェクト: aman01/mysite
	def test_was_published_recently_with_future_question(self):
		#pass
		"""docstring for QuestionMethodTest"TestCasef __init__(self, arg):
		def test_was_published_recently_with_future_question(self):
		pass"""
		time = timezone.now() + datetime.timedelta(days=30)
		future_question = Question(pub_date = time)
		self.assertEqual(future_question.was_published_recently(),False)
コード例 #28
0
ファイル: tests.py プロジェクト: ntmagda93/pollsApplication
    def test_was_published_recently_with_old_questions(self):
        """
        was_published_recently() should return flase for question published older that 1 day
        """

        time = timezone.now() - timezone.timedelta(days=2)
        old_question = Question(pub_date=time)
        self.assertEqual(old_question.was_published_recently(), False)
コード例 #29
0
    def test_new_poll(self):

        #creating a poll object
        poll = Question()
        poll.question_text = "Shall we begin?"
        poll.pub_date = timezone.now()
        poll.save()
        self.assertEquals(poll.question_text, "Shall we begin?")
コード例 #30
0
ファイル: tests.py プロジェクト: ntmagda93/pollsApplication
    def test_was_published_recently_with_normal_question(self):
        """
        was_published_recently() should return true for question published less than 1 day ago
        """

        time = timezone.now() - timezone.timedelta(hours=2)
        normal_question = Question(pub_date = time)
        self.assertEqual(normal_question.was_published_recently(), True)
コード例 #31
0
 def test_was_published_recently_with_old_question(self):
     """
     was_published_recently() returns False for question whose
     Pub_date is olded than 1 day
     """
     time = timezone.now() - datetime.timedelta(days=1, seconds=1)
     # old_question = mixer.blend('polls.Question', pub_date=time)
     old_question = Question(pub_date=time)
     assert old_question.was_published_recently() == False
コード例 #32
0
 def test_is_published_on_date(self):
     """The question is published on pub date time."""
     now = timezone.now()
     question = Question("Test1",
                         pub_date=now - datetime.timedelta(days=1),
                         end_date=now + datetime.timedelta(days=3))
     self.assertTrue(now >= question.pub_date)
     self.assertTrue(now <= question.end_date)
     self.assertTrue(question.is_published())
コード例 #33
0
 def test_can_vote_after_end_date(self):
     """The user could not vote after end date."""
     now = timezone.now()
     question = Question("Test1",
                         pub_date=now - datetime.timedelta(days=2),
                         end_date=now - datetime.timedelta(days=1))
     self.assertTrue(now > question.end_date)
     self.assertTrue(question.is_published())
     self.assertFalse(question.can_vote())
コード例 #34
0
 def test_was_published_recently_with_recent_question(self):
     """
     1天内的问卷返回True
     :return: boolean
     """
     time = timezone.now() - datetime.timedelta(
         hours=23, minutes=59, seconds=59)
     recent_question = Question(pub_date=time)
     self.assertIs(recent_question.was_published_recently(), True)
コード例 #35
0
    def test_was_published_recently_with_future_question(self):
        """ 
    was_published_recently() should return False for questions whose 
    pub_date is in the future
    """

        time = timezone.now() + datetime.timedelta(days=30)
        future_question = Question(pub_date=time)
        self.assertEqual(future_question.was_published_recently(), False)
コード例 #36
0
    def test_was_published_recently_with_old_question(self):
        """Test was published recently with old question.

        was_published_recently() returns False for questions whose pub_date
        is older than 1 day.
        """
        time = timezone.now() - datetime.timedelta(days=1, seconds=1)
        old_question = Question(pub_date=time)
        self.assertIs(old_question.was_published_recently(), False)
コード例 #37
0
 def test_was_published_recently_with_recent_question(self):
     """
     was_published_recently() returns True for questions whose pub_date
     is within the last day.
     """
     time = timezone.now() - datetime.timedelta(
         hours=23, minutes=59, seconds=59)
     recent_question = Question(pub_date=time)
     self.assertIs(recent_question.was_published_recently(), True)
コード例 #38
0
 def test_was_published_recently_with_recent_question(self):
     """
     was_published_recenlty() should return True for questions whose pub_date
     is within the last day
     """
     time = timezone.now() - datetime.timedelta(hours=1)
     recent_question = Question(pub_date=time)
     self.assertEqual(recent_question.was_published_recently(), True)
         
コード例 #39
0
    def test_was_published_recently_with_future_question(self):
        """Test was published recently with future question.

        was_published_recently() returns False for questions whose pub_date
        is in the future.
        """
        time = timezone.now() + datetime.timedelta(days=30)
        future_question = Question(pub_date=time)
        self.assertIs(future_question.was_published_recently(), False)
コード例 #40
0
 def test_can_vote_with_open_question(self):
     """
     can_vote() return True for questions whose still open.
     pub_date is in the past and end_date is in the future.
     """
     pub_date_time = timezone.now() - datetime.timedelta(days=1)
     end_date_time = timezone.now() + datetime.timedelta(days=1)
     open_question = Question(pub_date=pub_date_time,
                              end_date=end_date_time)
     self.assertIs(open_question.can_vote(), True)
コード例 #41
0
ファイル: test_poll_dates.py プロジェクト: ZEZAY/ku-polls
    def test_was_published_recently_with_recent_question(self):
        """Test for was_published_recently().

        was_published_recently() must returns True for questions whose pub_date is within the last day.
        """
        delta = datetime.timedelta(hours=23, minutes=59, seconds=59)
        time = timezone.now() - delta
        end_time = time + self.add_time_one_year
        recent_question = Question(pub_date=time, end_date=end_time)
        self.assertIs(recent_question.was_published_recently(), True)
コード例 #42
0
    def test_was_published_recently_with_recent_question(self):
        """Test if recent question is published recently.

        Test if recent question is published recently.

        """
        time = timezone.now() - datetime.timedelta(
            hours=23, minutes=59, seconds=59)
        recent_question = Question(pub_date=time)
        self.assertIs(recent_question.was_published_recently(), True)
コード例 #43
0
 def test_create_choice(self):
     q = Question(question_text="What day is it?", pub_date=timezone.now())
     q.save()
     c1 = Choice(choice_text="Monday", question=q)
     c2 = Choice(choice_text="Tuesday", question=q)
     c3 = Choice(choice_text="Sunday", question=q)
     c1.save()
     c2.save()
     c3.save()
     self.assertEqual(3, len(q.choice_set.all()))
コード例 #44
0
    def test_was_published_recently_with_recent_question(self):
        """
        It should return True if a question was published until 1 day ago.
        """

        recent_date = timezone.now() - datetime.timedelta(
            hours=23, minutes=59, seconds=59)
        recent_question = Question(pub_date=recent_date)

        self.assertIs(recent_question.was_published_recently(), True)
コード例 #45
0
ファイル: views.py プロジェクト: alekseev-pa/tms_polls
def questions(request):
    from polls.models import Question
    from datetime import datetime

    q = Question(question_text='How do you fel today?',
                 pub_date=datetime.now())
    q.save()

    questions = Question.objects.all()
    return render(request, 'questions.html', context={'questions': questions})
コード例 #46
0
 def test_can_vote_with_closed_question(self):
     """
     can_vote() return False for questions whose end_date
     is already pass.
     """
     pub_date_time = timezone.now() - datetime.timedelta(days=7)
     end_date_time = timezone.now() - datetime.timedelta(days=1)
     closed_question = Question(pub_date=pub_date_time,
                                end_date=end_date_time)
     self.assertIs(closed_question.can_vote(), False)
コード例 #47
0
ファイル: tests.py プロジェクト: GlynPrice/DjangoPythonPolls
 def pubStatusOfQuestion(self, theQuestionP, timePublishedP, pubStatusP):
   aQuestion = Question(question_text = theQuestionP, pub_date = timePublishedP)
   #aQuestion is created, but as it is not saved it is no put in the
   #db.sqlite3 database
   pubStatusP[0] = aQuestion.was_published_recently()
   #print aQuestion.id
   #print aQuestion.question_text
   #print aQuestion.pub_date
   #print "    pubStatusOfQuestion: ", pubStatusP[0], pubStatusP, "    ",
   return 0
コード例 #48
0
    def test_was_published_recently_with_future_question(self):
        """
        was_published_recently() returns False for questions whose pub_date
        is in the future.
        """
        time = timezone.now() + datetime.timedelta(days=30)
        future_question = Question(pub_date=time)

        # Assert future question will return false, otherwise, there is a bug
        self.assertIs(future_question.was_published_recently(), False)
コード例 #49
0
 def test_can_vote(self):
     """The user could vote between pub date and end date interval."""
     now = timezone.now()
     question = Question("Test1",
                         pub_date=now - datetime.timedelta(days=1),
                         end_date=now + datetime.timedelta(days=3))
     self.assertTrue(now >= question.pub_date)
     self.assertTrue(now <= question.end_date)
     self.assertTrue(question.is_published())
     self.assertTrue(question.can_vote())
コード例 #50
0
ファイル: views.py プロジェクト: aldebaran1/WebFrameworkTest
def index(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = InputForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            location = form.cleaned_data['location']
            fromdate = form.cleaned_data['fromdate']
            todate = form.cleaned_data['todate']
            if (location == '1'):
                madrigalUrl = 'http://isr.sri.com/madrigal'
            else:
                madrigalUrl = 'http://madrigal.haystack.mit.edu/madrigal'
            user_fullname = 'Ashaki Gumbs'
            user_email = '*****@*****.**'
            user_affiliation = 'Boston University'
            testData = madrigalWeb.MadrigalData(madrigalUrl)
            expList = testData.getExperiments(61,
                                              fromdate.year,
                                              fromdate.month,
                                              fromdate.day,
                                              0,
                                              0,
                                              0,
                                              todate.year,
                                              todate.month,
                                              todate.day,
                                              0,
                                              0,
                                              0,
                                              local=1)
            # newcgiurl = madrigalWeb.MadrigalData(madrigalUrl)
            # expList = newcgiurl.getExperiments(61, fromdate.year,fromdate.month,fromdate.day,0,0,0,
            #     todate.year,todate.month,todate.day,0,0,0, local=1)
            Question.objects.all().delete()
            for i in range(len(expList)):
                q = Question(pub_date=timezone.now(),
                             madrigalUrl=expList[i].madrigalUrl,
                             name=expList[i].name,
                             realUrl=expList[i].realUrl,
                             url=expList[i].url,
                             madid=expList[i].id)
                q.save()

            # process the data in form.cleaned_data as required
            # ...
            # redirect to a new URL:
            return HttpResponseRedirect('/polls/listexp/')

    # if a GET (or any other method) we'll create a blank form
    else:
        form = InputForm()

    return render(request, 'polls/inputinfo.html', {'form': form})
コード例 #51
0
    def test_list_question_relation(self):
        q = Question(
            question_text="question_text_006", pub_date=timezone.now())
        q.save()
        c = Choice(question=q, choice_text="006_001")
        c.save()

        response = self.client.get(
            reverse("polls:choice-list"), **self.auth_headers)

        self.assertEqual(q.id, json.loads(response.content)[0]["question"])
コード例 #52
0
 def test_was_published_recently_with_future_question(self):
     # 미래의 datetime객체를 time변수에 할당
     time = timezone.now() + datetime.timedelta(days=30)
     # 새 Question인스턴스를 생성, pub_date값에 미래시간을 주어줌
     future_question = Question(pub_date=time)
     # 주어진 2개의 객체가 같아야 할 것(is)으로 기대함
     # 같지 않은면 실패
     self.assertIs(
         future_question.was_published_recently(),
         False,
     )
コード例 #53
0
ファイル: tests.py プロジェクト: OkThought/DjangoPoll
 def test_was_published_recently_with_old_question(self):
     """
     was_published_recently() returns False for a question
     with pub_date older than one day the past
     """
     for step_back in [
             timezone.timedelta(days=1, seconds=1),
             timezone.timedelta(days=2),
     ]:
         past_time = timezone.now() - step_back
         past_question = Question(pub_date=past_time)
         self.assertFalse(past_question.was_published_recently())
コード例 #54
0
ファイル: forms.py プロジェクト: ktakats/django-polly
 def save(self, owner, options):
     data = self.cleaned_data
     time = timezone.now()
     q = Question(question_text=data['question_text'],
                  pub_date=time,
                  owner=owner)
     q.save()
     for i in range(len(options)):
         Options.objects.create(question=q,
                                option_text=options[i]['option_text'],
                                votes=0)
     return q
コード例 #55
0
ファイル: views.py プロジェクト: priyamulam/CDR
def index(request):

    q = get_object_or_404(Question, id=1)

    try:
        q = Question.objects.get(id=2)
    except Question.DoesNotExist:
        q = Question()
        q.question_text = ""
        q.save()

    return HttpResponse("Hello, world. New Resposne ")
コード例 #56
0
    def setUp(self):
        self.url = 'http://localhost:8000/api/polls/'
        self.url_question = 'http://localhost:8000/api/polls/1/'
        self.name = "My entry title"
        self.new_name = "Update entry title"
        self.date = "2018-12-24T13:45:25Z"
        self.pk = 1

        # create question db method
        self.movie = Question(question_text=self.name, pub_date=self.date)
        self.movie.save()
        self.assertEqual(Question.objects.count(), 1)
コード例 #57
0
ファイル: test_models.py プロジェクト: pranav94/djangoProject
def test_add_choice_to_question():
    """
    Test if we can add a choice to a question safely
    """
    pub_date = timezone.now()
    question = Question(question_text="Test question", pub_date=pub_date)
    question.save()
    choice = Choice(question_id=question.id,
                    choice_text="Test choice",
                    votes=23)
    choice.save()
    assert choice.choice_text == "Test choice"
    assert choice.votes == 23
コード例 #58
0
    def post(self, request):
        question = Question()
        question.question_text = "the question is what?"
        question.pub_date = timezone.now()

        # 序列化方法1
        serializer = QuestionSerializer(question)
        print(serializer.data)
        #反序列化
        stream = io.BytesIO(JSONRenderer().render(serializer.data))
        data = JSONParser().parse(stream)
        print(QuestionSerializer(data).data)

        return Response(serializer.data)
コード例 #59
0
def add(request):
    question = request.POST.get('question')
    choice1 = request.POST.get('choice1')
    choice2 = request.POST.get('choice2')

    q = Question(question_text=question, pub_date=timezone.now())
    q.save()

    c = Choice(question=q, choice_text=choice1)
    c.save()
    c = Choice(question=q, choice_text=choice2)
    c.save()

    return HttpResponseRedirect(reverse('polls:index'))
コード例 #60
0
ファイル: tests.py プロジェクト: OkThought/DjangoPoll
 def test_was_published_recently_with_recent_question(self):
     """
     was_published_recently() returns True for a question
     with pub_date within one day the past
     """
     for step_back in [
             timezone.timedelta(hours=23, minutes=59, seconds=59),
             timezone.timedelta(hours=12),
             timezone.timedelta(seconds=1),
             timezone.timedelta(seconds=0),
     ]:
         past_time = timezone.now() - step_back
         past_question = Question(pub_date=past_time)
         self.assertTrue(past_question.was_published_recently())