コード例 #1
0
    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)
コード例 #2
0
ファイル: test_views.py プロジェクト: SanomaCZ/django-entree
    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)
コード例 #3
0
    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'))
コード例 #4
0
ファイル: test_views.py プロジェクト: SanomaCZ/django-entree
    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"))
コード例 #5
0
ファイル: test_views.py プロジェクト: SanomaCZ/django-entree
    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"))
コード例 #6
0
    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'))
コード例 #7
0
ファイル: test_views.py プロジェクト: SanomaCZ/django-entree
    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
コード例 #8
0
    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
コード例 #9
0
ファイル: test_views.py プロジェクト: SanomaCZ/django-entree
    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)
コード例 #10
0
ファイル: test_views.py プロジェクト: SanomaCZ/django-entree
    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)
コード例 #11
0
    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)
コード例 #12
0
    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)
コード例 #13
0
ファイル: urls.py プロジェクト: SanomaCZ/django-entree
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')
)
コード例 #14
0
ファイル: test_views.py プロジェクト: SanomaCZ/django-entree
    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)
コード例 #15
0
ファイル: test_views.py プロジェクト: SanomaCZ/django-entree
 def test_edit_profile_no_site_id_raises_404(self):
     ViewClass = ProfileEdit.as_view()
     assert_raises(Http404, lambda: ViewClass(self.request))
コード例 #16
0
ファイル: test_views.py プロジェクト: SanomaCZ/django-entree
    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"))
コード例 #17
0
 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))
コード例 #18
0
    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'))
コード例 #19
0
    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)
コード例 #20
0
ファイル: test_views.py プロジェクト: SanomaCZ/django-entree
 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))
コード例 #21
0
 def test_edit_profile_no_site_id_raises_404(self):
     ViewClass = ProfileEdit.as_view()
     assert_raises(Http404, lambda: ViewClass(self.request))
コード例 #22
0
ファイル: urls.py プロジェクト: SanomaCZ/django-entree
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'))