Skip to content

Commit

Permalink
Changed url and related of add_category:
Browse files Browse the repository at this point in the history
from /<user>/<election>/add_category
to /<election>/add_category
  • Loading branch information
nmalbran committed Nov 17, 2011
1 parent 0d50271 commit ba31148
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 32 deletions.
34 changes: 6 additions & 28 deletions elections/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,34 +95,23 @@ def test_create_category(self):

def test_get_add_category_by_user_without_login(self):
request = self.client.get(reverse('add_category',
kwargs={'user': self.user.username,
'election_slug': self.election.slug}))
kwargs={'election_slug': self.election.slug}))
self.assertEquals(request.status_code, 302)

def test_get_add_category_by_user_election_not_owned_by_user(self):
user2 , created = User.objects.get_or_create(username='doe', password='doe')
election2, created = Election.objects.get_or_create(name='FooBar',
owner=user2,
slug='foobar')
# good user, bad election
self.client.login(username='joe', password='doe')
request = self.client.get(reverse('add_category',
kwargs={'user': self.user.username,
'election_slug': election2.slug}))
self.assertEqual(request.status_code, 404)

# bad user, bad election
self.client.login(username='joe', password='doe')
request = self.client.get(reverse('add_category',
kwargs={'user': user2.username,
'election_slug': election2.slug}))
kwargs={'election_slug': election2.slug}))
self.assertEqual(request.status_code, 404)

def test_get_add_category_by_user_success(self):
self.client.login(username='joe', password='doe')
request = self.client.get(reverse('add_category',
kwargs={'user': self.user.username,
'election_slug': self.election.slug}))
kwargs={'election_slug': self.election.slug}))
self.assertEqual(request.status_code, 200)

form = CategoryForm()
Expand All @@ -131,36 +120,25 @@ def test_get_add_category_by_user_success(self):

def test_post_add_category_by_user_without_login(self):
request = self.client.post(reverse('add_category',
kwargs={'user': self.user.username,
'election_slug': self.election.slug}))
kwargs={'election_slug': self.election.slug}))
self.assertEquals(request.status_code, 302)

def test_post_add_category_by_user_election_not_owned_by_user(self):
user2 , created = User.objects.get_or_create(username='doe', password='doe')
election2, created = Election.objects.get_or_create(name='FooBar',
owner=user2,
slug='foobar')
# good user, bad election
self.client.login(username='joe', password='doe')
request = self.client.post(reverse('add_category',
kwargs={'user': self.user.username,
'election_slug': election2.slug}))
self.assertEqual(request.status_code, 404)

# bad user, bad election
self.client.login(username='joe', password='doe')
request = self.client.post(reverse('add_category',
kwargs={'user': user2.username,
'election_slug': election2.slug}))
kwargs={'election_slug': election2.slug}))
self.assertEqual(request.status_code, 404)

def test_post_add_category_success(self):
new_category_name = 'FooCat'

self.client.login(username='joe', password='doe')
request=self.client.post(reverse('add_category',
kwargs={'user': self.user.username,
'election_slug': self.election.slug}),
kwargs={'election_slug': self.election.slug}),
{'name': new_category_name})

self.assertEqual(request.status_code, 200)
Expand Down
3 changes: 2 additions & 1 deletion elections/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def medianaranja2(request):

@login_required
@require_http_methods(['GET', 'POST'])
def add_category(request, user, election_slug):
def add_category(request, election_slug):
election = get_object_or_404(Election, slug=election_slug, owner=request.user)

if request.GET:
form = CategoryForm()
Expand Down
4 changes: 1 addition & 3 deletions urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@

url(r'^elections/', include('elections.urls')),
url(r'^(?P<my_user>[a-zA-Z0-9-]+)/(?P<election_slug>[a-zA-Z0-9-]+)/medianaranja/$', 'candidator.elections.views.medianaranja1',name='medianaranja1'),
url(r'^(?P<user>[a-zA-Z0-9-]+)/(?P<election_slug>[-\w]+)/add_category/$',
add_category,
name='add_category' ),
url(r'^(?P<election_slug>[-\w]+)/add_category/$', add_category, name='add_category' ),

# django-registration urls, maps common registration urls to the ones in django.contrib.auth
(r'^accounts/', include('registration.urls')),
Expand Down

0 comments on commit ba31148

Please sign in to comment.