def setUpClass(cls) -> None: secrets_file = Path(__file__).parent.parent.parent.joinpath( "secrets.json") cls.api = lse.connect(secrets=secrets_file, stats="-") # stats to stdout # delete the properties that are created in the tests properties = [ "Transaction/JLH/sub-acct", "Transaction/JLH/account", "Holding/JLH/prop1", "Holding/JLH/prop2", ] for p in properties: key_parts = p.split("/") if len(key_parts) != 3: raise Exception(f"invalid property key: {p}") try: cls.api.call.delete_property_definition(domain=key_parts[0], scope=key_parts[1], code=key_parts[2]) except: pass cls.work_dir = os.getcwd() cls.test_data_path = Path(__file__).parent os.chdir(cls.test_data_path)
def test_connect_with_token(self): api = lse.connect( env=["token"], token="test_access_token", secrets="none", stats="-", apiUrl="lusid.url", ) self.assertIsNotNone(api)
def __enter__(self): """ The __enter__ method is called when using Python's built in "with" statement e.g. with CachingApi() as api. :return: """ # If record_mode is true connect to LUSID if self.record_mode: self.api = lse.connect() else: # Otherwise import lusid self.api = lse.ExtendedAPI({}, lusid.ApiClient(lusid.Configuration()), lusid) # Replace the original 'call' with our interceptor self.api.call = self.Interceptor( original=self.api.call, wrapper=self.recorder if self.record_mode else self.reader) return self.api
#!/usr/bin/python3 import pandas as pd from lusidtools.lpt import stdargs from lusidtools.lpt import lse from lusidtools.lpt import lpt args = stdargs.Parser("Delete Portfolio Properties", ["scope", "portfolio", "properties"]).parse() api = lse.connect(args) api.call.delete_portfolio_properties( scope=args.scope, code=args.portfolio, portfolio_property_keys=args.properties).match( left=lpt.display_error, right=lambda r: print("Done!"))