Esempio n. 1
0
 def test_existing_entry_is_returned(self):
     user = get_user('us-ignite')
     challenge = fixtures.get_challenge(user=user)
     application = get_application(owner=user)
     entry = fixtures.get_entry(
         application, challenge=challenge, status=Entry.SUBMITTED)
     eq_(Entry.objects.get_entry_or_none(challenge, application), entry)
Esempio n. 2
0
 def test_get_entries_for_apps_returns_entry(self):
     user = get_user('us-ignite')
     challenge = fixtures.get_challenge(user=user)
     application = get_application(owner=user)
     entry = fixtures.get_entry(application, challenge=challenge)
     result = Entry.objects.get_entries_for_apps(challenge, [application])
     eq_(result, [AppEntry(application=application, entry=entry)])
Esempio n. 3
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)
Esempio n. 4
0
 def test_is_visible_for_owners(self):
     user = get_user('us-ignite')
     challenge = fixtures.get_challenge(user=user)
     application = get_application(owner=user)
     entry = fixtures.get_entry(
         application, challenge=challenge, status=Entry.DRAFT)
     eq_(entry.is_visible_by(user), True)
Esempio n. 5
0
 def test_is_not_visible_when_is_draft(self):
     user = get_user('us-ignite')
     challenge = fixtures.get_challenge(user=user)
     application = get_application(owner=user)
     entry = fixtures.get_entry(
         application, challenge=challenge, status=Entry.DRAFT)
     eq_(entry.is_visible_by(utils.get_anon_mock()), False)
Esempio n. 6
0
 def test_is_visible_for_published_challenges(self):
     user = get_user('us-ignite')
     challenge = fixtures.get_challenge(user=user)
     application = get_application(owner=user)
     entry = fixtures.get_entry(
         application, challenge=challenge, status=Entry.SUBMITTED)
     eq_(entry.is_visible_by(utils.get_anon_mock()), True)
Esempio n. 7
0
 def test_instance_is_draft(self):
     user = get_user('us-ignite')
     challenge = fixtures.get_challenge(user=user)
     application = get_application(owner=user)
     entry = fixtures.get_entry(
         application, challenge=challenge, status=Entry.DRAFT)
     eq_(entry.is_draft(), True)
Esempio n. 8
0
 def test_instance_is_submitted(self):
     user = get_user('us-ignite')
     challenge = fixtures.get_challenge(user=user)
     application = get_application(owner=user)
     entry = fixtures.get_entry(
         application, challenge=challenge, status=Entry.SUBMITTED)
     eq_(entry.is_submitted(), True)
Esempio n. 9
0
 def test_edit_url(self):
     user = get_user('us-ignite')
     challenge = fixtures.get_challenge(user=user)
     application = get_application(owner=user)
     entry = fixtures.get_entry(
         application, challenge=challenge, status=Entry.SUBMITTED)
     eq_(entry.get_edit_url(),
         '/challenges/%s/enter/%s/' % (challenge.slug, application.slug))
Esempio n. 10
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)
Esempio n. 11
0
 def test_save_answers_is_sucessful(self, mock_keys, mock_answer):
     user = get_user('us-ignite')
     challenge = fixtures.get_challenge(user=user)
     application = get_application(owner=user)
     entry = fixtures.get_entry(
         application, challenge=challenge)
     question = Mock(spec=Question)()
     question.id = 4
     mock_keys.return_value = [question]
     mock_answer.return_value = 4
     answers = entry.save_answers({'question_4': 'foo'})
     eq_(answers, [4])
     mock_answer.assert_called_once_with(entry, question, 'foo')
     mock_keys.assert_called_once_with(['question_4'])
Esempio n. 12
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)
Esempio n. 13
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()