Skip to content

Commit

Permalink
View and form
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Álvarez committed Jul 18, 2016
1 parent c3cbd60 commit f89d0b5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
27 changes: 25 additions & 2 deletions backend_citizen/tests/views_tests.py
Expand Up @@ -95,13 +95,36 @@ def test_post_update_my_profile(self):
"image": image
}
self.client.login(username=self.fiera.username, password=PASSWORD)
response = self.client.post(url, data=data,follow=True)
response = self.client.post(url, data=data, follow=True)
self.assertTemplateUsed(response, 'backend_citizen/index.html')
fiera = User.objects.get(id=self.fiera.id)
self.assertEquals(fiera.profile.description, data['description'])
self.assertTrue(fiera.profile.image)


class GroupUserCreateView(TestCase):
def setUp(self):
super(GroupUserCreateView, self).setUp()

def test_posting_to_url(self):
url = reverse('backend_citizen:create_group')
original_amount = User.objects.count()
data = {'username': 'group',
'name': 'This Is a Great Group',
'email': 'group@mail.com',
'password1': 'pass',
'password2': 'pass',
}
response = self.client.post(url, data=data)
registration_complete_url = reverse('registration_activation_complete')
self.assertRedirects(response, registration_complete_url)
new_amount = User.objects.count()
self.assertEquals(new_amount, original_amount + 1)
tha_group = User.objects.get(username="group")
self.assertEquals(tha_group.first_name, data['name'])
self.assertTrue(tha_group.profile.is_organization)


class OrganizationDetailViewTests(TestCase):
def setUp(self):
super(OrganizationDetailViewTests, self).setUp()
Expand All @@ -113,4 +136,4 @@ def test_there_is_a_url(self):
response = self.client.get(url)
self.assertEquals(response.status_code, 200)
self.assertTemplateUsed(response, 'backend_citizen/organization.html')
self.assertEquals(response.context['organization'], self.organization)
self.assertEquals(response.context['organization'], self.organization)
6 changes: 4 additions & 2 deletions backend_citizen/urls.py
Expand Up @@ -5,15 +5,17 @@
OrganizationDetailView,
OrganizationCreateView,
DoYouBelongToAnOrgView,
GroupRegistrationView,
)
from django.views.generic.base import TemplateView
from django.contrib.auth.decorators import login_required


urlpatterns = patterns('',
url(r'^$',
IndexView.as_view(),
name='index'),
url(r'^create_group/?$',
GroupRegistrationView.as_view(),
name='create_group'),
url(r'^organization/(?P<slug>[-\w]+)/?$',
OrganizationDetailView.as_view(),
name='organization'),
Expand Down
16 changes: 15 additions & 1 deletion backend_citizen/views.py
Expand Up @@ -7,13 +7,16 @@
from popular_proposal.models import ProposalTemporaryData
from django.core.urlresolvers import reverse
from django.views.generic.edit import UpdateView
from backend_citizen.forms import UserChangeForm, OrganizationCreationForm
from backend_citizen.forms import (UserChangeForm,
OrganizationCreationForm,
GroupCreationForm)
from django.contrib.auth.models import User
from backend_citizen.models import Organization
from django.views.generic.edit import CreateView
from django.shortcuts import redirect
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from registration.views import RegistrationView


class IndexView(TemplateView):
Expand Down Expand Up @@ -96,3 +99,14 @@ def get(self, *args, **kwargs):
self.request.user.profile.first_time_in_backend_citizen = True
self.request.user.profile.save()
return super(DoYouBelongToAnOrgView, self).get(*args, **kwargs)


class GroupRegistrationView(RegistrationView):
form_class = GroupCreationForm

def register(self, form):
new_user = form.save()
return new_user

def get_success_url(self, user):
return reverse('registration_activation_complete')
2 changes: 1 addition & 1 deletion elections/tests/home_tests.py
Expand Up @@ -18,7 +18,7 @@ def test_get_home(self):
self.assertTrue(response.status_code, 200)
self.assertTemplateUsed(response, 'elections/home.html')
self.assertTemplateUsed(response, 'base.html')
self.assertIn('form',response.context)
self.assertIn('form', response.context)
self.assertIsInstance(response.context['form'], ElectionSearchByTagsForm)

def test_home_view(self):
Expand Down
8 changes: 4 additions & 4 deletions elections/views.py
Expand Up @@ -150,10 +150,10 @@ def determine_taken_positions(self, positions_dict):
topic = Topic.objects.get(id=topic_id)
try:
position = Position.objects.get(id=position_id)
positions.append(TakenPosition(
topic=topic,
position=position
))
positions.append(TakenPosition(topic=topic,
position=position
)
)
except Position.DoesNotExist:
pass
return positions
Expand Down

0 comments on commit f89d0b5

Please sign in to comment.