<s> import sys <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:7> ) : <EOL> import unittest2 as unittest <EOL> else : <EOL> import unittest <EOL> from authy import AuthyException , AuthyFormatException <EOL> from authy . api . resources import Token <EOL> from authy . api . resources import Tokens <EOL> from authy . api . resources import User <EOL> from authy . api . resources import Users <EOL> class TokensTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . users = Users ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> self . resource = Tokens ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> def test_verify_digits_token ( self ) : <EOL> user = self . users . create ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> try : <EOL> token = self . resource . verify ( user . id , '<STR_LIT>' ) <EOL> self . fail ( ) <EOL> except Exception , e : <EOL> self . assertIsInstance ( e , AuthyFormatException ) <EOL> self . assertEqual ( e . message , '<STR_LIT>' ) <EOL> def test_verify_digits_authy_id ( self ) : <EOL> user = self . users . create ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> try : <EOL> token = self . resource . verify ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . fail ( ) <EOL> except Exception , e : <EOL> self . assertIsInstance ( e , AuthyFormatException ) <EOL> self . assertEqual ( e . message , '<STR_LIT>' ) <EOL> def test_verify_longer_token ( self ) : <EOL> user = self . users . create ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> try : <EOL> token = self . resource . verify ( user . id , '<STR_LIT>' ) <EOL> self . fail ( ) <EOL> except Exception , e : <EOL> self . assertIsInstance ( e , AuthyFormatException ) <EOL> self . assertEqual ( e . message , '<STR_LIT>' ) <EOL> def test_verify_invalid_token ( self ) : <EOL> user = self . users . create ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> token = self . resource . verify ( user . id , '<STR_LIT>' ) <EOL> self . assertIsInstance ( token , Token ) <EOL> self . assertFalse ( token . ok ( ) ) <EOL> self . assertEqual ( token . response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( token . errors ( ) [ '<STR_LIT:message>' ] , '<STR_LIT>' ) <EOL> def test_verify_valid_token ( self ) : <EOL> user = self . users . create ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> token = self . resource . verify ( user . id , '<STR_LIT>' ) <EOL> self . assertIsInstance ( token , Token ) <EOL> self . assertTrue ( token . ok ( ) ) <EOL> def test_force_verify_token ( self ) : <EOL> user = self . users . create ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> token = self . resource . verify ( user . id , '<STR_LIT>' , { "<STR_LIT>" : True } ) <EOL> self . assertIsInstance ( token , Token ) <EOL> self . assertTrue ( token . ok ( ) ) </s>
