<s> from __future__ import absolute_import , unicode_literals <EOL> from django . contrib . auth import get_user_model <EOL> from django . contrib . auth . models import Group <EOL> from django . core . urlresolvers import reverse <EOL> from django . test . client import Client <EOL> from django . test import TestCase <EOL> from permissions . classes import Permission <EOL> from permissions . models import Role <EOL> from permissions . tests import TEST_ROLE <EOL> from . . permissions import permission_settings_view <EOL> TEST_EMAIL = '<STR_LIT>' <EOL> TEST_GROUP = '<STR_LIT>' <EOL> TEST_PASSWORD = '<STR_LIT>' <EOL> TEST_USERNAME = '<STR_LIT>' <EOL> class SmartSettingViewPermissionsTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . user = get_user_model ( ) . objects . create_user ( <EOL> username = TEST_USERNAME , email = TEST_EMAIL , <EOL> password = TEST_PASSWORD <EOL> ) <EOL> self . group = Group . objects . create ( name = TEST_GROUP ) <EOL> self . role = Role . objects . create ( label = TEST_ROLE ) <EOL> self . group . user_set . add ( self . user ) <EOL> self . role . groups . add ( self . group ) <EOL> Permission . invalidate_cache ( ) <EOL> self . client = Client ( ) <EOL> self . client . login ( <EOL> username = TEST_USERNAME , password = TEST_PASSWORD <EOL> ) <EOL> def tearDown ( self ) : <EOL> self . group . delete ( ) <EOL> self . role . delete ( ) <EOL> self . user . delete ( ) <EOL> def test_view_access_denied ( self ) : <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> response = self . client . get ( <EOL> reverse ( '<STR_LIT>' , args = ( '<STR_LIT>' , ) , ) <EOL> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_view_access_permitted ( self ) : <EOL> self . role . permissions . add ( permission_settings_view . stored_permission ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> response = self . client . get ( <EOL> reverse ( '<STR_LIT>' , args = ( '<STR_LIT>' , ) , ) <EOL> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) </s>
