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)
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)
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'])
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')
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()
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/'))
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'])
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')
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)
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/'))
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)
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)
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)
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)
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/'))
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)
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()
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()
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()
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"])
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')
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)
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()
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")
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()
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)
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)
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('*****@*****.**')
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'])
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)