def test_challenge_not_found(): """Test behaviour when a challenge doesn't exist.""" request = _build_request('/my-project/not-a-challenge/') try: response = views.show(request, 'my-project', 'not-a-challenge') except Http404: pass else: assert_equal(response.status_code, 404)
def test_wrong_project(): """Test behaviour when the project and challenge don't match.""" project_fields = {'name': 'Another project', 'slug': 'another-project', 'description': "Not the project you're looking for", 'long_description': 'Nothing to see here'} other_project = Project.objects.create(**project_fields) request = _build_request('/another-project/my-challenge/') # We either want 404 by exception or by response code here: either is fine try: response = views.show(request, 'another-project', 'my-challenge') except Http404: pass else: assert_equal(response.status_code, 404)
def test_wrong_project(): """Test behaviour when the project and challenge don't match.""" project_fields = { 'name': 'Another project', 'slug': 'another-project', 'description': "Not the project you're looking for", 'long_description': 'Nothing to see here' } other_project = Project.objects.create(**project_fields) request = _build_request('/another-project/my-challenge/') # We either want 404 by exception or by response code here: either is fine try: response = views.show(request, 'another-project', 'my-challenge') except Http404: pass else: assert_equal(response.status_code, 404)
def test_show_challenge(): """Test the view to show an individual challenge.""" request = _build_request('/my-project/my-challenge/') response = views.show(request, 'my-project', 'my-challenge') assert_equal(response.status_code, 200)