<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import logging <EOL> import sys <EOL> import time <EOL> import unittest <EOL> from functools import partial <EOL> from tornado import stack_context <EOL> from viewfinder . backend . base import util <EOL> from viewfinder . backend . base . testing import async_test <EOL> from viewfinder . backend . db . schema import Location <EOL> from viewfinder . backend . db import device , viewpoint <EOL> from viewfinder . backend . db . user import User <EOL> from base_test import DBBaseTestCase <EOL> class UserTestCase ( DBBaseTestCase ) : <EOL> def _CreateDefaultUser ( self ) : <EOL> return self . _CreateUserAndDevice ( user_dict = { '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' } , <EOL> ident_dict = { '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> device_dict = None ) <EOL> def testPartialCreate ( self ) : <EOL> """<STR_LIT>""" <EOL> user_dict = { '<STR_LIT>' : <NUM_LIT:5> , '<STR_LIT>' : '<STR_LIT>' } <EOL> user , device = self . _CreateUserAndDevice ( user_dict = user_dict , <EOL> ident_dict = { '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> device_dict = None ) <EOL> user . _version = None <EOL> user . signing_key = None <EOL> user_dict [ '<STR_LIT>' ] = [ User . REGISTERED ] <EOL> user_dict [ '<STR_LIT:email>' ] = '<STR_LIT>' <EOL> user_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> user_dict [ '<STR_LIT>' ] = <NUM_LIT:3> <EOL> user_dict [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> self . assertEqual ( user . _asdict ( ) , user_dict ) <EOL> def testRegister ( self ) : <EOL> """<STR_LIT>""" <EOL> u , dev = self . _CreateUserAndDevice ( user_dict = { '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> ident_dict = { '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> device_dict = { '<STR_LIT>' : <NUM_LIT:20> , <EOL> '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( u . given_name , '<STR_LIT>' ) <EOL> self . assertEqual ( u . family_name , '<STR_LIT>' ) <EOL> self . assertEqual ( u . locale , '<STR_LIT>' ) <EOL> self . assertTrue ( dev . device_id > <NUM_LIT:0> ) <EOL> self . assertTrue ( dev . version , '<STR_LIT>' ) <EOL> self . assertTrue ( dev . os , '<STR_LIT>' ) <EOL> self . assertTrue ( dev . platform , '<STR_LIT>' ) <EOL> self . assertTrue ( dev . country , '<STR_LIT>' ) <EOL> self . assertTrue ( dev . language , '<STR_LIT>' ) <EOL> u2 , dev2 = self . _CreateUserAndDevice ( user_dict = { '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' } , <EOL> ident_dict = { '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> device_dict = { '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT:version>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( u . user_id , u2 . user_id ) <EOL> self . assertEqual ( u2 . given_name , '<STR_LIT>' ) <EOL> self . assertEqual ( u2 . email , '<STR_LIT>' ) <EOL> self . assertTrue ( dev . device_id != dev2 . device_id ) <EOL> self . assertEqual ( dev2 . version , '<STR_LIT>' ) <EOL> self . assertEqual ( dev2 . os , '<STR_LIT>' ) <EOL> self . assertEqual ( dev2 . platform , '<STR_LIT>' ) <EOL> u3 , dev3 = self . _CreateUserAndDevice ( user_dict = { '<STR_LIT>' : u2 . user_id , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> ident_dict = { '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> device_dict = { '<STR_LIT>' : dev . device_id , <EOL> '<STR_LIT:version>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( u . user_id , u3 . user_id ) <EOL> self . assertEqual ( u3 . link , '<STR_LIT>' ) <EOL> self . assertEqual ( dev3 . device_id , dev . device_id ) <EOL> self . assertEqual ( dev3 . os , dev . os ) <EOL> self . assertEqual ( dev3 . version , '<STR_LIT>' ) <EOL> try : <EOL> self . _CreateUserAndDevice ( user_dict = { '<STR_LIT>' : <NUM_LIT:1000> } , <EOL> ident_dict = { '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> device_dict = { '<STR_LIT>' : dev3 . device_id } ) <EOL> assert False , '<STR_LIT>' <EOL> except Exception as e : <EOL> assert e . message . startswith ( '<STR_LIT>' ) , e <EOL> identities = self . _RunAsync ( u3 . QueryIdentities , self . _client ) <EOL> keys = [ i . key for i in identities ] <EOL> self . assertTrue ( '<STR_LIT>' in keys ) <EOL> self . assertTrue ( '<STR_LIT>' in keys ) <EOL> def testRegisterViaWebApp ( self ) : <EOL> """<STR_LIT>""" <EOL> u , dev = self . _CreateUserAndDevice ( user_dict = { '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT:name>' : '<STR_LIT>' } , <EOL> ident_dict = { '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> device_dict = None ) <EOL> self . assertEqual ( u . name , '<STR_LIT>' ) <EOL> self . assertTrue ( u . webapp_dev_id > <NUM_LIT:0> ) <EOL> self . assertIsNone ( dev ) <EOL> def testAddDevice ( self ) : <EOL> """<STR_LIT>""" <EOL> u , dev = self . _CreateUserAndDevice ( user_dict = { '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT:name>' : '<STR_LIT>' } , <EOL> ident_dict = { '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> device_dict = None ) <EOL> u2 , dev2 = self . _CreateUserAndDevice ( user_dict = { '<STR_LIT>' : <NUM_LIT:4> } , <EOL> ident_dict = { '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> device_dict = { '<STR_LIT>' : <NUM_LIT:30> } ) <EOL> self . assertEqual ( u2 . user_id , u . user_id ) <EOL> self . assertIsNone ( dev ) <EOL> self . assertIsNotNone ( dev2 ) <EOL> def testQueryUpdate ( self ) : <EOL> """<STR_LIT>""" <EOL> u , d = self . _CreateDefaultUser ( ) <EOL> u2 , d2 = self . _CreateUserAndDevice ( user_dict = { '<STR_LIT>' : u . user_id , <EOL> '<STR_LIT:email>' : '<STR_LIT>' } , <EOL> ident_dict = { '<STR_LIT:key>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> device_dict = None ) <EOL> self . assertEqual ( u . email , u2 . email ) <EOL> def testAllocateAssetIds ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _RunAsync ( User . AllocateAssetIds , self . _client , self . _user . user_id , <NUM_LIT:5> ) <EOL> user = self . _RunAsync ( User . Query , self . _client , self . _user . user_id , None ) <EOL> self . assertEqual ( user . asset_id_seq , <NUM_LIT:6> ) <EOL> self . _RunAsync ( User . AllocateAssetIds , self . _client , self . _user . user_id , <NUM_LIT:100> ) <EOL> user = self . _RunAsync ( User . Query , self . _client , self . _user . user_id , None ) <EOL> self . assertEqual ( user . asset_id_seq , <NUM_LIT> ) <EOL> def testPartialQuery ( self ) : <EOL> """<STR_LIT>""" <EOL> u , dev = self . _CreateDefaultUser ( ) <EOL> u2 = self . _RunAsync ( User . Query , self . _client , u . user_id , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( u2 . email , None ) <EOL> self . assertEqual ( u2 . given_name , u . given_name ) <EOL> self . assertEqual ( u2 . family_name , u . family_name ) <EOL> def testMissing ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . _RunAsync ( User . Query , self . _client , <NUM_LIT:1> L << <NUM_LIT> , None ) <EOL> assert False , '<STR_LIT>' <EOL> except Exception as e : <EOL> pass </s>
