Beispiel #1
0
 def test_valid_payload_succeeds(self):
     user = get_user('us-ignite')
     challenge = fixtures.get_challenge(
         user=user, status=Challenge.PUBLISHED)
     app = get_application(owner=user, status=Application.PUBLISHED)
     question = fixtures.get_question(challenge)
     entry = fixtures.get_entry(app)
     EntryAnswer.get_or_create_answer(
         entry, question, 'Uses Gigabit features.')
     question_id = 'question_%s' % question.id
     data = {
         'status': Entry.SUBMITTED,
         question_id: 'Answer for the question!'
     }
     url = '/challenges/%s/enter/%s/' % (challenge.slug, app.slug)
     request = utils.get_request('post', url, data=data, user=user)
     request._messages = utils.TestMessagesBackend(request)
     response = views.challenge_entry(
         request, challenge.slug, app.slug)
     eq_(response.status_code, 302)
     eq_(response['location'], url)
     entry = Entry.objects.get_entry_or_none(challenge, app)
     values = entry.entryanswer_set.values('answer', 'question_id').all()
     expected = [{
         'answer': 'Answer for the question!',
         'question_id': question.id
     }]
     eq_(list(values), expected)
Beispiel #2
0
 def test_get_or_create_answer(self):
     user = get_user('us-ignite')
     challenge = fixtures.get_challenge(user=user)
     application = get_application(owner=user)
     question = fixtures.get_question(challenge)
     entry = fixtures.get_entry(application)
     instance = EntryAnswer.get_or_create_answer(
         entry, question, 'Uses Gigabit features.')
     ok_(instance.id)
     eq_(instance.question, question)
     eq_(instance.answer, 'Uses Gigabit features.')
     ok_(instance.created)
     ok_(instance.modified)
Beispiel #3
0
 def test_entry_can_be_created_successfully(self):
     user = get_user('us-ignite')
     challenge = fixtures.get_challenge(user=user)
     application = get_application(owner=user)
     question = fixtures.get_question(challenge)
     entry = fixtures.get_entry(application)
     data = {
         'entry': entry,
         'question': question,
         'answer': 'Uses Gigabit features.'
     }
     instance = EntryAnswer.objects.create(**data)
     ok_(instance.id)
     eq_(instance.question, question)
     eq_(instance.answer, 'Uses Gigabit features.')
     ok_(instance.created)
     ok_(instance.modified)
Beispiel #4
0
 def test_challenge_form_is_returned_successful(self):
     user = get_user('us-ignite')
     challenge = fixtures.get_challenge(
         user=user, status=Challenge.PUBLISHED)
     app = get_application(owner=user, status=Application.PUBLISHED)
     question = fixtures.get_question(challenge)
     entry = fixtures.get_entry(app)
     EntryAnswer.get_or_create_answer(
         entry, question, 'Uses Gigabit features.')
     request = utils.get_request(
         'get', '/challenges/foo/enter/abc/', user=user)
     response = views.challenge_entry(
         request, challenge.slug, app.slug)
     eq_(response.status_code, 200)
     eq_(sorted(response.context_data.keys()),
         sorted(['form', 'challenge', 'application', 'entry']))
     context = response.context_data
     eq_(context['challenge'], challenge)
     eq_(context['application'], app)
     eq_(context['entry'], None)
     eq_(sorted(context['form'].fields.keys()),
         sorted(['question_%s' % question.id, 'status']))
     self._tear_down()
Beispiel #5
0
 def test_questions_are_returned_from_keys(self):
     challenge = fixtures.get_challenge()
     question = fixtures.get_question(challenge, id=3)
     question_list = Question.objects.get_from_keys(['question_3'])
     eq_(list(question_list), [question])