def test_edit_profile_user_allowed(self): self.request.entree_user = self.user ViewClass = ProfileEdit.as_view() view = ViewClass(self.request, site_id=self.valid_site.pk) assert_equals(200, view.status_code)
def test_edit_profile_no_auth_user_redirects_to_login(self): self.request.entree_user = AnonymousUser() ViewClass = ProfileEdit.as_view() view = ViewClass(self.request, site_id=self.valid_site.pk) assert_equals(302, view.status_code) assert_equals(view['Location'], reverse('login'))
def test_edit_profile_no_auth_user_redirects_to_login(self): self.request.entree_user = AnonymousUser() ViewClass = ProfileEdit.as_view() view = ViewClass(self.request, site_id=self.valid_site.pk) assert_equals(302, view.status_code) assert_equals(view["Location"], reverse("login"))
def test_edit_profile_form_valid_no_next_url_redirect_profile(self): self.request.entree_user = self.user self.request.method = "POST" self.request.POST = {} ViewClass = csrf_exempt(ProfileEdit.as_view()) res = ViewClass(self.request, site_id=self.valid_site.pk) assert_equals(res["Location"], reverse("profile"))
def test_edit_profile_form_valid_no_next_url_redirect_profile(self): self.request.entree_user = self.user self.request.method = 'POST' self.request.POST = {} ViewClass = csrf_exempt(ProfileEdit.as_view()) res = ViewClass(self.request, site_id=self.valid_site.pk) assert_equals(res['Location'], reverse('profile'))
def test_edit_profile_form_redirects_to_profile_list(self): self.request.entree_user = self.user self.request.method = "POST" self.request.POST = {} ViewClass = csrf_exempt(ProfileEdit.as_view()) res = ViewClass(self.request, site_id=self.valid_site.pk, next_url="") assert_equals(res["Location"], reverse("profile")) profile = SiteProfile.objects.get(user=self.user, site=self.valid_site) assert profile
def test_edit_profile_form_redirects_to_profile_list(self): self.request.entree_user = self.user self.request.method = 'POST' self.request.POST = {} ViewClass = csrf_exempt(ProfileEdit.as_view()) res = ViewClass(self.request, site_id=self.valid_site.pk, next_url='') assert_equals(res['Location'], reverse('profile')) profile = SiteProfile.objects.get(user=self.user, site=self.valid_site) assert profile
def test_edit_profile_form_valid_next_url_redirect_there(self): self.request.entree_user = self.user self.request.method = "POST" self.request.POST = {} next_url = "/foo/" checked_url = "%s:%s" % (next_url, calc_checksum(next_url, salt=self.valid_site.secret, length=SHORT_CHECK)) ViewClass = csrf_exempt(ProfileEdit.as_view()) res = ViewClass(self.request, site_id=self.valid_site.pk, next_url=b64encode(checked_url)) location = "%s%s" % (self.valid_site.url, next_url) assert_equals(res["Location"], location)
def test_save_profile_invalidates_cache(self): prop = SiteProperty.objects.create(slug="foo", site=self.valid_site) NEWVAL = "fooval" self.request.entree_user = self.user self.request.method = "POST" self.request.POST = {prop.slug: NEWVAL} ViewClass = csrf_exempt(ProfileEdit.as_view()) ViewClass(self.request, site_id=self.valid_site.pk, next_url="") data = ProfileData.objects.get(site_property=prop, user=self.user) assert_equals(data.value, NEWVAL) form = ProfileForm(user=self.user, site=self.valid_site) assert_equals(form.fields[prop.slug].initial, NEWVAL)
def test_save_profile_invalidates_cache(self): prop = SiteProperty.objects.create(slug='foo', site=self.valid_site) NEWVAL = 'fooval' self.request.entree_user = self.user self.request.method = 'POST' self.request.POST = {prop.slug: NEWVAL} ViewClass = csrf_exempt(ProfileEdit.as_view()) ViewClass(self.request, site_id=self.valid_site.pk, next_url='') data = ProfileData.objects.get(site_property=prop, user=self.user) assert_equals(data.value, NEWVAL) form = ProfileForm(user=self.user, site=self.valid_site) assert_equals(form.fields[prop.slug].initial, NEWVAL)
def test_edit_profile_form_valid_next_url_redirect_there(self): self.request.entree_user = self.user self.request.method = 'POST' self.request.POST = {} next_url = '/foo/' checked_url = "%s:%s" % (next_url, calc_checksum(next_url, salt=self.valid_site.secret, length=SHORT_CHECK)) ViewClass = csrf_exempt(ProfileEdit.as_view()) res = ViewClass(self.request, site_id=self.valid_site.pk, next_url=b64encode(checked_url)) location = "%s%s" % (self.valid_site.url, next_url) assert_equals(res['Location'], location)
from django.conf.urls import patterns, url from django.views.decorators.csrf import csrf_exempt from entree.site.views import ProfileView, ProfileFetchView, ProfileEdit urlpatterns = patterns('entree.site.views', url(r'^edit/(?P<site_id>\d+)/(?P<next_url>[\w\d=]+)/$', ProfileEdit.as_view(), name='profile_edit'), url(r'^edit/(?P<site_id>\d+)/$', ProfileEdit.as_view(), name='profile_edit'), #used only to generate appropriate link in class ShowApiView url(r'^edit/$', ProfileEdit.as_view(), name='profile_edit'), url(r'^fetch/$', csrf_exempt(ProfileFetchView.as_view()), name='profile_fetch'), url(r'^$', ProfileView.as_view(), name='profile') )
def test_edit_profile_anonymous_restricted(self): ViewClass = ProfileEdit.as_view() view = ViewClass(self.request, site_id=self.valid_site.pk) assert_equals(302, view.status_code)
def test_edit_profile_no_site_id_raises_404(self): ViewClass = ProfileEdit.as_view() assert_raises(Http404, lambda: ViewClass(self.request))
def test_auth_required_mixin_anon_user_in_request(self): ViewClass = ProfileEdit.as_view() view = ViewClass(self.request, site_id=self.valid_site.pk) assert_equals(302, view.status_code) assert_equals(view["Location"], reverse("login"))
def test_edit_profile_invalid_site_id_raises_404(self): ViewClass = ProfileEdit.as_view() assert_raises( Http404, lambda: ViewClass(self.request, site_id=self.valid_site.pk + 10))
def test_auth_required_mixin_anon_user_in_request(self): ViewClass = ProfileEdit.as_view() view = ViewClass(self.request, site_id=self.valid_site.pk) assert_equals(302, view.status_code) assert_equals(view['Location'], reverse('login'))
def test_edit_profile_invalid_site_id_raises_404(self): ViewClass = ProfileEdit.as_view() assert_raises(Http404, lambda: ViewClass(self.request, site_id=self.valid_site.pk + 10))
from django.conf.urls import patterns, url from django.views.decorators.csrf import csrf_exempt from entree.site.views import ProfileView, ProfileFetchView, ProfileEdit urlpatterns = patterns( 'entree.site.views', url(r'^edit/(?P<site_id>\d+)/(?P<next_url>[\w\d=]+)/$', ProfileEdit.as_view(), name='profile_edit'), url(r'^edit/(?P<site_id>\d+)/$', ProfileEdit.as_view(), name='profile_edit'), #used only to generate appropriate link in class ShowApiView url(r'^edit/$', ProfileEdit.as_view(), name='profile_edit'), url(r'^fetch/$', csrf_exempt(ProfileFetchView.as_view()), name='profile_fetch'), url(r'^$', ProfileView.as_view(), name='profile'))