from datetime import datetime, timedelta
import time
import hashlib
from pylons import url, config
from {{package}}.model import *
from {{package}}.tests import *

class TestPermissionAdminController(TestController):

    def setUp(self):
        TestModel.setUp(self)
    
    
    def tearDown(self):
        TestModel.tearDown(self)
        Session.close()
    
    
    def test_unauthorised_permission_state_retrieval_prohibited(self):
        """Unauthorised permission GET access is prohibited."""
        response = self.app.get(url('edit_permission', id='1'))
        
        assert response.status_int == 302
        
        assert response.location == 'http://localhost/login/index'
        
        response = self.app.get(url('new_permission'))
        
        assert response.status_int == 302
        
        assert response.location == 'http://localhost/login/index'
        
        response = self.app.get(url('save_permission', id='1'),
                                params={'name': 'Fake Name',
                                        '_method':u'PUT'})
        
        assert response.status_int == 302
        
        assert response.location == 'http://localhost/login/index'
        
        response = self.app.get(url('delete_permission', id='1'),
                                params={'_method':'DELETE'})
        
        assert response.status_int == 302
        
        assert response.location == 'http://localhost/login/index'
    

    def test_unauthorised_permission_state_change_prohibited(self):
        """Unauthorised permission PUTs and DELETEs are prohibited"""
        response = self.app.put(url('save_permission', id='1'),
                                params={'name': 'Fake name',
                                        '_method':'PUT'})
        
        assert response.status_int == 302
        
        assert response.location == 'http://localhost/login/index'
        
        response = self.app.delete(url('delete_permission', id='1'))
        
        assert response.status_int == 302
        
        assert response.location == 'http://localhost/login/index'
    
