示例#1
0
 def test_non_published_applications_are_not_shown(self):
     fixtures.get_application(
         name='Gigabit app', status=Application.DRAFT)
     response = views.app_list(self.factory.get('/app/'))
     eq_(response.status_code, 200)
     eq_(len(response.context_data['page'].object_list), 0)
     _teardown_apps()
示例#2
0
 def test_applications_are_reverse_sorted(self):
     owner = get_user('us-ignite')
     app_a = fixtures.get_application(
         name='alpha app', status=Application.PUBLISHED, owner=owner)
     app_b = fixtures.get_application(
         name='beta app', status=Application.PUBLISHED, owner=owner)
     response = views.app_list(self.factory.get('/app/', {'order': '-name'}))
     eq_(list(response.context_data['page'].object_list), [app_b, app_a])
     _teardown_apps()
示例#3
0
 def test_applications_are_listed_by_domain(self):
     domain = fixtures.get_domain(name='foo')
     owner = get_user('us-ignite')
     app_a = fixtures.get_application(
         name='alpha app', status=Application.PUBLISHED, owner=owner,
         domain=domain)
     fixtures.get_application(
         name='beta app', status=Application.PUBLISHED, owner=owner)
     response = views.app_list(self.factory.get('/app/foo/'), 'foo')
     eq_(response.status_code, 200)
     eq_(response.template_name, 'apps/object_list.html')
     eq_(list(response.context_data['page'].object_list), [app_a])
     _teardown_apps()
示例#4
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)])
示例#5
0
 def test_published_applications_are_listed(self):
     app = fixtures.get_application(
         name='Gigabit app', status=Application.PUBLISHED)
     response = views.app_list(self.factory.get('/app/'))
     eq_(response.status_code, 200)
     eq_(list(response.context_data['page'].object_list), [app])
     _teardown_apps()
示例#6
0
 def test_application_member_membership(self):
     user = get_user('app-owner')
     member = get_user('app-member')
     application = fixtures.get_application(owner=user)
     models.ApplicationMembership.objects.create(
         application=application, user=member)
     ok_(application.has_member(member))
示例#7
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)
示例#8
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)
示例#9
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)
示例#10
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)
示例#11
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)
示例#12
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)
示例#13
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)
示例#14
0
 def test_app_is_not_editable_by_member(self):
     user = get_user('app-owner')
     member = get_user('member')
     application = fixtures.get_application(
         owner=user, status=models.Application.DRAFT)
     models.ApplicationMembership.objects.create(
         application=application, user=member, can_edit=False)
     eq_(application.is_editable_by(member), False)
示例#15
0
 def test_draft_app_is_visible_by_member(self):
     user = get_user('app-owner')
     member = get_user('app-member')
     application = fixtures.get_application(
         owner=user, status=models.Application.DRAFT)
     models.ApplicationMembership.objects.create(
         application=application, user=member)
     ok_(application.is_visible_by(member))
示例#16
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))
示例#17
0
 def test_member_cannot_change_app_membership(self):
     owner = get_user('owner')
     member = get_user('member', email='*****@*****.**')
     app = fixtures.get_application(
         slug='delta', status=Application.PUBLISHED, owner=owner)
     payload = _get_appmember_payload(app.id)
     request = utils.get_request(
         'post', '/app/delta/membership/', data=payload, user=member)
     assert_raises(Http404, views.app_membership, request, 'delta')
示例#18
0
 def test_get_request_is_successful(self):
     app = fixtures.get_application(
         slug='alpha', status=Application.PUBLISHED, owner=self.user)
     request = self.factory.get('/app/alpha/hubs/')
     request.user = self.user
     response = views.app_hub_membership(request, 'alpha')
     eq_(response.status_code, 200)
     eq_(response.template_name, 'apps/object_hub_membership.html')
     eq_(sorted(response.context_data.keys()), ['form', 'object'])
     eq_(response.context_data['object'], app)
示例#19
0
 def test_get_request_is_successful(self):
     owner = get_user('us-ignite')
     app = fixtures.get_application(
         slug='alpha', status=Application.PUBLISHED, owner=owner)
     request = self.factory.get('/app/alpha/')
     request.user = owner
     response = views.app_edit(request, 'alpha')
     eq_(sorted(response.context_data.keys()),
         ['form', 'image_formset', 'link_formset', 'object'])
     eq_(response.template_name, 'apps/object_edit.html')
