Changeset 452 in main


Ignore:
Timestamp:
11/04/11 14:46:17 (8 years ago)
Author:
pcosquer
Message:

views: test delegate features

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/openPLM/plmapp/tests/views.py

    r446 r452  
    2626This module contains some tests for openPLM. 
    2727""" 
     28import os.path 
     29import shutil 
     30from django.conf import settings 
    2831from django.contrib.auth.models import User 
    2932from django.test import TestCase 
     
    5760        brian.get_profile().save() 
    5861        self.brian = brian 
     62     
     63    def tearDown(self): 
     64        if os.path.exists(settings.HAYSTACK_XAPIAN_PATH): 
     65            shutil.rmtree(settings.HAYSTACK_XAPIAN_PATH) 
     66         
     67        super(CommonViewTest, self).tearDown() 
    5968 
    6069class ViewTest(CommonViewTest): 
     
    414423 
    415424class UserViewTestCase(CommonViewTest): 
    416      
     425 
    417426    def setUp(self): 
    418427        super(UserViewTestCase, self).setUp() 
    419428        self.user_url = "/user/%s/" % self.user.username 
    420  
    421      
     429        self.controller = UserController(self.user, self.user) 
     430         
    422431    def test_user_attribute(self): 
    423432        response = self.client.get(self.user_url + "attributes/") 
     
    428437        self.assertEqual(attributes["E-mail address"], self.user.email) 
    429438        self.assertTrue(response.context["is_owner"]) 
    430  
    431     def test_delegation(self): 
    432         response = self.client.get(self.user_url + "delegation/") 
    433         self.assertEqual(response.status_code,  200) 
    434         # TODO 
    435439 
    436440    def test_groups(self): 
     
    509513        self.assertFalse(self.user.check_password("pw")) 
    510514 
     515    def test_delegation_get(self): 
     516        response = self.client.get(self.user_url + "delegation/") 
     517        self.assertEqual(response.status_code,  200) 
     518         
     519    def test_delegation_remove(self): 
     520        self.controller.delegate(self.brian, ROLE_OWNER) 
     521        link = self.controller.get_user_delegation_links()[0] 
     522        data = {"link_id" : link.id } 
     523        response = self.client.post(self.user_url + "delegation/", data, follow=True) 
     524        self.assertEqual(response.status_code,  200) 
     525        self.assertFalse(self.controller.get_user_delegation_links()) 
     526        
     527    def test_delegate_get(self): 
     528        for role in ("owner", "notified"): 
     529            url = self.user_url + "delegation/delegate/%s/" % role 
     530            response = self.client.get(url) 
     531            self.assertEqual(response.status_code,  200) 
     532            self.assertEqual(role, unicode(response.context["role"])) 
     533            self.assertTrue(response.context["link_creation"]) 
     534            self.assertEqual("delegation", response.context["current_page"]) 
     535     
     536    def test_delegate_sign_get(self): 
     537        for level in ("all", "1", "2"): 
     538            url = self.user_url + "delegation/delegate/sign/%s/" % str(level) 
     539            response = self.client.get(url) 
     540            self.assertEqual(response.status_code,  200) 
     541            role = unicode(response.context["role"]) 
     542            self.assertTrue(role.startswith("signer")) 
     543            self.assertTrue(level in role) 
     544            self.assertTrue(response.context["link_creation"]) 
     545            self.assertEqual("delegation", response.context["current_page"]) 
     546 
     547    def test_delegate_post(self): 
     548        data = { "type" : "User", "username": self.brian.username } 
     549        for role in ("owner", "notified"): 
     550            url = self.user_url + "delegation/delegate/%s/" % role 
     551            response = self.client.post(url, data, follow=True) 
     552            DelegationLink.objects.get(role=role, delegator=self.user, 
     553                    delegatee=self.brian) 
     554 
     555    def test_delegate_sign_post(self): 
     556        data = { "type" : "User", "username": self.brian.username } 
     557        for level in xrange(1, 4): 
     558            url = self.user_url + "delegation/delegate/sign/%d/" % level 
     559            response = self.client.post(url, data, follow=True) 
     560            role = level_to_sign_str(level - 1) 
     561            DelegationLink.objects.get(role=role, 
     562                delegator=self.user, delegatee=self.brian) 
     563 
     564    def test_delegate_sign_all_post(self): 
     565        # sign all level 
     566        data = { "type" : "User", "username": self.brian.username } 
     567        url = self.user_url + "delegation/delegate/sign/all/" 
     568        response = self.client.post(url, data, follow=True) 
     569        for level in xrange(2): 
     570            role = level_to_sign_str(level) 
     571            DelegationLink.objects.get(role=role, delegator=self.user, 
     572                    delegatee=self.brian) 
     573     
    511574 
    512575from django.core.management import call_command 
Note: See TracChangeset for help on using the changeset viewer.