<s> from django . test import TestCase <EOL> from django . contrib . auth . models import User <EOL> from doac . models import AuthorizationToken , Client , RefreshToken , Scope <EOL> class TestAuthorizationTokenModel ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . oclient = Client ( name = "<STR_LIT>" , <EOL> access_host = "<STR_LIT>" ) <EOL> self . oclient . save ( ) <EOL> self . scope = Scope ( short_name = "<STR_LIT:test>" , full_name = "<STR_LIT>" , <EOL> description = "<STR_LIT>" ) <EOL> self . scope . save ( ) <EOL> self . user = User ( username = "<STR_LIT:test>" , password = "<STR_LIT:test>" , <EOL> email = "<STR_LIT>" ) <EOL> self . user . save ( ) <EOL> self . token = AuthorizationToken ( client = self . oclient , user = self . user ) <EOL> self . token . save ( ) <EOL> self . token . scope = [ self . scope ] <EOL> self . token . save ( ) <EOL> def test_unicode ( self ) : <EOL> self . assertEqual ( unicode ( self . token ) , self . token . token ) <EOL> def test_generate_refresh_token_creates ( self ) : <EOL> rt = self . token . generate_refresh_token ( ) <EOL> self . assertEqual ( RefreshToken . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertIsInstance ( rt , RefreshToken ) <EOL> def test_generate_refresh_token_no_create_twice ( self ) : <EOL> self . token . generate_refresh_token ( ) <EOL> rt = self . token . generate_refresh_token ( ) <EOL> self . assertEqual ( RefreshToken . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertIsNone ( rt ) <EOL> def test_generate_refresh_token_never_creates_twice ( self ) : <EOL> self . token . generate_refresh_token ( ) <EOL> self . token . is_active = True <EOL> rt = self . token . generate_refresh_token ( ) <EOL> self . assertEqual ( RefreshToken . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertIsNone ( rt ) </s>
