<s> """<STR_LIT>""" <EOL> import json <EOL> from django . core . urlresolvers import reverse_lazy , reverse <EOL> from django . test import TestCase <EOL> from superperms . orgs . models import Organization , OrganizationUser <EOL> from landing . models import SEEDUser as User <EOL> from seed . factory import SEEDFactory <EOL> from seed . models import CanonicalBuilding <EOL> from seed . utils . api import get_api_endpoints <EOL> class ApiAuthenticationTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> user_details = { <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' <EOL> } <EOL> self . user = User . objects . create_user ( ** user_details ) <EOL> self . user . generate_key ( ) <EOL> self . org = Organization . objects . create ( ) <EOL> OrganizationUser . objects . create ( user = self . user , organization = self . org ) <EOL> cb = CanonicalBuilding ( active = True ) <EOL> cb . save ( ) <EOL> b = SEEDFactory . building_snapshot ( canonical_building = cb , <EOL> property_name = '<STR_LIT>' , <EOL> address_line_1 = '<STR_LIT>' ) <EOL> cb . canonical_snapshot = b <EOL> cb . save ( ) <EOL> b . super_organization = self . org <EOL> b . save ( ) <EOL> self . building = b <EOL> self . api_url = reverse_lazy ( '<STR_LIT>' ) <EOL> self . params = { <EOL> '<STR_LIT>' : cb . pk , <EOL> '<STR_LIT>' : self . org . pk , <EOL> } <EOL> self . auth_string = '<STR_LIT>' % ( self . user . username , self . user . api_key ) <EOL> def test_get ( self ) : <EOL> """<STR_LIT>""" <EOL> headers = { '<STR_LIT>' : self . auth_string } <EOL> resp = self . client . get ( self . api_url , data = self . params , ** headers ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> body = json . loads ( resp . content ) <EOL> self . assertEqual ( body [ '<STR_LIT:status>' ] , '<STR_LIT:success>' ) <EOL> self . assertEqual ( body [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> self . building . address_line_1 ) <EOL> def test_no_auth ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . client . get ( self . api_url , data = self . params ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content , '<STR_LIT>' ) <EOL> class SchemaGenerationTests ( TestCase ) : <EOL> def test_get_api_endpoints_utils ( self ) : <EOL> """<STR_LIT>""" <EOL> res = get_api_endpoints ( ) <EOL> for url , fn in res . items ( ) : <EOL> self . assertTrue ( fn . is_api_endpoint ) <EOL> self . assertTrue ( url . startswith ( '<STR_LIT:/>' ) ) <EOL> self . assertTrue ( url . endswith ( '<STR_LIT:/>' ) , <EOL> "<STR_LIT>" % url ) <EOL> def test_get_api_schema ( self ) : <EOL> """<STR_LIT>""" <EOL> url = reverse ( '<STR_LIT>' ) <EOL> res = self . client . get ( url ) <EOL> self . assertEqual ( res . status_code , <NUM_LIT:200> ) <EOL> endpoints = json . loads ( res . content ) <EOL> self . assertTrue ( url in endpoints ) <EOL> endpoint = endpoints [ url ] <EOL> self . assertEqual ( endpoint [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT:description>' in endpoint ) </s>
