예제 #1
0
 def test_organization_does_not_exist(self, mock_get):
     mock_get.side_effect = Http404
     request = utils.get_request(
         'get', '/org/foo/edit/', user=utils.get_user_mock())
     assert_raises(Http404, views.organization_edit, request, 'foo')
     mock_get.assert_called_once_with(
         Organization, slug__exact='foo', members=request.user)
예제 #2
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)
예제 #3
0
 def test_request_is_successful(self):
     request = utils.get_request(
         'get', '/org/', user=utils.get_user_mock())
     response = views.organization_list(request)
     eq_(response.status_code, 200)
     eq_(response.template_name, 'organizations/object_list.html')
     eq_(sorted(response.context_data.keys()), ['page'])
예제 #4
0
 def test_search_tag_is_successful(self, search_mock):
     search_mock.return_value = 'ok'
     request = utils.get_request('get', '/search/orgs/')
     response = views.search_organizations(request)
     eq_(response, 'ok')
     search_mock.assert_called_once_with(
         request, Organization.active, 'search/organization_list.html')
예제 #5
0
 def invalid_payload_fails(self):
     user = get_user("ignite-user")
     request = utils.get_request("post", "/event/add/", data={}, user=user)
     response = views.event_add(request)
     eq_(response.status_code, 200)
     ok_(response.context_data["form"].errors)
     self._tear_down()
예제 #6
0
 def test_entry_request_requires_authentication(self):
     request = utils.get_request(
         'get', '/challenges/foo/enter/abc/', user=utils.get_anon_mock())
     response = views.challenge_entry(request, 'foo', 'abc')
     eq_(response.status_code, 302)
     eq_(response['Location'],
         utils.get_login_url('/challenges/foo/enter/abc/'))
예제 #7
0
 def test_get_request_is_successful(self):
     request = utils.get_request(
         'get', '/resource/add/', user=utils.get_user_mock())
     response = views.resource_add(request)
     eq_(response.status_code, 200)
     eq_(response.template_name, 'resources/object_add.html')
     eq_(sorted(response.context_data.keys()), ['form'])
예제 #8
0
 def test_search_tag_is_successful(self, search_mock):
     search_mock.return_value = 'ok'
     request = utils.get_request('get', '/search/resource/')
     response = views.search_resources(request)
     eq_(response, 'ok')
     search_mock.assert_called_once_with(
         request, Resource.published, 'search/resource_list.html')
예제 #9
0
 def test_redirect_does_not_exists(self, mock_get):
     mock_get.side_effect = Http404
     request = utils.get_request('get', '/2014/3/foo/')
     assert_raises(Http404, views.legacy_redirect, request, 2014, 3, u'foo')
     mock_get.assert_called_once_with(
         Post.published, slug='foo', publication_date__year=2014,
         publication_date__month=3)
예제 #10
0
 def test_membership_requires_authentication(self):
     request = utils.get_request(
         'post', '/hub/community/membership/', user=utils.get_anon_mock())
     response = views.hub_membership(request, 'community')
     eq_(response.status_code, 302)
     eq_(response['Location'],
         utils.get_login_url('/hub/community/membership/'))
예제 #11
0
 def test_challenge_does_not_exist(self, mock_get):
     mock_get.side_effect = [Mock(spec=Application), Http404]
     request = utils.get_request(
         'get', '/challenges/foo/enter/abc/', user=utils.get_user_mock())
     assert_raises(Http404, views.challenge_entry, request, 'foo', 'abc')
     mock_get.assert_any_call(
         Challenge, slug__exact='foo', status=Challenge.PUBLISHED)
예제 #12
0
 def test_invalid_published_post_returns_404(self, mock_get):
     mock_get.side_effect = Http404
     request = utils.get_request('get', '/blog/', user=utils.get_anon_mock())
     assert_raises(Http404, views.post_detail, request, 2013, 12, 'gigabit')
     mock_get.assert_called_once_with(
         Post, slug='gigabit', publication_date__year=2013,
         publication_date__month=12)
예제 #13
0
 def test_empty_post_request_fails(self, mock_get):
     mock_profile = Mock(spec=Profile)()
     mock_get.return_value = mock_profile
     request = utils.get_request(
         'post', '/contact/foo/', data={}, user=utils.get_user_mock())
     response = views.contact_user(request, 'foo')
     ok_(response.context_data['form'].errors)
예제 #14
0
 def test_organization_is_not_visible(self, mock_get):
     mock_instance = Mock(spec=Organization)()
     mock_get.return_value = mock_instance
     mock_instance.is_visible_by.return_value = False
     request = utils.get_request("get", "/organization/foo/", user=utils.get_anon_mock())
     assert_raises(Http404, views.organization_detail, request, "foo")
     mock_instance.is_visible_by.assert_called_once_with(request.user)
예제 #15
0
 def test_entry_detail_requires_authentication(self):
     request = utils.get_request(
         'get', '/challenges/gigabit/app/', user=utils.get_anon_mock())
     response = views.entry_detail(request, 'gigabit', 'app')
     eq_(response.status_code, 302)
     eq_(response['Location'],
         utils.get_login_url('/challenges/gigabit/app/'))
예제 #16
0
 def test_empty_submission_fails(self, *args):
     request = utils.get_request(
         'post', '/hub/apply/', data={}, user=utils.get_user_mock())
     response = views.hub_application(request)
     eq_(response.status_code, 200)
     eq_(sorted(response.context_data.keys()), ['form', 'object_list'])
     eq_(response.template_name, 'hubs/object_application.html')
     ok_(response.context_data['form'].errors)
