<s> from django . test import TestCase <EOL> from django . contrib . sites . models import Site <EOL> from django . contrib . auth import get_user_model <EOL> from django . contrib . auth . models import Group <EOL> from opps . channels . models import Channel <EOL> from opps . core . permissions . models import Permission , PermissionGroup <EOL> User = get_user_model ( ) <EOL> class PermissionModelTest ( TestCase ) : <EOL> def test_create ( self ) : <EOL> user = User . objects . create ( username = '<STR_LIT:user>' ) <EOL> instance = Permission . objects . create ( user = user ) <EOL> self . assertTrue ( instance ) <EOL> def test_empty_get_by_user ( self ) : <EOL> user = User . objects . create ( username = '<STR_LIT>' ) <EOL> result = Permission . get_by_user ( user ) <EOL> self . assertEqual ( len ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( result [ '<STR_LIT>' ] ) , <NUM_LIT:0> ) <EOL> def test_get_by_user_with_user_permission ( self ) : <EOL> user = User . objects . create ( username = '<STR_LIT>' ) <EOL> site = Site . objects . all ( ) [ <NUM_LIT:0> ] <EOL> channel = Channel . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> slug = '<STR_LIT>' , <EOL> site = site , <EOL> user = user <EOL> ) <EOL> permission = Permission . objects . create ( user = user ) <EOL> permission . channel . add ( channel ) <EOL> permission . save ( ) <EOL> result = Permission . get_by_user ( user ) <EOL> self . assertTrue ( site . pk in result [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( channel . pk in result [ '<STR_LIT>' ] ) <EOL> def test_get_by_user_with_group_permission ( self ) : <EOL> group = Group . objects . create ( name = '<STR_LIT>' ) <EOL> user = User . objects . create ( username = '<STR_LIT>' ) <EOL> user . groups . add ( group ) <EOL> site = Site . objects . all ( ) [ <NUM_LIT:0> ] <EOL> channel = Channel . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> slug = '<STR_LIT>' , <EOL> site = site , <EOL> user = user <EOL> ) <EOL> permission = PermissionGroup . objects . create ( group = group ) <EOL> permission . channel . add ( channel ) <EOL> permission . save ( ) <EOL> result = Permission . get_by_user ( user ) <EOL> self . assertTrue ( site . pk in result [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( channel . pk in result [ '<STR_LIT>' ] ) </s>
