<s> from __future__ import print_function <EOL> from __future__ import absolute_import <EOL> import unittest <EOL> import responses <EOL> import requests <EOL> from . requests_patch import patched_extract_cookies_to_jar <EOL> from terminalone import T1 <EOL> mock_credentials = { <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT:password>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> API_BASE = '<STR_LIT>' <EOL> requests . sessions . extract_cookies_to_jar = patched_extract_cookies_to_jar <EOL> requests . adapters . extract_cookies_to_jar = patched_extract_cookies_to_jar <EOL> class TestPermissions ( unittest . TestCase ) : <EOL> def setup ( self ) : <EOL> """<STR_LIT>""" <EOL> with open ( '<STR_LIT>' ) as f : <EOL> fixture = f . read ( ) <EOL> responses . add ( responses . POST , '<STR_LIT>' , <EOL> body = fixture , <EOL> adding_headers = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> content_type = '<STR_LIT>' ) <EOL> self . t1 = T1 ( auth_method = '<STR_LIT>' , <EOL> api_base = API_BASE , <EOL> ** mock_credentials ) <EOL> @ responses . activate <EOL> def test_get_permissions ( self ) : <EOL> self . setup ( ) <EOL> with open ( '<STR_LIT>' ) as f : <EOL> fixture = f . read ( ) <EOL> responses . add ( responses . GET , <EOL> '<STR_LIT>' , <EOL> body = fixture , <EOL> content_type = '<STR_LIT>' , <EOL> match_querystring = True ) <EOL> p = self . t1 . get ( '<STR_LIT>' , <NUM_LIT> , child = '<STR_LIT>' ) <EOL> assert p . _type == '<STR_LIT>' , '<STR_LIT>' . format ( p . _type ) <EOL> assert p . parent_id == <NUM_LIT> , '<STR_LIT>' . format ( p . parent_id ) <EOL> @ responses . activate <EOL> def test_remove_advertiser ( self ) : <EOL> self . setup ( ) <EOL> with open ( '<STR_LIT>' ) as f : <EOL> fixture = f . read ( ) <EOL> responses . add ( responses . GET , <EOL> '<STR_LIT>' , <EOL> body = fixture , <EOL> content_type = '<STR_LIT>' , <EOL> match_querystring = True ) <EOL> p = self . t1 . get ( '<STR_LIT>' , <NUM_LIT> , child = '<STR_LIT>' ) <EOL> remove_id = <NUM_LIT:6> <EOL> assert remove_id in p . advertiser . keys ( ) , '<STR_LIT>' . format ( remove_id ) <EOL> p . remove ( '<STR_LIT>' , <NUM_LIT:6> ) <EOL> assert remove_id not in p . advertiser . keys ( ) , '<STR_LIT>' . format ( remove_id ) <EOL> @ responses . activate <EOL> def test_it_should_remove_child_advertisers_when_removing_agency ( self ) : <EOL> self . setup ( ) <EOL> with open ( '<STR_LIT>' ) as f : <EOL> fixture = f . read ( ) <EOL> responses . add ( responses . GET , <EOL> '<STR_LIT>' , <EOL> body = fixture , <EOL> content_type = '<STR_LIT>' , <EOL> match_querystring = True ) <EOL> p = self . t1 . get ( '<STR_LIT>' , <NUM_LIT> , child = '<STR_LIT>' ) <EOL> remove_ids = [ <NUM_LIT:6> , <NUM_LIT:7> ] <EOL> for ad_id in remove_ids : <EOL> assert ad_id in p . advertiser . keys ( ) , '<STR_LIT>' . format ( ad_id ) <EOL> p . remove ( '<STR_LIT>' , <NUM_LIT:3> ) <EOL> for ad_id in remove_ids : <EOL> assert ad_id not in p . advertiser . keys ( ) , '<STR_LIT>' . format ( ad_id ) <EOL> @ responses . activate <EOL> def test_it_should_remove_child_agencies_and_advertisers_when_removing_organization ( self ) : <EOL> self . setup ( ) <EOL> with open ( '<STR_LIT>' ) as f : <EOL> fixture = f . read ( ) <EOL> responses . add ( responses . GET , <EOL> '<STR_LIT>' , <EOL> body = fixture , <EOL> content_type = '<STR_LIT>' , <EOL> match_querystring = True ) <EOL> p = self . t1 . get ( '<STR_LIT>' , <NUM_LIT> , child = '<STR_LIT>' ) <EOL> remove_advertiser_ids = [ <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> ] <EOL> remove_agency_ids = [ <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> for advertiser_id in remove_advertiser_ids : <EOL> assert advertiser_id in p . advertiser . keys ( ) , '<STR_LIT>' . format ( advertiser_id ) <EOL> for agency_id in remove_agency_ids : <EOL> assert agency_id in p . agency . keys ( ) , '<STR_LIT>' . format ( agency_id ) <EOL> p . remove ( '<STR_LIT>' , <NUM_LIT:2> ) <EOL> for advertiser_id in remove_advertiser_ids : <EOL> assert advertiser_id not in p . advertiser . keys ( ) , '<STR_LIT>' . format ( advertiser_id ) <EOL> for agency_id in remove_agency_ids : <EOL> assert agency_id not in p . agency . keys ( ) , '<STR_LIT>' . format ( agency_id ) <EOL> @ responses . activate <EOL> def test_it_should_add_entity_ids_on_save ( self ) : <EOL> self . setup ( ) <EOL> with open ( '<STR_LIT>' ) as f : <EOL> fixture = f . read ( ) <EOL> responses . add ( responses . GET , <EOL> '<STR_LIT>' , <EOL> body = fixture , <EOL> content_type = '<STR_LIT>' , <EOL> match_querystring = True ) <EOL> p = self . t1 . get ( '<STR_LIT>' , <NUM_LIT> , child = '<STR_LIT>' ) <EOL> p . add ( '<STR_LIT>' , <NUM_LIT:10> ) <EOL> data = p . _generate_save_data ( ) <EOL> assert sorted ( data [ '<STR_LIT>' ] ) == [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:10> ] , data [ '<STR_LIT>' ] <EOL> @ responses . activate <EOL> def test_it_should_add_access_to_empty_permissions ( self ) : <EOL> self . setup ( ) <EOL> with open ( '<STR_LIT>' ) as f : <EOL> fixture = f . read ( ) <EOL> responses . add ( responses . GET , <EOL> '<STR_LIT>' , <EOL> body = fixture , <EOL> content_type = '<STR_LIT>' , <EOL> match_querystring = True ) <EOL> p = self . t1 . get ( '<STR_LIT>' , <NUM_LIT> , child = '<STR_LIT>' ) <EOL> p . add ( '<STR_LIT>' , <NUM_LIT:10> ) <EOL> data = p . _generate_save_data ( ) <EOL> assert sorted ( data [ '<STR_LIT>' ] ) == [ <NUM_LIT:10> ] , data [ '<STR_LIT>' ] </s>