예제 #17
0
 def test_get_request_is_successful(self, mock_filter):
     request = utils.get_request(
         'get', '/hub/apply/', user=utils.get_user_mock())
     response = views.hub_application(request)
     eq_(response.status_code, 200)
     eq_(sorted(response.context_data.keys()), ['form', 'object_list'])
     eq_(response.template_name, 'hubs/object_application.html')
     mock_filter.assert_called_once()
예제 #18
0
 def test_get_request_is_successful(self, all_mock):
     user = utils.get_anon_mock()
     request = utils.get_request('get', '/hub/', user=user)
     response = views.hub_list(request)
     eq_(response.status_code, 200)
     eq_(response.template_name, 'hubs/object_list.html')
     eq_(sorted(response.context_data.keys()), ['page'])
     all_mock.assert_called_once_with()
예제 #19
0
 def test_not_visible_event_raises_404(self, mock_get):
     mock_instance = Mock(spec=Event)()
     mock_instance.is_visible_by.return_value = False
     mock_get.return_value = mock_instance
     request = utils.get_request("get", "/event/abc/", user=utils.get_anon_mock())
     assert_raises(Http404, views.event_detail, request, "abc")
     mock_get.assert_called_once_with(Event, slug__exact="abc")
     mock_instance.is_visible_by.assert_called_once()
예제 #20
0
 def test_event_detail_is_successful(self):
     user = get_user("ignite-user")
     event = fixtures.get_event(user=user, slug="foo", status=Event.PUBLISHED)
     request = utils.get_request("get", event.get_absolute_url(), user=user)
     response = views.event_edit(request, "foo")
     eq_(response.status_code, 200)
     eq_(response.template_name, "events/object_edit.html")
     eq_(sorted(response.context_data.keys()), ["form", "formset", "object"])
예제 #21
0
 def test_search_tag_is_successful(self, search_mock, mock_filter):
     mock_filter.return_value = []
     search_mock.return_value = 'ok'
     request = utils.get_request('get', '/search/apps/')
     response = views.search_apps(request)
     eq_(response, 'ok')
     search_mock.assert_called_once_with(
         request, [], 'search/application_list.html')
예제 #22
0
 def test_tag_list_is_successful(self, mock_filter):
     mock_filter.return_value = Tag.objects.none()
     request = utils.get_request('get', '/search/tags.json')
     response = views.tag_list(request)
     eq_(response.status_code, 200)
     eq_(response['Content-Type'], 'application/javascript')
     eq_(response.content, u"[]")
     mock_filter.assert_called_once_with(is_featured=True)
예제 #23
0
 def test_article_list_request_is_successful(self, mock_all):
     mock_all.return_value = []
     request = utils.get_request('get', '/news/')
     response = views.article_list(request)
     eq_(response.status_code, 200)
     eq_(response.template_name, 'news/object_list.html')
     eq_(sorted(response.context_data.keys()), ['page'])
     mock_all.assert_called_once_with()
예제 #24
0
 def test_request_is_successful(self, mock_related):
     request = utils.get_request("get", "/maps/")
     response = views.location_list(request)
     mock_related.assert_called_once_with("category")
     mock_related.return_value.all.assert_called_once_with()
     eq_(response.status_code, 200)
     eq_(sorted(response.context_data.keys()), ["object_list"])
     eq_(response.template_name, "maps/object_list.html")
예제 #25
0
 def test_event_list_request_is_successful(self, mock_filter):
     mock_filter.return_value = []
     request = utils.get_request("get", "/events/", user=utils.get_anon_mock())
     response = views.event_list(request)
     eq_(response.status_code, 200)
     eq_(response.template_name, "events/object_list.html")
     eq_(sorted(response.context_data.keys()), sorted(["page", "timeframe", "featured_list"]))
     mock_filter.assert_called_once()
예제 #26
0
 def test_application_does_not_exist(self, mock_get):
     mock_get.side_effect = Http404
     request = utils.get_request(
         'get', '/challenge/foo/enter/abc/', user=utils.get_user_mock())
     assert_raises(Http404, views.challenge_entry, request, 'foo', 'abc')
     mock_get.assert_called_once_with(
         Application, slug__exact='abc', owner=request.user,
         status=Application.PUBLISHED)
예제 #27
0
 def test_event_invalid_payload_fails(self):
     user = get_user("ignite-user")
     event = fixtures.get_event(user=user, slug="foo", status=Event.PUBLISHED)
     request = utils.get_request("post", event.get_absolute_url(), data={}, user=user)
     response = views.event_edit(request, "foo")
     eq_(response.status_code, 200)
     eq_(response.template_name, "events/object_edit.html")
     ok_(response.context_data["form"].errors)
예제 #28
0
 def test_valid_post_request_is_successful(self, mock_subscribe):
     request = utils.get_request(
         'post', '/subscribe/', data={'email': '*****@*****.**'})
     request._messages = utils.TestMessagesBackend(request)
     response = views.mailing_subscribe(request)
     eq_(response.status_code, 302)
     eq_(response['Location'], '/')
     mock_subscribe.assert_called_once_with('*****@*****.**')
예제 #29
0
 def test_resource_list_request_is_successful(self, mock_filter):
     mock_filter.return_value = []
     request = utils.get_request(
         'get', '/resource/', user=utils.get_anon_mock())
     response = views.resource_list(request)
     eq_(response.status_code, 200)
     eq_(response.template_name, 'resources/object_list.html')
     eq_(sorted(response.context_data.keys()), ['page'])
예제 #30
0
 def challenge_detail_anon_request_is_valid(self, mock_filter):
     request = utils.get_request(
         'get', '/challenges/gigabit/', user=utils.get_anon_mock())
     response = views.challenge_detail(request, 'gigabit')
     eq_(response.status_code, 200)
     eq_(response.template_name, 'challenges/object_detail.html')
     eq_(sorted(response.context_data.keys()), ['entry_list', 'object'])
     eq_(mock_filter.call_count, 0)