示例#20
0
 def test_owner_membership_get_request_is_successful(self):
     owner = get_user('owner')
     app = fixtures.get_application(
         slug='gamma', status=Application.PUBLISHED, owner=owner)
     request = self.factory.get('/app/gamma/membership/')
     request.user = owner
     response = views.app_membership(request, 'gamma')
     eq_(response.status_code, 200)
     eq_(sorted(response.context_data.keys()),
         ['form', 'formset', 'object'])
     eq_(response.context_data['object'], app)
     self._teardown()
示例#21
0
 def test_application_url_creation(self):
     user = get_user('app-owner')
     application = fixtures.get_application(owner=user)
     data = {
         'application': application,
         'url': 'http://us-ignite.org',
     }
     instance = models.ApplicationURL.objects.create(**data)
     ok_(instance.id)
     eq_(instance.application, application)
     eq_(instance.name, '')
     eq_(instance.url, 'http://us-ignite.org')
示例#22
0
 def test_application_award_creation_is_successful(self):
     user = get_user('us-ignite')
     application = get_application(owner=user)
     award = fixtures.get_award(name='Gold star')
     data = {
         'application': application,
         'award': award,
     }
     instance = ApplicationAward.objects.create(**data)
     ok_(instance.id)
     ok_(instance.created)
     eq_(instance.application, application)
     eq_(instance.award, award)
示例#23
0
 def test_post_payload_is_successful(self):
     app = fixtures.get_application(
         slug='alpha', status=Application.PUBLISHED, owner=self.user)
     data = {
         'hubs': [self.hub.id],
     }
     request = self.factory.post('/app/alpha/hubs/', data)
     request.user = self.user
     request._messages = utils.TestMessagesBackend(request)
     response = views.app_hub_membership(request, 'alpha')
     eq_(response.status_code, 302)
     eq_(response['Location'], app.get_absolute_url())
     ok_(HubAppMembership.objects.get(application=app, hub=self.hub))
示例#24
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)
示例#25
0
 def test_owner_membership_empty_payload_succeds(self):
     owner = get_user('owner')
     app = fixtures.get_application(
         slug='gamma', status=Application.PUBLISHED, owner=owner)
     payload = _get_appmember_payload(app.id)
     request = self.factory.post('/app/gamma/membership/', payload)
     request.user = owner
     request._messages = utils.TestMessagesBackend(request)
     response = views.app_membership(request, 'gamma')
     eq_(response.status_code, 302)
     eq_(response['Location'], app.get_membership_url())
     eq_(ApplicationMembership.objects.all().count(), 0)
     self._teardown()
示例#26
0
 def test_application_membership_creation(self):
     user = get_user('app-owner')
     member = get_user('member')
     application = fixtures.get_application(owner=user)
     data = {
         'user': member,
         'application': application,
     }
     instance = models.ApplicationMembership.objects.create(**data)
     eq_(instance.user, member)
     eq_(instance.application, application)
     eq_(instance.can_edit, False)
     ok_(instance.created)
示例#27
0
 def test_page_item_is_created_successfully(self):
     user = get_user('app-maker')
     application = fixtures.get_application(owner=user)
     page = fixtures.get_page(name='Awesome apps')
     data = {
         'application': application,
         'page': page,
     }
     instance = models.PageApplication.objects.create(**data)
     ok_(instance.id)
     eq_(instance.application, application)
     eq_(instance.page, page)
     eq_(instance.order, 0)
示例#28
0
 def test_membership_is_create_successful(self):
     user = get_user('owner')
     hub = fixtures.get_hub(name='Gigabit hub')
     app = get_application(owner=user)
     data = {
         'hub': hub,
         'application': app,
     }
     instance = HubAppMembership.objects.create(**data)
     ok_(instance.id)
     eq_(instance.hub, hub)
     eq_(instance.application, app)
     eq_(instance.is_featured, False)
     ok_(instance.created)
示例#29
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'])
示例#30
0
 def test_valid_membership_adds_user(self):
     owner = get_user('owner')
     member = get_user('member', email='*****@*****.**')
     app = fixtures.get_application(
         slug='delta', status=Application.PUBLISHED, owner=owner)
     payload = _get_appmember_payload(
         app.id, collaborators='*****@*****.**')
     request = self.factory.post('/app/delta/membership/', payload)
     request.user = owner
     request._messages = utils.TestMessagesBackend(request)
     response = views.app_membership(request, 'delta')
     ok_(app.members.get(id=member.id))
     eq_(response.status_code, 302)
     eq_(response['Location'], app.get_membership_url())