Best Python code snippet using avocado_python
_api4.py
Source:_api4.py  
1# Copyright (c) 2013 Riverbed Technology, Inc.2#3# This software is licensed under the terms and conditions of the 4# MIT License set forth at:5#   https://github.com/riverbed/flyscript/blob/master/LICENSE ("License").  6# This software is distributed "AS IS" as set forth in the License.7from rvbd.shark._api_helpers import APIGroup, APITimestampFormat8import urllib9class API4Group(APIGroup):10    base_headers = {}11    def _xjtrans(self, urlpath, method, data, as_json,12                 timestamp_format=APITimestampFormat.NANOSECOND,13                 params=None,14                 custom_headers=None):15        """Issue the given API request using either JSON or XML16        (dictated by the as_json parameter)."""17        self.add_base_header('X-RBT-High-Precision-Timestamp-Format', timestamp_format)18        # XXXWP Changing the method so that the caller can specify some extra headers19        headers = dict(self.base_headers)20        if isinstance(custom_headers, dict):21            headers.update(custom_headers)22        # we are dealing with a url so let's sanitize it.23        # this may break code but at least prevents flyscript to send insane urls to the server24        # define insane: url that contains spaces25        urlpath = urllib.quote(urlpath)26        if as_json:27            return self.shark.conn.json_request(method, self.uri_prefix + urlpath,28                                                body=data, params=params, extra_headers=headers)29        else:30            return self.shark.conn.xml_request(method, self.uri_prefix + urlpath,31                                               body=data,32                                               params=params, extra_headers=headers)33    def add_base_header(self, key, value=""):34        if isinstance(key, basestring):35            self.base_headers[key] = value36    def remove_base_header(self, key):37        if isinstance(key, basestring):38            self.base_headers.pop(key, None)39class Common(API4Group):40    def get_services(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):41        """Return the set of services running on this system42        """43        return self._xjtrans("/services", "GET", None, as_json, timestamp_format)44    def get_auth_info(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):45        """Return authentication information necessary to properly log in to the system.46        """47        return self._xjtrans("/auth_info", "GET", None, as_json, timestamp_format)48    def login(self, credentials, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):49        """Log in to the system using the given credentials. Returns the session cookie for use in subsequent calls.50        """51        return self._xjtrans("/login", "POST", credentials, as_json, timestamp_format)52    def logout(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):53        """Log out from the system by invalidating the session cookie54        """55        headers = {'connection':'close'}56        return self._xjtrans("/logout", "POST", {}, as_json, timestamp_format, custom_headers=headers)57    def ping(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):58        return self._xjtrans("/ping", "GET", None, as_json, timestamp_format)59    60    def info(self):61        return self._xjtrans("/info", "GET", None, True, APITimestampFormat.NANOSECOND)62class Settings(API4Group):63    def get_basic(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):64        """ Retrieves the basic configuration settings """65        return self._xjtrans("/settings/basic", "GET", None, as_json, timestamp_format)66    67    def update_basic(self, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):68        """ Updates the basic configuration settings """69        return self._xjtrans("/settings/basic", "PUT", config, as_json, timestamp_format)70    71    def get_auth(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):72        """ Retrieves the authentication settings """73        return self._xjtrans("/settings/auth", "GET", None, as_json, timestamp_format)74    def update_auth(self, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):75        """ Updates the authentication settings """76        return self._xjtrans("/settings/auth", "PUT", config, as_json, timestamp_format)77    def get_audit(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):78        """ Retrieves the audit settings """79        return self._xjtrans("/settings/audit", "GET", None, as_json, timestamp_format)80    def update_audit(self, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):81        """ Updates the audit settings """82        return self._xjtrans("/settings/audit", "PUT", config, as_json, timestamp_format)83    def get_cors_domains(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):84        """ Retrieves the cors_domains settings """85        return self._xjtrans("/settings/cors_domains", "GET", None, as_json, timestamp_format)86    def update_cors_domains(self, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):87        """ Updates the cors_domains settings """88        return self._xjtrans("/settings/cors_domains", "PUT", config, as_json, timestamp_format)89    90    def update_firewall_config(self, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):91        """ Updates the firewall settings """92        return self._xjtrans("/settings/firewall", "POST", config, as_json, timestamp_format)93    94    def get_firewall_config(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):95        """ Returns the firewall settings """96        return self._xjtrans("/settings/firewall", "GET", None, as_json, timestamp_format)97    def get_raw(self):98        """ Returns the raw settings contained in the configuration file in plain text"""99        resp = self.shark.conn.request(self.uri_prefix + "/settings/raw", "GET")100        data = resp.read()101        return data102    def update_raw(self, settings):103        self.shark.conn.request(self.uri_prefix + "/settings/raw", "PUT",104                                body=settings, extra_headers={'Content-Type' : 'text/plain'})105    def reset_raw(self):106        self.shark.conn.request(self.uri_prefix + "/settings/raw", "PUT",107                                body='', extra_headers={'Content-Type' : 'text/plain', 'Content-length' : 0})108    def get_protocol_groups(self):109        """ Returns the protocol_groups settings contained in the configuration file in plain text"""110        resp = self.shark.conn.request(self.uri_prefix + "/settings/protocol_groups", "GET")111        data = resp.read()112        return data113    def update_protocol_groups(self, settings):114        resp = self.shark.conn.request(self.uri_prefix + "/settings/protocol_groups", "PUT",115                                       body=settings, extra_headers={'Content-Type' : 'text/plain'})116        resp.read()117    def get_protocol_names(self):118        """ Returns the protocol_names settings contained in the configuration file in plain text"""119        resp = self.shark.conn.request(self.uri_prefix + "/settings/protocol_names", "GET")120        data = resp.read()121        return data122    def update_protocol_names(self, settings):123        resp = self.shark.conn.request(self.uri_prefix + "/settings/protocol_names", "PUT",124                                       body=settings, extra_headers={'Content-Type' : 'text/plain'})125        resp.read()126        127    def get_notification(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):128        """ Returns notification and SMTP settings from management daemon"""129        return self._xjtrans("/settings/notification", "GET", None, as_json, timestamp_format)130    def update_notification(self, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):131        """ Updates notification and SMTP settings on management daemon"""132        return self._xjtrans("/settings/notification", "PUT", config, as_json, timestamp_format)133    def send_test_email(self, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):134        """ Send a test email using the given config"""135        return self._xjtrans("/settings/notification/send_test_mail", "POST", config, as_json, timestamp_format)136    def send_test_trap(self, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):137        return self._xjtrans('/settings/notification/send_test_trap', "POST", config, as_json, timestamp_format)138    def get_profiler_export(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):139        """Get the profiler export140        """141        return self._xjtrans('/settings/profiler_export', 'GET', None, as_json, timestamp_format)142    def update_profiler_export(self, params=None, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):143        """Set the profiler export144        """145        return self._xjtrans('/settings/profiler_export', 'PUT', params, as_json, timestamp_format)146class Interfaces(API4Group):147    def get_all(self, params=None, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):148        """ Lists the interfaces on the system """149        return self._xjtrans("/interfaces", "GET", None, as_json, timestamp_format, params=params)150    def get_details(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):151        """ Retrieves information about an interface """152        return self._xjtrans("/interfaces/%s" % handle, "GET", None, as_json, timestamp_format)153    def update(self, handle, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):154        """ Updates the interface configuration """155        return self._xjtrans("/interfaces/%s" % handle, "PUT", config, as_json, timestamp_format)156    def start_blink(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):157        """ Sets an interface LED to blink mode. """158        return self._xjtrans("/interfaces/%s/blink_status" % handle, "PUT", {"blink_status":"ON"}, as_json, timestamp_format)159    def stop_blink(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):160        """ Sets an interface LED to non-blink mode. """161        return self._xjtrans("/interfaces/%s/blink_status" % handle, "PUT", {"blink_status":"OFF"}, as_json, timestamp_format)162    def create_export(self, handle, config=None, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):163        """ Create an export and return url """164        return self._xjtrans("/interfaces/%s/exports" % handle, "POST", config, as_json, timestamp_format)165    def get_all_exports(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):166        """ List all exports for this job """167        return self._xjtrans("/interfaces/%s/exports" % handle, "GET", None, as_json, timestamp_format)168    def get_export_details(self, handle, export_id, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):169        """ Return details for a specific export """170        return self._xjtrans("/interfaces/%s/exports/%s" % (handle, export_id), "GET", None, as_json, timestamp_format)171    def get_packets_from_export(self, handle, export_id, path=None):172        """ Fetch packets from export ID """173        return self.shark.conn.download(self.uri_prefix + "/interfaces/%s/exports/%s/packets" % (handle, export_id), path)174    175    def get_packets(self, handle, path=None, params=None):176        """ Directly fetch packets for this interface, with optional parameters """177        return self.shark.conn.download(self.uri_prefix + "/interfaces/%s/packets" % handle, path, params=params)178    def delete_export(self, handle, export_id):179        """ Delete an export """180        return self._xjtrans("/interfaces/%s/exports/%s" % (handle, export_id), "DELETE", None, True, APITimestampFormat.NANOSECOND)181class Jobs(API4Group):182    def get_all(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):183        """ Lists the capture jobs on the system """184        return self._xjtrans("/jobs" , "GET", None, as_json, timestamp_format)185    186    def add(self, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):187        """ Add a new capture job to the system """188        return self._xjtrans("/jobs", "POST", config, as_json, timestamp_format)189    def delete(self, handle):190        """ Updates the capture jobs configuration """191        return self._xjtrans("/jobs/%s" % handle, "DELETE", None, True, APITimestampFormat.NANOSECOND)192    def get_details(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):193        """ Retrieves information about a capture job """194        return self._xjtrans("/jobs/%s" % handle, "GET", None, as_json, timestamp_format)195    def update(self, handle, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):196        """ Updates the capture jobs configuration """197        return self._xjtrans("/jobs/%s" % handle, "PUT", config, as_json, timestamp_format)198    def create_export(self, handle, config=None, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):199        """ Create an export and return url """200        return self._xjtrans("/jobs/%s/exports" % handle, "POST", config, as_json, timestamp_format)201    def get_all_exports(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):202        """ List all exports for this job """203        return self._xjtrans("/jobs/%s/exports" % handle, "GET", None, as_json, timestamp_format)204    def get_export_details(self, handle, export_id, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):205        """ Return details for a specific export """206        return self._xjtrans("/jobs/%s/exports/%s" % (handle, export_id), "GET", None, as_json, timestamp_format)207    def delete_export(self, handle, export_id):208        """ Delete an export """209        return self._xjtrans("/jobs/%s/exports/%s" % (handle, export_id), "DELETE", None, True, APITimestampFormat.NANOSECOND)210    def get_packets_from_export(self, handle, export_id, path=None):211        """ Fetch packets from export ID """212        return self.shark.conn.download(self.uri_prefix + "/jobs/%s/exports/%s/packets" % (handle, export_id), path)213    def get_packets(self, handle, path=None, params=None):214        """ Directly fetch packets for this job, with optional parameters """215        return self.shark.conn.download(self.uri_prefix + "/jobs/%s/packets" % handle, path, params=params)216    def state_update(self, handle, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):217        """ Updates the capture jobs status """218        return self._xjtrans("/jobs/%s/status" % handle, "PUT", config, as_json, timestamp_format)219  220    def get_config(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):221        """ Retrieves configuration information about a capture job """222        return self._xjtrans("/jobs/%s/config" % handle, "GET", None, as_json, timestamp_format)223        224    def get_status(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):225        """ Retrieves status information about a capture job """226        return self._xjtrans("/jobs/%s/status" % handle, "GET", None, as_json, timestamp_format)227        228    def get_index(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):229        """ Retrieves index information about a capture job """230        return self._xjtrans("/jobs/%s/index" % handle, "GET", None, as_json, timestamp_format)231    def get_stats(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):232        """ Retrieves statistics about a capture job """233        return self._xjtrans("/jobs/%s/stats" % handle, "GET", None, as_json, timestamp_format)234        235class Clips(API4Group):236    def get_all(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):237        """ Lists the trace clips on the system """238        return self._xjtrans("/clips" , "GET", None, as_json, timestamp_format)239    240    def add(self, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):241        """ Add a new trace clip to the system """242        return self._xjtrans("/clips", "POST", config, as_json, timestamp_format)243    244    def get_details(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):245        """ Retrieves information about a trace clip """246        return self._xjtrans("/clips/%s" % handle, "GET", None, as_json, timestamp_format)247    248    def update(self, handle, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):249        """ Updates the trace clip configuration """250        return self._xjtrans("/clips/%s" % handle, "PUT", config, as_json, timestamp_format)251    252    def delete(self, handle):253        """Delete a trace clip."""254        return self._xjtrans('/clips/%s' % handle, "DELETE", None, True, APITimestampFormat.NANOSECOND)255    def set_locked(self, handle, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):256        """ Locks/unlocks the trace clip """257        return self._xjtrans("/clips/%s/status" % handle, "PUT", config, as_json, timestamp_format)258    259    def create_export(self, handle, config=None, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):260        """ Create an export and return url """261        return self._xjtrans("/clips/%s/exports" % handle, "POST", config, as_json, timestamp_format)262    263    def get_all_exports(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):264        """ List all exports for this job """265        return self._xjtrans("/clips/%s/exports" % handle, "GET", None, as_json, timestamp_format)266    267    def get_export_details(self, handle, export_id, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):268        """ Return details for a specific export """269        return self._xjtrans("/clips/%s/exports/%s" % (handle, export_id), "GET", None, as_json, timestamp_format)270    def delete_export(self, handle, export_id):271        """ Delete an export """272        return self._xjtrans("/clips/%s/exports/%s" % (handle, export_id), "DELETE", None, True, APITimestampFormat.NANOSECOND)273    def get_packets_from_export(self, handle, export_id, path=None):274        """ Fetch packets from export ID """275        return self.shark.conn.download(self.uri_prefix + "/clips/%s/exports/%s/packets" % (handle, export_id), path)276    def get_packets(self, handle, path=None, params=None):277        """ Directly fetch packets from this clip, with optional parameters """278        return self.shark.conn.download(self.uri_prefix + "/clips/%s/packets" % handle, path, params=params)279        280    def get_config(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):281        """ Retrieves configuration information about a trace clip """282        return self._xjtrans("/clips/%s/config" % handle, "GET", None, as_json, timestamp_format)283        284    def get_status(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):285        """ Retrieves status information about a trace clip """286        return self._xjtrans("/clips/%s/status" % handle, "GET", None, as_json, timestamp_format)287        288    def get_index(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):289        """ Retrieves index information about a trace clip """290        return self._xjtrans("/clips/%s/index" % handle, "GET", None, as_json, timestamp_format)291class Files(API4Group):292    def get_all(self, details = False, recursive= False, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):293        """ Lists all user files on the system """294        # This call includes some parameters in the url295        url = "/fs"296        params = {}297        if details == True:298            params['details'] = True299        if recursive:300            params['recursive'] = True301        return self._xjtrans(url , "GET", None, as_json, timestamp_format, params=params)302    def upload_raw(self, path, data, headers):303        """Raw wrapper around the file upload. """304        if path[0] == '/':305            path = path[1:]306        return self.shark.conn.upload(self.uri_prefix + "/fs/%s" % path, data, extra_headers=headers)307                        308    def upload_xjobject(self, path, data, headers, as_json=True, timestamp_format = APITimestampFormat.NANOSECOND):309        """Upload an XML or JSON-encoded file object."""310        if path[0] == '/':311            path = path[1:]312        return self._xjtrans("/fs/%s" % path, "POST", data, as_json, timestamp_format, custom_headers = headers)313    314    def get_details(self, path, params=None, as_json=True, details = False, recursive = False,315                    timestamp_format=APITimestampFormat.NANOSECOND):316        """Retrieves information about a disk file """317        if path[0] == '/':318            path = path[1:]319        # This call includes some parameters in the url320        url = "/fs/%s" % path321        if params is None:322            params = {}323            324        if details == True:325            params['details'] = True326        if recursive:327            params['recursive'] = True328        return self._xjtrans(url, "GET", None, as_json, timestamp_format, params)329    def upload_trace(self, path, filename, local_file_ref ):330        """Convenience function to upload a trace file."""331        headers = {'Content-Disposition' : filename,332                   'Content-Type' : 'application/octet-stream'}333        if path[0] == '/':334            path = path[1:]335        return self.shark.conn.upload(self.uri_prefix + "/fs/%s" % path, local_file_ref, extra_headers=headers)336    337    def download(self, path, local_path=None):338        """Convenience function to download a file."""339        if path[0] == '/':340            path = path[1:]341        return self.shark.conn.download(self.uri_prefix + "/fs/%s/download" % path, path=local_path)342        343    def delete(self, path):344        """Delete a file from the system."""345        if path[0] == '/':346            path = path[1:]347        return self._xjtrans('/fs/%s' % path, "DELETE", None, True, APITimestampFormat.NANOSECOND)348    def update(self, path, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):349        """ Updates the disk file """350        if path[0] == '/':351            path = path[1:]352        return self._xjtrans("/fs/%s" % path, "PUT", config, as_json, timestamp_format)353    def checksum(self, path, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):354        """ Obtains a disk file checksum """355        if path[0] == '/':356            path = path[1:]357        return self._xjtrans("/fs/%s/checksum" % path, "GET", None, as_json, timestamp_format)358    def move(self, path, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):359        """ Moves a disk file """360        if path[0] == '/':361            path = path[1:]362        return self._xjtrans("/fs/%s/move" % path, "POST", config, as_json, timestamp_format)363    364    def copy(self, path, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):365        """ Moves a disk file """366        if path[0] == '/':367            path = path[1:]368        return self._xjtrans("/fs/%s/copy" % path, "POST", config, as_json, timestamp_format)369    370    def create_index(self, path, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):371        """ Creates an index for a disk file """372        if path[0] == '/':373            path = path[1:]374        return self._xjtrans("/fs/%s/index" % path, "POST", None, as_json, timestamp_format)375    def delete_index(self, path):376        """ Deletes an index for a disk file """377        if path[0] == '/':378            path = path[1:]379        return self._xjtrans("/fs/%s/index" % path, "DELETE", None, True, APITimestampFormat.NANOSECOND)380    def index_info(self, path, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):381        """ Gets information on an index for a disk file """382        if path[0] == '/':383            path = path[1:]384        return self._xjtrans("/fs/%s/index" % path, "GET", None, as_json, timestamp_format)385    def update_timeskew(self, path, packets, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):386        """ Creates a timeskew estimation for a multi-segment file """387        url = "/fs/%s/timeskew_estimate" % path388        params = {389            'packet_count': packets390            }391        if path[0] == '/':392            path = path[1:]393        return self._xjtrans(url, "PUT", None, as_json, timestamp_format, params=params)394    def delete_timeskew(self, path):395        """ Deletes a timeskew estimation for a multi-segment file """396        if path[0] == '/':397            path = path[1:]398        return self._xjtrans("/fs/%s/timeskew_estimate" % path, "DELETE", None, True, APITimestampFormat.NANOSECOND)399    def get_timeskew(self, path, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):400        """ Gets information on a timeskew estimation for a multi-segment file """401        if path[0] == '/':402            path = path[1:]403        return self._xjtrans("/fs/%s/timeskew_estimate" % path, "GET", None, as_json, timestamp_format)404    def create_export(self, path, config=None, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):405        """ Create an export and return url """406        if path[0] == '/':407            path = path[1:]408        return self._xjtrans("/fs/%s/exports" % path, "POST", config, as_json, timestamp_format)409    def get_all_exports(self, path, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):410        """ List all exports for this job """411        if path[0] == '/':412            path = path[1:]413        return self._xjtrans("/fs/%s/exports" % path, "GET", None, as_json, timestamp_format)414    def get_export_details(self, path, export_id, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):415        """ Return details for a specific export """416        if path[0] == '/':417            path = path[1:]418        return self._xjtrans("/fs/%s/exports/%s" % (path, export_id), "GET", None, as_json, timestamp_format)419    def delete_export(self, path, export_id):420        """ Delete an export """421        if path[0] == '/':422            path = path[1:]423        return self._xjtrans("/fs/%s/exports/%s" % (path, export_id), "DELETE", None, True, APITimestampFormat.NANOSECOND)424    def get_packets_from_export(self, path, export_id, local_path=None):425        """ Fetch packets from export ID """426        if path[0] == '/':427            path = path[1:]428        return self.shark.conn.download(self.uri_prefix + "/fs/%s/exports/%s/packets" % (path, export_id), local_path)429    def get_packets(self, path, local_path=None,  params=None):430        """ Directly fetch packets from file on server, with optional parameters """431        if path[0] == '/':432            path = path[1:]433        return self.shark.conn.download(self.uri_prefix + "/fs/%s/packets" % path, local_path, params=params)434        435class Users(API4Group):436    def get(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):437        """ Lists the users on the system """438        return self._xjtrans("/auth/users" , "GET", None, as_json, timestamp_format)439    def add(self, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):440        """ Add a user to the system """441        return self._xjtrans("/auth/users", "POST", config, as_json, timestamp_format)442    def get_details(self, username, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):443        """ Retrieves information about a user """444        return self._xjtrans("/auth/users/%s" % username, "GET", None, as_json, timestamp_format)445    def delete(self, username):446        """ Deletes the given user from the system """447        return self._xjtrans("/auth/users/%s" % username, "DELETE", None, True, APITimestampFormat.NANOSECOND)448    def update(self, user, config):449        """Updates user configuration"""450        return self._xjtrans('/auth/users/{0}'.format(user), 'PUT', config, True, APITimestampFormat.NANOSECOND)451class Groups(API4Group):452    def get(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):453        """ Lists the groups on the system """454        return self._xjtrans("/auth/groups" , "GET", None, as_json, timestamp_format)455    def get_details(self, groupname, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):456        """ Retrieves information about a group on the system """457        return self._xjtrans("/auth/groups/%s" % groupname, "GET", None, as_json, timestamp_format)458    def add(self, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):459        """ Add a group to the system """460        return self._xjtrans("/auth/groups", "POST", config, as_json, timestamp_format)461    def delete(self, groupname):462        """ Deletes the given group from the system """463        return self._xjtrans("/auth/groups/%s" % groupname, "DELETE", None, True, APITimestampFormat.NANOSECOND)464class Licenses(API4Group):465    def get(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):466        """ Lists all licenses in the system """467        return self._xjtrans("/settings/licenses" , "GET", None, as_json, timestamp_format)468    def get_details(self, license_key, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):469        """ Get details for a specific license key """470        return self._xjtrans("/settings/licenses/%s" % license_key, "GET", None, as_json, timestamp_format)471    def get_status(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):472        """ Get system-wide licensing status """473        return self._xjtrans("/settings/licenses/status" , "GET", None, as_json, timestamp_format)474    def add_license(self, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):475        """ Add new license to the system """476        return self._xjtrans("/settings/licenses", "POST", config, as_json, timestamp_format)477    def delete_license(self, license_key):478        """ Delete a license from the system. """479        return self._xjtrans("/settings/licenses/%s" % license_key, "DELETE", None, True, APITimestampFormat.NANOSECOND)480    def generate_license_req(self, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):481        """ Generate a license request. """482        return self._xjtrans("/settings/licenses/request", "POST", config, as_json, timestamp_format)483class Views(API4Group):484    def add(self, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):485        """Add and run a new view"""486        return self._xjtrans("/views", "POST", config, as_json, timestamp_format)487    def get_all(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):488        """Return the list of all running views"""489        return self._xjtrans("/views" , "GET", None, as_json, timestamp_format)490    def close(self, handle):491        """Close the running view"""492        return self._xjtrans("/views/%s" % handle, "DELETE", None, True, APITimestampFormat.NANOSECOND)493        494    def get_config(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):495        """Return the configuration of the given view"""496        return self._xjtrans("/views/%s" % handle, "GET", None, as_json, timestamp_format)497    def get_acl(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):498        """Return the access control list of the given view"""499        return self._xjtrans("/views/%s/acl" % handle, "GET", None, as_json, timestamp_format)500    def update_acl(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):501        """Return the access control list of the given view"""502        # XXX/demmer should this be a PUT??503        return self._xjtrans("/views/%s/acl" % handle, "POST", None, as_json, timestamp_format)504    def get_legend(self, handle, output, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):505        """Return the legend for the given view output"""506        return self._xjtrans("/views/%s/data/%s/legend" % (handle, output), "GET", None, as_json, timestamp_format)507        508    def get_data(self, handle, output, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND, **params):509        """Return the output for the given view"""510        return self._xjtrans("/views/%s/data/%s" % (handle, output), "GET", None, as_json, timestamp_format, params)511    def get_stats(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):512        """Return the statistics for the given view"""513        return self._xjtrans("/views/%s/stats" % handle, "GET", None, as_json, timestamp_format)514    515    def get_processor_stats(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):516        """Return the processor statistics for the given view"""517        return self._xjtrans("/debug/handles/%s" % handle, "GET", None, as_json, timestamp_format)518    def create_watch(self, handle, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):519        """Create a new watch on the view"""520        return self._xjtrans("/views/%s/watches" % handle, "POST", config, as_json, timestamp_format)521    def get_watches(self, handle, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):522        """Obtain the list of watches for a running view"""523        return self._xjtrans("/views/%s/watches" % handle, "GET", as_json, timestamp_format)524    def delete_watch(self, handle, watch_id, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):525        """Delete a watch from the view"""526        return self._xjtrans("/views/%s/watches/%s" % (handle, watch_id), "DELETE", None, as_json, timestamp_format)527    def get_watch(self, handle, watch_id, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):528        """Get settings for a watch on a running view"""529        return self._xjtrans("/views/%s/watches/%s" % (handle, watch_id), "GET", None, as_json, timestamp_format)530    def update_watch(self, handle, watch_id, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):531        """Update settings for a watch on a running view"""532        return self._xjtrans("/views/%s/watches/%s" % (handle, watch_id), "PUT", config, as_json, timestamp_format)533    def disable_watch(self, handle, watch_id, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):534        """Disable a watch on a running view"""535        return self._xjtrans("/views/%s/watches/%s/disable" % (handle, watch_id), "POST", None, as_json, timestamp_format)536    def enable_watch(self, handle, watch_id, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):537        """Enable a watch on a running view"""538        return self._xjtrans("/views/%s/watches/%s/enable" % (handle, watch_id), "POST", None, as_json, timestamp_format)539    # XXX/demmer lock/unlock/stop540    541class System(API4Group):542    def get_info(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):543        """Return the system info"""544        return self._xjtrans("/system/info", "GET", None, as_json, timestamp_format)545    def restart(self, config, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):546        """Restart the probe or reboot the system"""547        return self._xjtrans("/system/restart", "POST", config, as_json, timestamp_format)548    def get_events(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):549        """Return the events list"""550        return self._xjtrans("/debug/events", "GET", None, as_json, timestamp_format)551    552    def get_sysdump(self, path, config, as_json=True, timestap_format=APITimestampFormat.NANOSECOND):553        """Dump log archive554        """555        return self.shark.conn.download(self.uri_prefix + "/system/sysdump", path, params=config)556class Certificates(API4Group):557    558    def get(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):559        """ Returns the certificates settings """560        return self._xjtrans("/settings/certificates", "GET", None, as_json, timestamp_format)561    562    563    def update_profiler_export_certificate(self, certificate_data, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND): 564        """ Set a new Profiler Export certificate"""565        return self._xjtrans("/settings/certificates/profiler_export", "PUT", certificate_data, as_json, timestamp_format)566    567    def generate_profiler_export_certificate(self, certificate_data, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):568        """ Generate new Trusted Profiler certificate"""569        return self._xjtrans("/settings/certificates/profiler_export/generate", "POST", certificate_data, as_json, timestamp_format)570    571    def copy_web_certificate(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND): 572        """ Reuses the web certificate as profiler export certificate"""573        return self._xjtrans("/settings/certificates/profiler_export/copy_web", "POST", None, as_json, timestamp_format)574    575    576    def update_web_certificate(self, certificate_data, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND): 577        """ Set a new Web certificate"""578        return self._xjtrans("/settings/certificates/web", "PUT", certificate_data, as_json, timestamp_format)579    580    def generate_web_certificate(self, certificate_data, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):581        """ Generate new web certificate"""582        return self._xjtrans("/settings/certificates/web/generate", "POST", certificate_data, as_json, timestamp_format)583        584    def copy_profiler_export_certificate(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND): 585        """ Reuses the Profiler Export's certificate as web certificate"""586        return self._xjtrans("/settings/certificates/web/copy_profiler_export", "POST", None, as_json, timestamp_format)587       588    589    def add_trusted_profiler_certificate(self, certificate_data, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND): 590        """ Add a new Trusted Profiler certificate"""591        return self._xjtrans("/settings/certificates/trusted_profilers", "POST", certificate_data, as_json, timestamp_format)592    593    def delete_trusted_profiler_certificate(self, id, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):594        """ Delete a new Trusted Profiler certificate by its id"""595        return self._xjtrans("/settings/certificates/trusted_profilers/"+id, "DELETE", None, as_json, timestamp_format)596class Stats(API4Group):597    def get_memory(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):598        """ Returns the memory stats """599        return self._xjtrans("/stats/memory", "GET", None, as_json, timestamp_format)600        601    def get_profiler_export(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):602        """ Returns the profiler export stats """603        return self._xjtrans("/stats/profiler_export", "GET", None, as_json, timestamp_format)604        605    def get_storage(self, as_json=True, timestamp_format=APITimestampFormat.NANOSECOND):606        """Returns the storage stats607        """608        return self._xjtrans("/stats/storage", "GET", None, as_json, timestamp_format)609class Info(API4Group):610    def get_fields(self, as_json=True):611        """Returns all the extractor fields612        """613        return self._xjtrans("/fields.json", 'GET', None, as_json)614class Misc(API4Group):615    def ping(self, method="GET", data=None, headers=None):616        """Run the ping command using the specified method and617        optionally passing the given data. Note that for POST/PUT the618        server will echo back exactly what was posted.619        For GET, the content type can be requested using an Accept620        header of either text/xml or application/json.621        """622        resp = self.shark.conn.request(self.uri_prefix + "/ping", method, body=data, extra_headers=headers)623        return resp.read()624class Update(API4Group):625    def get(self):626        return self._xjtrans('/system/update', 'GET', None, True, APITimestampFormat.NANOSECOND)627    def load_iso_from_url(self, data):628        """Download upload iso from an url"""629        return self._xjtrans('/system/update/url', 'POST', data, True, APITimestampFormat.NANOSECOND)630    def upload_iso(self, f):631        """Given a file descriptor `f`, uploads the content to the server as an upload iso632        """633        headers = {'Content-Disposition' : 'update.iso',634                   'Content-Type' : 'application/octet-stream'}635        636        return self.shark.conn.upload(self.uri_prefix + "/system/update/iso", data=f, extra_headers=headers)637    def delete_iso(self, data):638        """Delete a previously uploaded iso"""639        return self._xjtrans('/system/update/state', 'PUT', data, True, APITimestampFormat.NANOSECOND)640    def update(self, data):641        """Perform update of the shark642        `init_id` is the id of the image on the server that is ready for update643        """644        return self._xjtrans('/system/update/state', 'PUT',645                             data,646                             True, APITimestampFormat.NANOSECOND)647class Storage(API4Group):648    """Encapsulates the storage informations that can be found in649    Maintenance page in the webui650    """651    def get(self):652        """Gets the storage configuration from the Server653        """654        return self._xjtrans('/system/storage', 'GET', None, True, APITimestampFormat.NANOSECOND)655    def reinitialize(self):656        """Reinitializes the packet storage657        """658        return self._xjtrans('/system/storage/reinitialize', 'POST', None, True, APITimestampFormat.NANOSECOND)659    def format(self, data):660        """Formats packet storage661        """662        return self._xjtrans('/system/format_storage', 'POST', data, True, APITimestampFormat.NANOSECOND )663class API4_0(object):664    version = '4.0'665    common_version = '1.0'666    def __init__(self, shark):667        self.shark = shark668        self.common = Common("/api/common/"+self.common_version, self.shark)669        self.settings = Settings("/api/shark/"+self.version, self.shark)670        self.interfaces = Interfaces("/api/shark/"+self.version, self.shark)671        self.jobs = Jobs("/api/shark/"+self.version, self.shark)672        self.clips = Clips("/api/shark/"+self.version, self.shark)673        self.fs = Files("/api/shark/"+self.version, self.shark)674        self.licenses = Licenses("/api/shark/"+self.version, self.shark)675        self.certificates = Certificates("/api/shark/"+self.version, self.shark)676        self.system = System("/api/shark/"+self.version, self.shark)677        self.view = Views("/api/shark/"+self.version, self.shark)678        self.stats = Stats("/api/shark/"+self.version, self.shark)679        self.info = Info('/api/shark/'+self.version+'/info', self.shark)680        self.users = Users('/api/shark/'+self.version, self.shark)681        self.groups = Groups('/api/shark/'+self.version, self.shark)682        self.update = Update('/api/shark/'+self.version, self.shark)683        self.storage = Storage('/api/shark/'+self.version, self.shark)684        # For the misc handlers just make them methods of the api class itself685        m = Misc('/api/shark/'+self.version, self.shark)686        self.ping = m.ping...test_investpy.py
Source:test_investpy.py  
1#!/usr/bin/python32# Copyright 2018-2020 Alvaro Bartolome @ alvarob96 in GitHub3# See LICENSE for details.4import pytest5import investpy6def test_investpy():7    """8    This function checks that both the investpy's author and version are the correct ones.9    """10    print(investpy.__author__)11    print(investpy.__version__)12def test_investpy_stocks():13    """14    This function checks that stock data retrieval functions listed in investpy work properly.15    """16    params = [17        {18            'country': 'spain',19        },20        {21            'country': None,22        },23    ]24    for param in params:25        investpy.get_stocks(country=param['country'])26        investpy.get_stocks_list(country=param['country'])27    params = [28        {29            'country': None,30            'columns': ['full_name', 'name'],31            'as_json': True32        },33        {34            'country': None,35            'columns': ['full_name', 'name'],36            'as_json': False37        },38        {39            'country': 'spain',40            'columns': ['full_name', 'name'],41            'as_json': True42        },43        {44            'country': 'spain',45            'columns': ['full_name', 'name'],46            'as_json': False47        },48        {49            'country': 'spain',50            'columns': None,51            'as_json': False52        },53    ]54    for param in params:55        investpy.get_stocks_dict(country=param['country'],56                                 columns=param['columns'],57                                 as_json=param['as_json'])58    investpy.get_stock_countries()59    params = [60        {61            'as_json': True,62            'order': 'ascending',63        },64        {65            'as_json': False,66            'order': 'ascending',67        },68        {69            'as_json': True,70            'order': 'descending',71        },72        {73            'as_json': False,74            'order': 'descending',75        },76    ]77    for param in params:78        investpy.get_stock_recent_data(stock='BBVA',79                                       country='spain',80                                       as_json=param['as_json'],81                                       order=param['order'],82                                       interval='Daily')83        investpy.get_stock_historical_data(stock='BBVA',84                                           country='spain',85                                           from_date='01/01/1990',86                                           to_date='01/01/2019',87                                           as_json=param['as_json'],88                                           order=param['order'],89                                           interval='Daily')90    for value in ['spanish', 'english']:91        investpy.get_stock_company_profile(stock='BBVA',92                                           country='spain',93                                           language=value)94    params = [95        {96            'stock': 'bbva',97            'country': 'spain',98            'as_json': False99        },100        {101            'stock': 'bbva',102            'country': 'spain',103            'as_json': True104        },105        {106            'stock': 'HSBK',107            'country': 'kazakhstan',108            'as_json': False109        }110    ]111    for param in params:112        investpy.get_stock_information(stock=param['stock'], country=param['country'], as_json=param['as_json'])113    params = [114        {115            'country': 'spain',116            'as_json': True,117            'n_results': 50118        },119        {120            'country': 'united states',121            'as_json': False,122            'n_results': 50123        },124        {125            'country': 'bosnia',126            'as_json': False,127            'n_results': 50128        },129        {130            'country': 'palestine',131            'as_json': False,132            'n_results': 50133        },134        {135            'country': 'dubai',136            'as_json': False,137            'n_results': 50138        },139        {140            'country': 'ivory coast',141            'as_json': False,142            'n_results': 50143        }144    ]145    for param in params:146        investpy.get_stocks_overview(country=param['country'], as_json=param['as_json'], n_results=param['n_results'])147    investpy.get_stock_dividends(stock='BBVA', country='spain')148    investpy.search_stocks(by='name', value='BBVA')149def test_investpy_funds():150    """151    This function checks that fund data retrieval functions listed in investpy work properly.152    """153    params = [154        {155            'country': 'spain',156        },157        {158            'country': None,159        },160    ]161    for param in params:162        investpy.get_funds(country=param['country'])163        investpy.get_funds_list(country=param['country'])164    params = [165        {166            'country': None,167            'columns': ['name'],168            'as_json': True169        },170        {171            'country': None,172            'columns': ['name'],173            'as_json': False174        },175        {176            'country': 'spain',177            'columns': ['name'],178            'as_json': True179        },180        {181            'country': 'spain',182            'columns': ['name'],183            'as_json': False184        },185        {186            'country': 'spain',187            'columns': None,188            'as_json': False189        },190    ]191    for param in params:192        investpy.get_funds_dict(country=param['country'],193                                columns=param['columns'],194                                as_json=param['as_json'])195    investpy.get_fund_countries()196    params = [197        {198            'as_json': True,199            'order': 'ascending',200        },201        {202            'as_json': False,203            'order': 'ascending',204        },205        {206            'as_json': True,207            'order': 'descending',208        },209        {210            'as_json': False,211            'order': 'descending',212        },213    ]214    for param in params:215        investpy.get_fund_recent_data(fund='bbva multiactivo conservador pp',216                                      country='spain',217                                      as_json=param['as_json'],218                                      order=param['order'],219                                      interval='Daily')220        investpy.get_fund_historical_data(fund='bbva multiactivo conservador pp',221                                          country='spain',222                                          from_date='01/01/2010',223                                          to_date='01/01/2019',224                                          as_json=param['as_json'],225                                          order=param['order'],226                                          interval='Daily')227    params = [228        {229            'fund': 'bbva multiactivo conservador pp',230            'country': 'spain',231            'as_json': True,232        },233        {234            'fund': 'bbva multiactivo conservador pp',235            'country': 'spain',236            'as_json': False,237        },238    ]239    for param in params:240        investpy.get_fund_information(fund=param['fund'],241                                      country=param['country'],242                                      as_json=param['as_json'])243    params = [244        {245            'country': 'andorra',246            'as_json': True,247            'n_results': 2248        },249        {250            'country': 'andorra',251            'as_json': False,252            'n_results': 2253        },254        {255            'country': 'united states',256            'as_json': False,257            'n_results': 2258        },259        {260            'country': 'united kingdom',261            'as_json': False,262            'n_results': 2263        }264    ]265    for param in params:266        investpy.get_funds_overview(country=param['country'], as_json=param['as_json'], n_results=param['n_results'])267    investpy.search_funds(by='name', value='bbva')268def test_investpy_etfs():269    """270    This function checks that etf data retrieval functions listed in investpy work properly.271    """272    params = [273        {274            'country': 'spain',275        },276        {277            'country': None,278        },279    ]280    for param in params:281        investpy.get_etfs(country=param['country'])282        investpy.get_etfs_list(country=param['country'])283    params = [284        {285            'country': None,286            'columns': ['name'],287            'as_json': True288        },289        {290            'country': None,291            'columns': ['name'],292            'as_json': False293        },294        {295            'country': 'spain',296            'columns': ['name'],297            'as_json': True298        },299        {300            'country': 'spain',301            'columns': ['name'],302            'as_json': False303        },304        {305            'country': 'spain',306            'columns': None,307            'as_json': False308        },309    ]310    for param in params:311        investpy.get_etfs_dict(country=param['country'],312                               columns=param['columns'],313                               as_json=param['as_json'])314    investpy.get_etf_countries()315    params = [316        {317            'as_json': True,318            'order': 'ascending',319        },320        {321            'as_json': False,322            'order': 'ascending',323        },324        {325            'as_json': True,326            'order': 'descending',327        },328        {329            'as_json': False,330            'order': 'descending',331        },332    ]333    for param in params:334        investpy.get_etf_recent_data(etf='bbva accion dj eurostoxx 50',335                                     country='spain',336                                     as_json=param['as_json'],337                                     order=param['order'],338                                     interval='Daily')339        investpy.get_etf_historical_data(etf='bbva accion dj eurostoxx 50',340                                         country='spain',341                                         from_date='01/01/2010',342                                         to_date='01/01/2019',343                                         as_json=param['as_json'],344                                         order=param['order'],345                                         interval='Daily')346    params = [347        {348            'etf': 'bbva accion dj eurostoxx 50',349            'country': 'spain',350            'as_json': False351        },352        {353            'etf': 'bbva accion dj eurostoxx 50',354            'country': 'spain',355            'as_json': True356        }357    ]358    for param in params:359        investpy.get_etf_information(etf=param['etf'], country=param['country'], as_json=param['as_json'])360    params = [361        {362            'country': 'united states',363            'as_json': True,364            'n_results': 2365        },366        {367            'country': 'united kingdom',368            'as_json': False,369            'n_results': 2370        },371    ]372    for param in params:373        investpy.get_etfs_overview(country=param['country'], as_json=param['as_json'], n_results=param['n_results'])374    investpy.search_etfs(by='name', value='bbva')375def test_investpy_indices():376    """377    This function checks that index data retrieval functions listed in investpy work properly.378    """379    params = [380        {381            'country': 'spain',382        },383        {384            'country': None,385        },386    ]387    for param in params:388        investpy.get_indices(country=param['country'])389        investpy.get_indices_list(country=param['country'])390    params = [391        {392            'country': None,393            'columns': ['name', 'currency'],394            'as_json': True395        },396        {397            'country': None,398            'columns': ['name', 'currency'],399            'as_json': False400        },401        {402            'country': 'spain',403            'columns': ['name', 'currency'],404            'as_json': True405        },406        {407            'country': 'spain',408            'columns': ['name', 'currency'],409            'as_json': False410        },411        {412            'country': 'spain',413            'columns': None,414            'as_json': False415        },416    ]417    for param in params:418        investpy.get_indices_dict(country=param['country'],419                                  columns=param['columns'],420                                  as_json=param['as_json'])421    investpy.get_index_countries()422    params = [423        {424            'as_json': True,425            'order': 'ascending',426        },427        {428            'as_json': False,429            'order': 'ascending',430        },431        {432            'as_json': True,433            'order': 'descending',434        },435        {436            'as_json': False,437            'order': 'descending',438        },439    ]440    for param in params:441        investpy.get_index_recent_data(index='ibex 35',442                                       country='spain',443                                       as_json=param['as_json'],444                                       order=param['order'],445                                       interval='Daily')446        investpy.get_index_historical_data(index='ibex 35',447                                           country='spain',448                                           from_date='01/01/2018',449                                           to_date='01/01/2019',450                                           as_json=param['as_json'],451                                           order=param['order'],452                                           interval='Daily')453    params = [454        {455            'index': 'ibex 35',456            'country': 'spain',457            'as_json': False458        },459        {460            'index': 'ibex 35',461            'country': 'spain',462            'as_json': True463        }464    ]465    for param in params:466        investpy.get_index_information(index=param['index'], country=param['country'], as_json=param['as_json'])467    468    params = [469        {470            'country': 'united states', 471            'as_json': False,472            'n_results': 10473        },474        {475            'country': 'united kingdom', 476            'as_json': True,477            'n_results': 10478        }479    ]480    for param in params:481        investpy.get_indices_overview(country=param['country'], as_json=param['as_json'], n_results=param['n_results'])482    investpy.search_indices(by='name', value='ibex')483def test_investpy_currency_crosses():484    """485    This function checks that currency cross data retrieval functions listed in investpy work properly.486    """487    params = [488        {489            'base': None,490            'second': None,491        },492        {493            'base': 'EUR',494            'second': None,495        },496        {497            'base': None,498            'second': 'EUR',499        },500        {501            'base': 'EUR',502            'second': 'USD',503        },504    ]505    for param in params:506        investpy.get_currency_crosses(base=param['base'], second=param['second'])507        investpy.get_currency_crosses_list(base=param['base'], second=param['second'])508    params = [509        {510            'base': None,511            'second': None,512            'columns': None,513            'as_json': True514        },515        {516            'base': None,517            'second': None,518            'columns': None,519            'as_json': False520        },521        {522            'base': 'EUR',523            'second': None,524            'columns': None,525            'as_json': True526        },527        {528            'base': 'EUR',529            'second': None,530            'columns': None,531            'as_json': False532        },533        {534            'base': None,535            'second': 'USD',536            'columns': None,537            'as_json': True538        },539        {540            'base': None,541            'second': 'USD',542            'columns': None,543            'as_json': False544        },545        {546            'base': 'EUR',547            'second': 'USD',548            'columns': None,549            'as_json': True550        },551        {552            'base': 'EUR',553            'second': 'USD',554            'columns': None,555            'as_json': False556        },557        {558            'base': 'EUR',559            'second': 'USD',560            'columns': ['name', 'full_name'],561            'as_json': False562        },563    ]564    for param in params:565        investpy.get_currency_crosses_dict(base=param['base'],566                                           second=param['second'],567                                           columns=param['columns'],568                                           as_json=param['as_json'])569    investpy.get_available_currencies()570    params = [571        {572            'currency_cross': 'EUR/USD',573            'from_date': '01/01/2018',574            'to_date': '01/01/2019',575            'as_json': True,576            'order': 'ascending',577        },578        {579            'currency_cross': 'EUR/USD',580            'from_date': '01/01/1990',581            'to_date': '01/01/2019',582            'as_json': False,583            'order': 'descending',584        },585    ]586    for param in params:587        investpy.get_currency_cross_recent_data(currency_cross=param['currency_cross'],588                                                as_json=param['as_json'],589                                                order=param['order'],590                                                interval='Daily')591        investpy.get_currency_cross_historical_data(currency_cross=param['currency_cross'],592                                                    from_date=param['from_date'],593                                                    to_date=param['to_date'],594                                                    as_json=param['as_json'],595                                                    order=param['order'],596                                                    interval='Daily')597    params = [598        {599            'currency_cross': 'EUR/USD',600            'as_json': False601        },602        {603            'currency_cross': 'EUR/USD',604            'as_json': True605        }606    ]607    for param in params:608        investpy.get_currency_cross_information(currency_cross=param['currency_cross'], as_json=param['as_json'])609    610    params = [611        {612            'currency': 'try',613            'as_json': False,614            'n_results': 100615        },616        {617            'currency': 'amd',618            'as_json': True,619            'n_results': 100620        }621    ]622    623    for param in params:624        investpy.get_currency_crosses_overview(currency=param['currency'], as_json=param['as_json'], n_results=param['n_results'])625    investpy.search_currency_crosses(by='base', value='EUR')626def test_investpy_bonds():627    """628    This function checks that bond data retrieval functions listed in investpy work properly.629    """630    params = [631        {632            'country': 'spain',633        },634        {635            'country': None,636        },637    ]638    for param in params:639        investpy.get_bonds(country=param['country'])640        investpy.get_bonds_list(country=param['country'])641    params = [642        {643            'country': None,644            'columns': ['full_name', 'name'],645            'as_json': True646        },647        {648            'country': None,649            'columns': ['full_name', 'name'],650            'as_json': False651        },652        {653            'country': 'spain',654            'columns': ['full_name', 'name'],655            'as_json': True656        },657        {658            'country': 'spain',659            'columns': ['full_name', 'name'],660            'as_json': False661        },662        {663            'country': 'spain',664            'columns': None,665            'as_json': False666        },667    ]668    for param in params:669        investpy.get_bonds_dict(country=param['country'],670                                columns=param['columns'],671                                as_json=param['as_json'])672    investpy.get_bond_countries()673    params = [674        {675            'as_json': True,676            'order': 'ascending',677        },678        {679            'as_json': False,680            'order': 'ascending',681        },682        {683            'as_json': True,684            'order': 'descending',685        },686        {687            'as_json': False,688            'order': 'descending',689        },690    ]691    for param in params:692        investpy.get_bond_recent_data(bond='Spain 30Y',693                                      as_json=param['as_json'],694                                      order=param['order'],695                                      interval='Daily')696        investpy.get_bond_historical_data(bond='Spain 30Y',697                                          from_date='01/01/1990',698                                          to_date='01/01/2019',699                                          as_json=param['as_json'],700                                          order=param['order'],701                                          interval='Daily')702    params = [703        {704            'bond': 'spain 30y',705            'as_json': False706        },707        {708            'bond': 'argentina 3y',709            'as_json': True710        },711        {712            'bond': 'germany 3m',713            'as_json': False714        },715    ]716    for param in params:717        investpy.get_bond_information(bond=param['bond'], as_json=param['as_json'])718    719    params = [720        {721            'country': 'united states',722            'as_json': True,723        },724        {725            'country': 'united kingdom',726            'as_json': False,727        }728    ]729    for param in params:730        investpy.get_bonds_overview(country=param['country'], as_json=param['as_json'])731    investpy.search_bonds(by='name', value='Spain')732def test_investpy_commodities():733    """734    This function checks that commodity data retrieval functions listed in investpy work properly.735    """736    params = [737        {738            'group': 'metals',739        },740        {741            'group': None,742        },743    ]744    for param in params:745        investpy.get_commodities(group=param['group'])746        investpy.get_commodities_list(group=param['group'])747    params = [748        {749            'group': None,750            'columns': ['title', 'full_name', 'name'],751            'as_json': True752        },753        {754            'group': None,755            'columns': ['title', 'full_name', 'name'],756            'as_json': False757        },758        {759            'group': 'metals',760            'columns': ['title', 'full_name', 'name'],761            'as_json': True762        },763        {764            'group': 'metals',765            'columns': ['title', 'full_name', 'name'],766            'as_json': False767        },768        {769            'group': 'metals',770            'columns': None,771            'as_json': False772        },773    ]774    for param in params:775        investpy.get_commodities_dict(group=param['group'],776                                      columns=param['columns'],777                                      as_json=param['as_json'])778    investpy.get_commodity_groups()779    params = [780        {781            'country': None,782            'as_json': True,783            'order': 'ascending',784        },785        {786            'country': 'united states',787            'as_json': False,788            'order': 'ascending',789        },790        {791            'country': 'united states',792            'as_json': True,793            'order': 'descending',794        },795        {796            'country': 'united states',797            'as_json': False,798            'order': 'descending',799        },800    ]801    for param in params:802        investpy.get_commodity_recent_data(commodity='copper',803                                           country=param['country'],804                                           as_json=param['as_json'],805                                           order=param['order'],806                                           interval='Daily')807        investpy.get_commodity_historical_data(commodity='copper',808                                               from_date='01/01/1990',809                                               to_date='01/01/2019',810                                               country=param['country'],811                                               as_json=param['as_json'],812                                               order=param['order'],813                                               interval='Daily')814    params = [815        {816            'commodity': 'copper',817            'country': None,818            'as_json': False819        },820        {821            'commodity': 'copper',822            'country': 'united states',823            'as_json': True824        }825    ]826    for param in params:827        investpy.get_commodity_information(commodity=param['commodity'], country=param['country'], as_json=param['as_json'])828    829    params = [830        {831            'group': 'metals',832            'as_json': True,833            'n_results': 100834        },835        {836            'group': 'metals',837            'as_json': False,838            'n_results': 100839        }840    ]841    for param in params:842        investpy.get_commodities_overview(group=param['group'], as_json=param['as_json'], n_results=param['n_results'])843    investpy.search_commodities(by='name', value='gold')844def test_investpy_cryptos():845    """846    This function checks that crypto currencies data retrieval functions listed in investpy work properly.847    """848    849    investpy.get_cryptos()850    investpy.get_cryptos_list()851    params = [852        {853            'columns': None,854            'as_json': False855        },856        {857            'columns': ['name', 'symbol', 'currency'],858            'as_json': False859        },860        {861            'columns': None,862            'as_json': True863        },    864    ]865    for param in params:866        investpy.get_cryptos_dict(columns=param['columns'],867                                  as_json=param['as_json'])868    params = [869        {870            'as_json': True,871            'order': 'ascending',872        },873        {874            'as_json': False,875            'order': 'ascending',876        },877        {878            'as_json': True,879            'order': 'descending',880        },881        {882            'as_json': False,883            'order': 'descending',884        },885    ]886    for param in params:887        investpy.get_crypto_recent_data(crypto='bitcoin',888                                        as_json=param['as_json'],889                                        order=param['order'],890                                        interval='Daily')891        investpy.get_crypto_historical_data(crypto='bitcoin',892                                            from_date='01/01/1990',893                                            to_date='01/01/2019',894                                            as_json=param['as_json'],895                                            order=param['order'],896                                            interval='Daily')897    params = [898        {899            'crypto': 'bitcoin',900            'as_json': False901        },902        {903            'crypto': 'bitcoin',904            'as_json': True905        }906    ]907    for param in params:908        investpy.get_crypto_information(crypto=param['crypto'], as_json=param['as_json'])909    910    params = [911        {912            'as_json': False,913            'n_results': 10914        },915        {916            'as_json': True,917            'n_results': 10918        },919        {920            'as_json': False,921            'n_results': 110922        },923        {924            'as_json': True,925            'n_results': 110926        },927        {928            'as_json': False,929            'n_results': None930        },931        {932            'as_json': True,933            'n_results': None934        },935    ]936    for param in params:937        investpy.get_cryptos_overview(as_json=param['as_json'], n_results=param['n_results'])938    investpy.search_cryptos(by='name', value='bitcoin')939def test_investpy_certificates():940    """941    This function checks that certificate data retrieval functions listed in investpy work properly.942    """943    params = [944        {945            'country': 'france',946        },947        {948            'country': None,949        },950    ]951    for param in params:952        investpy.get_certificates(country=param['country'])953        investpy.get_certificates_list(country=param['country'])954    params = [955        {956            'country': None,957            'columns': ['full_name', 'name'],958            'as_json': True959        },960        {961            'country': None,962            'columns': ['full_name', 'name'],963            'as_json': False964        },965        {966            'country': 'france',967            'columns': ['full_name', 'name'],968            'as_json': True969        },970        {971            'country': 'france',972            'columns': ['full_name', 'name'],973            'as_json': False974        },975        {976            'country': 'france',977            'columns': None,978            'as_json': False979        },980    ]981    for param in params:982        investpy.get_certificates_dict(country=param['country'],983                                       columns=param['columns'],984                                       as_json=param['as_json'])985    investpy.get_certificate_countries()986    params = [987        {988            'as_json': True,989            'order': 'ascending',990        },991        {992            'as_json': False,993            'order': 'ascending',994        },995        {996            'as_json': True,997            'order': 'descending',998        },999        {1000            'as_json': False,1001            'order': 'descending',1002        },1003    ]1004    for param in params:1005        investpy.get_certificate_recent_data(certificate='COMMERZBANK SG 31Dec99',1006                                             country='france',1007                                             as_json=param['as_json'],1008                                             order=param['order'],1009                                             interval='Daily')1010        investpy.get_certificate_historical_data(certificate='COMMERZBANK SG 31Dec99',1011                                                 country='france',1012                                                 from_date='01/01/1990',1013                                                 to_date='01/01/2019',1014                                                 as_json=param['as_json'],1015                                                 order=param['order'],1016                                                 interval='Daily')1017    params = [1018        {1019            'certificate': 'COMMERZBANK SG 31Dec99',1020            'country': 'france',1021            'as_json': False1022        },1023        {1024            'certificate': 'COMMERZBANK SG 31Dec99',1025            'country': 'france',1026            'as_json': True1027        }1028    ]1029    for param in params:1030        investpy.get_certificate_information(certificate=param['certificate'],1031                                             country=param['country'],1032                                             as_json=param['as_json'])1033    1034    params = [1035        {1036            'country': 'france',1037            'as_json': True,1038            'n_results': 101039        },1040        {1041            'country': 'france',1042            'as_json': False,1043            'n_results': 101044        }1045    ]1046    for param in params:1047        investpy.get_certificates_overview(country=param['country'],1048                                           as_json=param['as_json'],1049                                           n_results=param['n_results'])1050    investpy.search_certificates(by='name', value='COMMERZBANK')1051def test_investpy_search():1052    """1053    This function checks that investpy search function works properly.1054    """1055    params = [1056        {1057            'text': 'bbva',1058            'n_results': 5,1059            'filters': None1060        },1061        {1062            'text': 'spain 3y',1063            'n_results': 5,1064            'filters': None1065        },1066        {1067            'text': 'ibex 35',1068            'n_results': 5,1069            'filters': None1070        },1071        {1072            'text': 'bnp daxplus',1073            'n_results': 5,1074            'filters': None1075        },1076        {1077            'text': 'apple',1078            'n_results': None,1079            'filters': ['stocks']1080        },1081        {1082            'text': 'apple',1083            'n_results': 10,1084            'filters': ['stocks']1085        }1086    ]1087    for param in params:1088        results = investpy.search(text=param['text'],1089                                  n_results=param['n_results'],1090                                  filters=param['filters'])1091        dates = [1092            {1093                'from_date': '01/01/2018',1094                'to_date': '01/01/2019'1095            },1096            {1097                'from_date': '01/01/1990',1098                'to_date': '01/01/2019'1099            },1100        ]1101        for result in results:1102            print(result)1103            result.retrieve_recent_data()1104            for date in dates:1105                result.retrieve_historical_data(from_date=date['from_date'], to_date=date['to_date'])1106def test_investpy_news():1107    """1108    This function checks that investpy news retrieval functionality works as expected.1109    """1110    params = [1111        {1112            'time_zone': None,1113            'time_filter': 'time_only',1114            'countries': ['spain', 'france'],1115            'importances': ['high', 'low'],1116            'categories': ['credit', 'employment'],1117            'from_date': None,1118            'to_date': None1119        },1120        {1121            'time_zone': 'GMT -3:00',1122            'time_filter': 'time_only',1123            'countries': None,1124            'importances': None,1125            'categories': None,1126            'from_date': '01/01/2020',1127            'to_date': '01/02/2020'1128        }1129    ]1130    for param in params:1131        investpy.get_calendar(time_zone=param['time_zone'],1132                              time_filter=param['time_filter'],1133                              countries=param['countries'],1134                              importances=param['importances'],1135                              categories=param['categories'],1136                              from_date=param['from_date'],1137                              to_date=param['to_date'])1138def test_investpy_technical():1139    """1140    This function checks that investpy news retrieval functionality works as expected.1141    """1142    params = [1143        {1144            'name': 'bbva',1145            'country': 'spain',1146            'product_type': 'stock',1147            'interval': 'weekly',1148        },1149        {1150            'name': 'bbva mi inversion rf mixta fi',1151            'country': 'spain',1152            'product_type': 'fund',1153            'interval': 'daily',1154        },1155    ]1156    for param in params:1157        investpy.technical_indicators(name=param['name'],1158                                      country=param['country'],1159                                      product_type=param['product_type'],1160                                      interval=param['interval'])1161        investpy.moving_averages(name=param['name'],1162                                 country=param['country'],1163                                 product_type=param['product_type'],1164                                 interval=param['interval'])1165        investpy.pivot_points(name=param['name'],1166                              country=param['country'],1167                              product_type=param['product_type'],1168                              interval=param['interval'])1169if __name__ == '__main__':1170    test_investpy()1171    test_investpy_stocks()1172    test_investpy_funds()1173    test_investpy_etfs()1174    test_investpy_indices()1175    test_investpy_currency_crosses()1176    test_investpy_bonds()1177    test_investpy_commodities()1178    test_investpy_cryptos()1179    test_investpy_certificates()1180    test_investpy_search()1181    test_investpy_news()...test_client.py
Source:test_client.py  
...48    td = _init_client()49    return td.time_series(symbol=symbols, interval="1min", outputsize=1)50def test_get_stocks_list():51    td = _init_client()52    td.get_stocks_list(exchange='NASDAQ').as_json()53    td.get_stocks_list(exchange='NASDAQ').as_csv()54    td.get_stocks_list(exchange='NASDAQ').as_url()55def test_get_stock_exchanges_list():56    td = _init_client()57    td.get_stock_exchanges_list().as_json()58    td.get_stock_exchanges_list().as_csv()59    td.get_stock_exchanges_list().as_url()60def test_get_forex_pairs_list():61    td = _init_client()62    td.get_forex_pairs_list().as_json()63    td.get_forex_pairs_list().as_csv()64    td.get_forex_pairs_list().as_url()65def test_get_cryptocurrencies_list():66    td = _init_client()67    td.get_cryptocurrencies_list().as_json()68    td.get_cryptocurrencies_list().as_csv()69    td.get_cryptocurrencies_list().as_url()70def test_get_etf_list():71    td = _init_client()72    td.get_etf_list().as_json()73    td.get_etf_list().as_csv()74    td.get_etf_list().as_url()75def test_get_indices_list():76    td = _init_client()77    td.get_indices_list().as_json()78    td.get_indices_list().as_csv()79    td.get_indices_list().as_url()80def test_get_technical_indicators_list():81    td = _init_client()82    td.get_technical_indicators_list().as_json()83    td.get_technical_indicators_list().as_url()84def test_get_exchanges_list():85    td = _init_client()86    td.get_exchanges_list().as_json()87    td.get_exchanges_list().as_csv()88    td.get_exchanges_list().as_url()89def test_symbol_search():90    td = _init_client()91    td.symbol_search().as_json()92    td.symbol_search().as_url()93def test_earliest_timestamp():94    td = _init_client()95    td.get_earliest_timestamp(symbol="AAPL", interval="1day").as_json()96    td.get_earliest_timestamp(symbol="AAPL", interval="1day").as_url()97def test_exchange_rate():98    td = _init_client()99    td.exchange_rate(symbol="EUR/USD").as_json()100    td.exchange_rate(symbol="EUR/USD").as_url()101def test_currency_conversion():102    td = _init_client()103    td.currency_conversion(symbol="EUR/USD", amount=100).as_json()104    td.currency_conversion(symbol="EUR/USD", amount=100).as_url()105def test_quote():106    td = _init_client()107    td.quote(symbol="AAPL").as_json()108    td.quote(symbol="AAPL").as_url()109def test_price():110    td = _init_client()111    td.price(symbol="AAPL").as_json()112    td.price(symbol="AAPL").as_url()113def test_eod():114    td = _init_client()115    td.eod(symbol="AAPL").as_json()116    td.eod(symbol="AAPL").as_url()117def test_api_usage():118    td = _init_client()119    td.api_usage().as_json()120    td.api_usage().as_url()121def test_logo():122    td = _init_client()123    td.get_logo(symbol="AAPL").as_json()124    td.get_logo(symbol="AAPL").as_url()125def test_profile():126    td = _init_client()127    td.get_profile(symbol="AAPL").as_json()128    td.get_profile(symbol="AAPL").as_url()129def test_dividends():130    td = _init_client()131    td.get_dividends(symbol="AAPL").as_json()132    td.get_dividends(symbol="AAPL").as_url()133def test_splits():134    td = _init_client()135    td.get_splits(symbol="AAPL").as_json()136    td.get_splits(symbol="AAPL").as_url()137def test_earnings():138    td = _init_client()139    td.get_earnings(symbol="AAPL").as_json()140    td.get_earnings(symbol="AAPL").as_url()141def test_statistics():142    td = _init_client()143    td.get_statistics(symbol="AAPL").as_json()144    td.get_statistics(symbol="AAPL").as_url()145def test_insider_transactions():146    td = _init_client()147    td.get_insider_transactions(symbol="AAPL").as_json()148    td.get_insider_transactions(symbol="AAPL").as_url()149def test_income_statement():150    td = _init_client()151    td.get_income_statement(symbol="AAPL").as_json()152    td.get_income_statement(symbol="AAPL").as_url()153def test_balance_sheet():154    td = _init_client()155    td.get_balance_sheet(symbol="AAPL").as_json()156    td.get_balance_sheet(symbol="AAPL").as_url()157def test_cash_flow():158    td = _init_client()159    td.get_cash_flow(symbol="AAPL").as_json()160    td.get_cash_flow(symbol="AAPL").as_url()161def test_options_expiration():162    td = _init_client()163    td.get_options_expiration(symbol="AAPL").as_json()164    td.get_options_expiration(symbol="AAPL").as_url()165def test_options_chain():166    td = _init_client()167    expiration_date = td.get_options_expiration(symbol="AAPL").as_json()['dates'][0]168    td.get_options_chain(symbol="AAPL", expiration_date=expiration_date).as_json()169    td.get_options_chain(symbol="AAPL", expiration_date=expiration_date).as_url()170def test_key_executives():171    td = _init_client()172    td.get_key_executives(symbol="AAPL").as_json()173    td.get_key_executives(symbol="AAPL").as_url()174def test_institutional_holders():175    td = _init_client()176    td.get_institutional_holders(symbol="AAPL").as_json()177    td.get_institutional_holders(symbol="AAPL").as_url()178def test_fund_holders():179    td = _init_client()180    td.get_fund_holders(symbol="AAPL").as_json()181    td.get_fund_holders(symbol="AAPL").as_url()182def test_time_series():183    ts = _init_ts()184    ts.as_json()185    ts.as_csv()186    ts.as_pandas()187    ts.as_plotly_figure()188    ts.as_url()189    plt.close()190def test_time_series_get_ad():191    ts = _init_ts()192    ts.with_ad().as_json()193    ts.with_ad().as_csv()194    ts.with_ad().as_pandas()195    ts.with_ad().as_plotly_figure()196    ts.with_ad().as_url()197    plt.close()198def test_time_series_get_adosc():199    ts = _init_ts()200    ts.with_adosc().as_json()201    ts.with_adosc().as_csv()202    ts.with_adosc().as_pandas()203    ts.with_adosc().as_plotly_figure()204    ts.with_adosc().as_url()205    plt.close()206def test_time_series_get_adx():207    ts = _init_ts()208    ts.with_adx().as_json()209    ts.with_adx().as_csv()210    ts.with_adx().as_pandas()211    ts.with_adx().as_plotly_figure()212    ts.with_adx().as_url()213    plt.close()214def test_time_series_get_adxr():215    ts = _init_ts()216    ts.with_adxr().as_json()217    ts.with_adxr().as_csv()218    ts.with_adxr().as_pandas()219    ts.with_adxr().as_plotly_figure()220    ts.with_adxr().as_url()221    plt.close()222def test_time_series_get_apo():223    ts = _init_ts()224    ts.with_apo().as_json()225    ts.with_apo().as_csv()226    ts.with_apo().as_pandas()227    ts.with_apo().as_plotly_figure()228    ts.with_apo().as_url()229    plt.close()230def test_time_series_get_aroon():231    ts = _init_ts()232    ts.with_aroon().as_json()233    ts.with_aroon().as_csv()234    ts.with_aroon().as_pandas()235    ts.with_aroon().as_plotly_figure()236    ts.with_aroon().as_url()237    plt.close()238def test_time_series_get_aroonosc():239    ts = _init_ts()240    ts.with_aroonosc().as_json()241    ts.with_aroonosc().as_csv()242    ts.with_aroonosc().as_pandas()243    ts.with_aroonosc().as_plotly_figure()244    ts.with_aroonosc().as_url()245    plt.close()246def test_time_series_get_atr():247    ts = _init_ts()248    ts.with_atr().as_json()249    ts.with_atr().as_csv()250    ts.with_atr().as_pandas()251    ts.with_atr().as_plotly_figure()252    ts.with_atr().as_url()253    plt.close()254def test_time_series_get_avgprice():255    ts = _init_ts()256    ts.with_avgprice().as_json()257    ts.with_avgprice().as_csv()258    ts.with_avgprice().as_pandas()259    ts.with_avgprice().as_plotly_figure()260    ts.with_avgprice().as_url()261    plt.close()262def test_time_series_get_bbands():263    ts = _init_ts()264    ts.with_bbands().as_json()265    ts.with_bbands().as_csv()266    ts.with_bbands().as_pandas()267    ts.with_bbands().as_plotly_figure()268    ts.with_bbands().as_url()269    plt.close()270def test_time_series_get_percent_b():271    ts = _init_ts()272    ts.with_percent_b().as_json()273    ts.with_percent_b().as_csv()274    ts.with_percent_b().as_pandas()275    ts.with_percent_b().as_plotly_figure()276    ts.with_percent_b().as_url()277    plt.close()278def test_time_series_get_bop():279    ts = _init_ts()280    ts.with_bop().as_json()281    ts.with_bop().as_csv()282    ts.with_bop().as_pandas()283    ts.with_bop().as_plotly_figure()284    ts.with_bop().as_url()285    plt.close()286def test_time_series_get_cci():287    ts = _init_ts()288    ts.with_cci().as_json()289    ts.with_cci().as_csv()290    ts.with_cci().as_pandas()291    ts.with_cci().as_plotly_figure()292    ts.with_cci().as_url()293    plt.close()294def test_time_series_get_ceil():295    ts = _init_ts()296    ts.with_ceil().as_json()297    ts.with_ceil().as_csv()298    ts.with_ceil().as_pandas()299    ts.with_ceil().as_plotly_figure()300    ts.with_ceil().as_url()301    plt.close()302def test_time_series_get_cmo():303    ts = _init_ts()304    ts.with_cmo().as_json()305    ts.with_cmo().as_csv()306    ts.with_cmo().as_pandas()307    ts.with_cmo().as_plotly_figure()308    ts.with_cmo().as_url()309    plt.close()310def test_time_series_get_coppock():311    ts = _init_ts()312    ts.with_coppock().as_json()313    ts.with_coppock().as_csv()314    ts.with_coppock().as_pandas()315    ts.with_coppock().as_plotly_figure()316    ts.with_coppock().as_url()317    plt.close()318def test_time_series_get_dema():319    ts = _init_ts()320    ts.with_dema().as_json()321    ts.with_dema().as_csv()322    ts.with_dema().as_pandas()323    ts.with_dema().as_plotly_figure()324    ts.with_dema().as_url()325    plt.close()326def test_time_series_get_dx():327    ts = _init_ts()328    ts.with_dx().as_json()329    ts.with_dx().as_csv()330    ts.with_dx().as_pandas()331    ts.with_dx().as_plotly_figure()332    ts.with_dx().as_url()333    plt.close()334def test_time_series_get_ema():335    ts = _init_ts()336    ts.with_ema().as_json()337    ts.with_ema().as_csv()338    ts.with_ema().as_pandas()339    ts.with_ema().as_plotly_figure()340    ts.with_ema().as_url()341    plt.close()342def test_time_series_get_exp():343    ts = _init_ts()344    ts.with_exp().as_json()345    ts.with_exp().as_csv()346    ts.with_exp().as_pandas()347    ts.with_exp().as_plotly_figure()348    ts.with_exp().as_url()349    plt.close()350def test_time_series_get_floor():351    ts = _init_ts()352    ts.with_floor().as_json()353    ts.with_floor().as_csv()354    ts.with_floor().as_pandas()355    ts.with_floor().as_plotly_figure()356    ts.with_floor().as_url()357    plt.close()358def test_time_series_get_heikinashicandles():359    ts = _init_ts()360    ts.with_heikinashicandles().as_json()361    ts.with_heikinashicandles().as_csv()362    ts.with_heikinashicandles().as_pandas()363    ts.with_heikinashicandles().as_plotly_figure()364    ts.with_heikinashicandles().as_url()365    plt.close()366def test_time_series_get_hlc3():367    ts = _init_ts()368    ts.with_hlc3().as_json()369    ts.with_hlc3().as_csv()370    ts.with_hlc3().as_pandas()371    ts.with_hlc3().as_plotly_figure()372    ts.with_hlc3().as_url()373    plt.close()374def test_time_series_get_ht_dcperiod():375    ts = _init_ts()376    ts.with_ht_dcperiod().as_json()377    ts.with_ht_dcperiod().as_csv()378    ts.with_ht_dcperiod().as_pandas()379    ts.with_ht_dcperiod().as_plotly_figure()380    ts.with_ht_dcperiod().as_url()381    plt.close()382def test_time_series_get_ht_dcphase():383    ts = _init_ts()384    ts.with_ht_dcphase().as_json()385    ts.with_ht_dcphase().as_csv()386    ts.with_ht_dcphase().as_pandas()387    ts.with_ht_dcphase().as_plotly_figure()388    ts.with_ht_dcphase().as_url()389    plt.close()390def test_time_series_get_ht_phasor():391    ts = _init_ts()392    ts.with_ht_phasor().as_json()393    ts.with_ht_phasor().as_csv()394    ts.with_ht_phasor().as_pandas()395    ts.with_ht_phasor().as_plotly_figure()396    ts.with_ht_phasor().as_url()397    plt.close()398def test_time_series_get_ht_sine():399    ts = _init_ts()400    ts.with_ht_sine().as_json()401    ts.with_ht_sine().as_csv()402    ts.with_ht_sine().as_pandas()403    ts.with_ht_sine().as_plotly_figure()404    ts.with_ht_sine().as_url()405    plt.close()406def test_time_series_get_ht_trendline():407    ts = _init_ts()408    ts.with_ht_trendline().as_json()409    ts.with_ht_trendline().as_csv()410    ts.with_ht_trendline().as_pandas()411    ts.with_ht_trendline().as_plotly_figure()412    ts.with_ht_trendline().as_url()413    plt.close()414def test_time_series_get_ht_trendmode():415    ts = _init_ts()416    ts.with_ht_trendmode().as_json()417    ts.with_ht_trendmode().as_csv()418    ts.with_ht_trendmode().as_pandas()419    ts.with_ht_trendmode().as_plotly_figure()420    ts.with_ht_trendmode().as_url()421    plt.close()422def test_time_series_get_ichimoku():423    ts = _init_ts()424    ts.with_ichimoku().as_json()425    ts.with_ichimoku().as_csv()426    ts.with_ichimoku().as_pandas()427    ts.with_ichimoku().as_plotly_figure()428    ts.with_ichimoku().as_url()429    plt.close()430def test_time_series_get_kama():431    ts = _init_ts()432    ts.with_kama().as_json()433    ts.with_kama().as_csv()434    ts.with_kama().as_pandas()435    ts.with_kama().as_plotly_figure()436    ts.with_kama().as_url()437    plt.close()438def test_time_series_get_keltner():439    ts = _init_ts()440    ts.with_keltner().as_json()441    ts.with_keltner().as_csv()442    ts.with_keltner().as_pandas()443    ts.with_keltner().as_plotly_figure()444    ts.with_keltner().as_url()445    plt.close()446def test_time_series_get_kst():447    ts = _init_ts()448    ts.with_kst().as_json()449    ts.with_kst().as_csv()450    ts.with_kst().as_pandas()451    ts.with_kst().as_plotly_figure()452    ts.with_kst().as_url()453    plt.close()454def test_time_series_get_linearreg():455    ts = _init_ts()456    ts.with_linearreg().as_json()457    ts.with_linearreg().as_csv()458    ts.with_linearreg().as_pandas()459    ts.with_linearreg().as_plotly_figure()460    ts.with_linearreg().as_url()461    plt.close()462def test_time_series_get_linearregangle():463    ts = _init_ts()464    ts.with_linearregangle().as_json()465    ts.with_linearregangle().as_csv()466    ts.with_linearregangle().as_pandas()467    ts.with_linearregangle().as_plotly_figure()468    ts.with_linearregangle().as_url()469    plt.close()470def test_time_series_get_linearregintercept():471    ts = _init_ts()472    ts.with_linearregintercept().as_json()473    ts.with_linearregintercept().as_csv()474    ts.with_linearregintercept().as_pandas()475    ts.with_linearregintercept().as_plotly_figure()476    ts.with_linearregintercept().as_url()477    plt.close()478def test_time_series_get_linearregslope():479    ts = _init_ts()480    ts.with_linearregslope().as_json()481    ts.with_linearregslope().as_csv()482    ts.with_linearregslope().as_pandas()483    ts.with_linearregslope().as_plotly_figure()484    ts.with_linearregslope().as_url()485    plt.close()486def test_time_series_get_ln():487    ts = _init_ts()488    ts.with_ln().as_json()489    ts.with_ln().as_csv()490    ts.with_ln().as_pandas()491    ts.with_ln().as_plotly_figure()492    ts.with_ln().as_url()493    plt.close()494def test_time_series_get_log10():495    ts = _init_ts()496    ts.with_log10().as_json()497    ts.with_log10().as_csv()498    ts.with_log10().as_pandas()499    ts.with_log10().as_plotly_figure()500    ts.with_log10().as_url()501    plt.close()502def test_time_series_get_ma():503    ts = _init_ts()504    ts.with_ma().as_json()505    ts.with_ma().as_csv()506    ts.with_ma().as_pandas()507    ts.with_ma().as_plotly_figure()508    ts.with_ma().as_url()509    plt.close()510def test_time_series_get_macd():511    ts = _init_ts()512    ts.with_macd().as_json()513    ts.with_macd().as_csv()514    ts.with_macd().as_pandas()515    ts.with_macd().as_plotly_figure()516    ts.with_macd().as_url()517    plt.close()518def test_time_series_get_macdext():519    ts = _init_ts()520    ts.with_macdext().as_json()521    ts.with_macdext().as_csv()522    ts.with_macdext().as_pandas()523    ts.with_macdext().as_plotly_figure()524    ts.with_macdext().as_url()525    plt.close()526def test_time_series_get_mama():527    ts = _init_ts()528    ts.with_mama().as_json()529    ts.with_mama().as_csv()530    ts.with_mama().as_pandas()531    ts.with_mama().as_plotly_figure()532    ts.with_mama().as_url()533    plt.close()534def test_time_series_get_max():535    ts = _init_ts()536    ts.with_max().as_json()537    ts.with_max().as_csv()538    ts.with_max().as_pandas()539    ts.with_max().as_plotly_figure()540    ts.with_max().as_url()541    plt.close()542def test_time_series_get_maxindex():543    ts = _init_ts()544    ts.with_maxindex().as_json()545    ts.with_maxindex().as_csv()546    ts.with_maxindex().as_pandas()547    ts.with_maxindex().as_plotly_figure()548    ts.with_maxindex().as_url()549    plt.close()550def test_time_series_get_mcginley_dynamic():551    ts = _init_ts()552    ts.with_mcginley_dynamic().as_json()553    ts.with_mcginley_dynamic().as_csv()554    ts.with_mcginley_dynamic().as_pandas()555    ts.with_mcginley_dynamic().as_plotly_figure()556    ts.with_mcginley_dynamic().as_url()557    plt.close()558def test_time_series_get_medprice():559    ts = _init_ts()560    ts.with_medprice().as_json()561    ts.with_medprice().as_csv()562    ts.with_medprice().as_pandas()563    ts.with_medprice().as_plotly_figure()564    ts.with_medprice().as_url()565    plt.close()566def test_time_series_get_mfi():567    ts = _init_ts()568    ts.with_mfi().as_json()569    ts.with_mfi().as_csv()570    ts.with_mfi().as_pandas()571    ts.with_mfi().as_plotly_figure()572    ts.with_mfi().as_url()573    plt.close()574def test_time_series_get_midpoint():575    ts = _init_ts()576    ts.with_midpoint().as_json()577    ts.with_midpoint().as_csv()578    ts.with_midpoint().as_pandas()579    ts.with_midpoint().as_plotly_figure()580    ts.with_midpoint().as_url()581    plt.close()582def test_time_series_get_midprice():583    ts = _init_ts()584    ts.with_midprice().as_json()585    ts.with_midprice().as_csv()586    ts.with_midprice().as_pandas()587    ts.with_midprice().as_plotly_figure()588    ts.with_midprice().as_url()589    plt.close()590def test_time_series_get_min():591    ts = _init_ts()592    ts.with_min().as_json()593    ts.with_min().as_csv()594    ts.with_min().as_pandas()595    ts.with_min().as_plotly_figure()596    ts.with_min().as_url()597    plt.close()598def test_time_series_get_minindex():599    ts = _init_ts()600    ts.with_minindex().as_json()601    ts.with_minindex().as_csv()602    ts.with_minindex().as_pandas()603    ts.with_minindex().as_plotly_figure()604    ts.with_minindex().as_url()605    plt.close()606def test_time_series_get_minmax():607    ts = _init_ts()608    ts.with_minmax().as_json()609    ts.with_minmax().as_csv()610    ts.with_minmax().as_pandas()611    ts.with_minmax().as_plotly_figure()612    ts.with_minmax().as_url()613    plt.close()614def test_time_series_get_minmaxindex():615    ts = _init_ts()616    ts.with_minmaxindex().as_json()617    ts.with_minmaxindex().as_csv()618    ts.with_minmaxindex().as_pandas()619    ts.with_minmaxindex().as_plotly_figure()620    ts.with_minmaxindex().as_url()621    plt.close()622def test_time_series_get_minus_di():623    ts = _init_ts()624    ts.with_minus_di().as_json()625    ts.with_minus_di().as_csv()626    ts.with_minus_di().as_pandas()627    ts.with_minus_di().as_plotly_figure()628    ts.with_minus_di().as_url()629    plt.close()630def test_time_series_get_minus_dm():631    ts = _init_ts()632    ts.with_minus_dm().as_json()633    ts.with_minus_dm().as_csv()634    ts.with_minus_dm().as_pandas()635    ts.with_minus_dm().as_plotly_figure()636    ts.with_minus_dm().as_url()637    plt.close()638def test_time_series_get_mom():639    ts = _init_ts()640    ts.with_mom().as_json()641    ts.with_mom().as_csv()642    ts.with_mom().as_pandas()643    ts.with_mom().as_plotly_figure()644    ts.with_mom().as_url()645    plt.close()646def test_time_series_get_natr():647    ts = _init_ts()648    ts.with_natr().as_json()649    ts.with_natr().as_csv()650    ts.with_natr().as_pandas()651    ts.with_natr().as_plotly_figure()652    ts.with_natr().as_url()653    plt.close()654def test_time_series_get_obv():655    ts = _init_ts()656    ts.with_obv().as_json()657    ts.with_obv().as_csv()658    ts.with_obv().as_pandas()659    ts.with_obv().as_plotly_figure()660    ts.with_obv().as_url()661    plt.close()662def test_time_series_get_plus_di():663    ts = _init_ts()664    ts.with_plus_di().as_json()665    ts.with_plus_di().as_csv()666    ts.with_plus_di().as_pandas()667    ts.with_plus_di().as_plotly_figure()668    ts.with_plus_di().as_url()669    plt.close()670def test_time_series_get_plus_dm():671    ts = _init_ts()672    ts.with_plus_dm().as_json()673    ts.with_plus_dm().as_csv()674    ts.with_plus_dm().as_pandas()675    ts.with_plus_dm().as_plotly_figure()676    ts.with_plus_dm().as_url()677    plt.close()678def test_time_series_get_ppo():679    ts = _init_ts()680    ts.with_ppo().as_json()681    ts.with_ppo().as_csv()682    ts.with_ppo().as_pandas()683    ts.with_ppo().as_plotly_figure()684    ts.with_ppo().as_url()685    plt.close()686def test_time_series_get_roc():687    ts = _init_ts()688    ts.with_roc().as_json()689    ts.with_roc().as_csv()690    ts.with_roc().as_pandas()691    ts.with_roc().as_plotly_figure()692    ts.with_roc().as_url()693    plt.close()694def test_time_series_get_rocp():695    ts = _init_ts()696    ts.with_rocp().as_json()697    ts.with_rocp().as_csv()698    ts.with_rocp().as_pandas()699    ts.with_rocp().as_plotly_figure()700    ts.with_rocp().as_url()701    plt.close()702def test_time_series_get_rocr():703    ts = _init_ts()704    ts.with_rocr().as_json()705    ts.with_rocr().as_csv()706    ts.with_rocr().as_pandas()707    ts.with_rocr().as_plotly_figure()708    ts.with_rocr().as_url()709    plt.close()710def test_time_series_get_rocr100():711    ts = _init_ts()712    ts.with_rocr100().as_json()713    ts.with_rocr100().as_csv()714    ts.with_rocr100().as_pandas()715    ts.with_rocr100().as_plotly_figure()716    ts.with_rocr100().as_url()717    plt.close()718def test_time_series_get_rsi():719    ts = _init_ts()720    ts.with_rsi().as_json()721    ts.with_rsi().as_csv()722    ts.with_rsi().as_pandas()723    ts.with_rsi().as_plotly_figure()724    ts.with_rsi().as_url()725    plt.close()726def test_time_series_get_sar():727    ts = _init_ts()728    ts.with_sar().as_json()729    ts.with_sar().as_csv()730    ts.with_sar().as_pandas()731    ts.with_sar().as_plotly_figure()732    ts.with_sar().as_url()733    plt.close()734def test_time_series_get_sma():735    ts = _init_ts()736    ts.with_sma().as_json()737    ts.with_sma().as_csv()738    ts.with_sma().as_pandas()739    ts.with_sma().as_plotly_figure()740    ts.with_sma().as_url()741    plt.close()742def test_time_series_get_sqrt():743    ts = _init_ts()744    ts.with_sqrt().as_json()745    ts.with_sqrt().as_csv()746    ts.with_sqrt().as_pandas()747    ts.with_sqrt().as_plotly_figure()748    ts.with_sqrt().as_url()749    plt.close()750def test_time_series_get_stddev():751    ts = _init_ts()752    ts.with_stddev().as_json()753    ts.with_stddev().as_csv()754    ts.with_stddev().as_pandas()755    ts.with_stddev().as_plotly_figure()756    ts.with_stddev().as_url()757    plt.close()758def test_time_series_get_stoch():759    ts = _init_ts()760    ts.with_stoch().as_json()761    ts.with_stoch().as_csv()762    ts.with_stoch().as_pandas()763    ts.with_stoch().as_plotly_figure()764    ts.with_stoch().as_url()765    plt.close()766def test_time_series_get_stochf():767    ts = _init_ts()768    ts.with_stochf().as_json()769    ts.with_stochf().as_csv()770    ts.with_stochf().as_pandas()771    ts.with_stochf().as_plotly_figure()772    ts.with_stochf().as_url()773    plt.close()774def test_time_series_get_stochrsi():775    ts = _init_ts()776    ts.with_stochrsi().as_json()777    ts.with_stochrsi().as_csv()778    ts.with_stochrsi().as_pandas()779    ts.with_stochrsi().as_plotly_figure()780    ts.with_stochrsi().as_url()781    plt.close()782def test_time_series_get_supertrend():783    ts = _init_ts()784    ts.with_supertrend().as_json()785    ts.with_supertrend().as_csv()786    ts.with_supertrend().as_pandas()787    ts.with_supertrend().as_plotly_figure()788    ts.with_supertrend().as_url()789    plt.close()790def test_time_series_get_t3ma():791    ts = _init_ts()792    ts.with_t3ma().as_json()793    ts.with_t3ma().as_csv()794    ts.with_t3ma().as_pandas()795    ts.with_t3ma().as_plotly_figure()796    ts.with_t3ma().as_url()797    plt.close()798def test_time_series_get_tema():799    ts = _init_ts()800    ts.with_tema().as_json()801    ts.with_tema().as_csv()802    ts.with_tema().as_pandas()803    ts.with_tema().as_plotly_figure()804    ts.with_tema().as_url()805    plt.close()806def test_time_series_get_trange():807    ts = _init_ts()808    ts.with_trange().as_json()809    ts.with_trange().as_csv()810    ts.with_trange().as_pandas()811    ts.with_trange().as_plotly_figure()812    ts.with_trange().as_url()813    plt.close()814def test_time_series_get_trima():815    ts = _init_ts()816    ts.with_trima().as_json()817    ts.with_trima().as_csv()818    ts.with_trima().as_pandas()819    ts.with_trima().as_plotly_figure()820    ts.with_trima().as_url()821    plt.close()822def test_time_series_get_tsf():823    ts = _init_ts()824    ts.with_tsf().as_json()825    ts.with_tsf().as_csv()826    ts.with_tsf().as_pandas()827    ts.with_tsf().as_plotly_figure()828    ts.with_tsf().as_url()829    plt.close()830def test_time_series_get_typprice():831    ts = _init_ts()832    ts.with_typprice().as_json()833    ts.with_typprice().as_csv()834    ts.with_typprice().as_pandas()835    ts.with_typprice().as_plotly_figure()836    ts.with_typprice().as_url()837    plt.close()838def test_time_series_get_ultosc():839    ts = _init_ts()840    ts.with_ultosc().as_json()841    ts.with_ultosc().as_csv()842    ts.with_ultosc().as_pandas()843    ts.with_ultosc().as_plotly_figure()844    ts.with_ultosc().as_url()845    plt.close()846def test_time_series_get_var():847    ts = _init_ts()848    ts.with_var().as_json()849    ts.with_var().as_csv()850    ts.with_var().as_pandas()851    ts.with_var().as_plotly_figure()852    ts.with_var().as_url()853    plt.close()854def test_time_series_get_vwap():855    ts = _init_ts()856    ts.with_vwap().as_json()857    ts.with_vwap().as_csv()858    ts.with_vwap().as_pandas()859    ts.with_vwap().as_plotly_figure()860    ts.with_vwap().as_url()861    plt.close()862def test_time_series_get_wclprice():863    ts = _init_ts()864    ts.with_wclprice().as_json()865    ts.with_wclprice().as_csv()866    ts.with_wclprice().as_pandas()867    ts.with_wclprice().as_plotly_figure()868    ts.with_wclprice().as_url()869    plt.close()870def test_time_series_get_willr():871    ts = _init_ts()872    ts.with_willr().as_json()873    ts.with_willr().as_csv()874    ts.with_willr().as_pandas()875    ts.with_willr().as_plotly_figure()876    ts.with_willr().as_url()877    plt.close()878def test_time_series_get_wma():879    ts = _init_ts()880    ts.with_wma().as_json()881    ts.with_wma().as_csv()882    ts.with_wma().as_pandas()883    ts.with_wma().as_plotly_figure()884    ts.with_wma().as_url()885    plt.close()886def _init_chart():887    td = _init_client()888    return (889        td.time_series(symbol="AAPL", interval="1min")890        .with_ad()891        .with_adosc()892        .with_adx()893        .with_adxr()894        .with_apo()895        .with_aroon()896        .with_aroonosc()897        .with_atr()898        .with_avgprice()899        .with_bbands()900        .with_percent_b()901        .with_bop()902        .with_cci()903        .with_ceil()904        .with_cmo()905        .with_coppock()906        .with_ceil()907        .with_dema()908        .with_dx()909        .with_ema()910        .with_exp()911        .with_floor()912        .with_heikinashicandles()913        .with_hlc3()914        .with_ht_dcperiod()915        .with_ht_dcphase()916        .with_ht_phasor()917        .with_ht_sine()918        .with_ht_trendline()919        .with_ht_trendmode()920        .with_ichimoku()921        .with_kama()922        .with_keltner()923        .with_kst()924        .with_linearreg()925        .with_linearregangle()926        .with_linearregintercept()927        .with_linearregslope()928        .with_ln()929        .with_log10()930        .with_ma()931        .with_macd()932        .with_macdext()933        .with_mama()934        .with_max()935        .with_maxindex()936        .with_mcginley_dynamic()937        .with_medprice()938        .with_midpoint()939        .with_midprice()940        .with_min()941        .with_minindex()942        .with_minmax()943        .with_minmaxindex()944        .with_minus_di()945        .with_minus_dm()946        .with_mom()947        .with_natr()948        .with_obv()949        .with_plus_di()950        .with_plus_dm()951        .with_ppo()952        .with_roc()953        .with_rocp()954        .with_rocr()955        .with_rocr100()956        .with_rsi()957        .with_sar()958        .with_sma()959        .with_sqrt()960        .with_stddev()961        .with_stoch()962        .with_stochf()963        .with_stochrsi()964        .with_supertrend()965        .with_t3ma()966        .with_tema()967        .with_trange()968        .with_trima()969        .with_tsf()970        .with_typprice()971        .with_ultosc()972        .with_var()973        .with_vwap()974        .with_wclprice()975        .with_willr()976        .with_wma()977    )978def test_chart_json():979    chart = _init_chart()980    chart.as_json()981def test_chart_csv():982    chart = _init_chart()983    chart.as_csv()984def test_chart_pandas():985    chart = _init_chart()986    chart.as_pandas()987def test_chart_url():988    chart = _init_chart()989    chart.as_url()990# def test_chart_plot():991#     chart = _init_chart()992#     chart.as_plotly_figure()993    # plt.close()994def test_string_batch():995    batch_ts = _init_batch_ts('AAPL,QQQ,IXIC,EUR/USD,BTC/USD,')996    batch_ts.with_macd().with_stoch().as_json()997    batch_ts.with_ema().with_bbands().as_pandas()998    batch_ts.with_ema().with_bbands().as_url()999def test_list_batch():1000    batch_ts = _init_batch_ts(['AAPL', 'QQQ', 'IXIC', 'EUR/USD', 'BTC/USD'])1001    batch_ts.with_macd().with_stoch().as_json()1002    batch_ts.with_ema().with_bbands().as_pandas()1003    batch_ts.with_ema().with_bbands().as_url()1004@patch('twelvedata.http_client.requests.get', return_value=_fake_resp(500))1005def test_http_internal_server_error_response(mock_get):1006    http_client = DefaultHttpClient(API_URL)1007    with pytest.raises(InternalServerError):1008        http_client.get('/fake_url')1009    mock_get.assert_called_once_with(API_URL + '/fake_url', timeout=30, params={'source': 'python'})1010@patch('twelvedata.http_client.requests.get', return_value=_fake_json_resp(1011    json.loads('{"status": "error", "code": 500, "message": "error message"}')),1012)1013def test_http_internal_server_error_response_in_json(mock_get):1014    http_client = DefaultHttpClient(API_URL)1015    with pytest.raises(InternalServerError) as err:...test.py
Source:test.py  
1from regression_tests import *2import json3class TestExtractMachOIsArchiveJson(Test):4    settings = TestSettings(5        tool='retdec-macho-extractor',6        input='archive',7        args='--check-archive'8    )9    def test_check_control_json(self):10        assert 'is a static library.' in self.retdec_macho_extractor.output11class TestExtractMachONotArchiveJson(Test):12    settings = TestSettings(13        tool='retdec-macho-extractor',14        input='non-archive',15        args='--check-archive'16    )17    def test_check_control_json(self):18        assert 'NOT a static library.' in self.retdec_macho_extractor.output19class TestExtractMachONotArchiveObjectsJson(Test):20    settings = TestSettings(21        tool='retdec-macho-extractor',22        input='non-archive',23        args='--objects'24    )25    def test_check_control_json(self):26        assert 'is not an archive!' in self.retdec_macho_extractor.output27class TestExtractMachOJson(Test):28    settings = TestSettings(29        tool='retdec-macho-extractor',30        input='non-archive',31        args='--json'32    )33    def test_check_extract_json(self):34        as_json = json.loads(self.retdec_macho_extractor.output)35        self.assertEqual(as_json['architectures'][0]['name'], 'i386')36        self.assertEqual(as_json['architectures'][0]['index'], 0)37        self.assertEqual(as_json['architectures'][0]['cpuFamily'], 'x86')38        self.assertEqual(as_json['architectures'][1]['name'], 'powerpc')39        self.assertEqual(as_json['architectures'][1]['index'], 1)40        self.assertEqual(as_json['architectures'][1]['cpuFamily'], 'powerpc')41class TestExtractArchiveJson(Test):42    settings = TestSettings(43        tool='retdec-macho-extractor',44        input='archive',45        args='--json'46    )47    def test_check_extract_json(self):48        as_json = json.loads(self.retdec_macho_extractor.output)49        self.assertEqual(as_json['architectures'][0]['name'], 'armv7')50        self.assertEqual(as_json['architectures'][0]['index'], 0)51        self.assertEqual(as_json['architectures'][0]['cpuFamily'], 'arm')52        self.assertEqual(as_json['architectures'][1]['name'], 'arm64')53        self.assertEqual(as_json['architectures'][1]['index'], 1)54        self.assertEqual(as_json['architectures'][1]['cpuFamily'], 'arm64')55class TestExtractArchiveJsonWithOjects(Test):56    settings = TestSettings(57        tool='retdec-macho-extractor',58        input='archive',59        args='--json --objects'60    )61    def test_check_extract_json(self):62        as_json = json.loads(self.retdec_macho_extractor.output)63        self.assertEqual(as_json['architectures'][0]['name'], 'armv7')64        self.assertEqual(as_json['architectures'][0]['index'], 0)65        self.assertEqual(as_json['architectures'][0]['cpuFamily'], 'arm')66        self.assertEqual(67            as_json['architectures'][0]['objects'][0]['name'],68            'TatvikMpeg2DemuxBitStreamReader.o'69        )70        self.assertEqual(71            as_json['architectures'][0]['objects'][1]['name'],72            'TatvikMpeg2DemuxPESDecoder.o'73        )74        self.assertEqual(75            as_json['architectures'][0]['objects'][2]['name'],76            'TatvikMpeg2TSDemuxer.o'77        )78        self.assertEqual(79            as_json['architectures'][0]['objects'][3]['name'],80            'TatvikTransportStreamParser.o'81        )82        self.assertEqual(as_json['architectures'][1]['name'], 'arm64')83        self.assertEqual(as_json['architectures'][1]['index'], 1)84        self.assertEqual(as_json['architectures'][1]['cpuFamily'], 'arm64')85        self.assertEqual(86            as_json['architectures'][1]['objects'][0]['name'],87            'TatvikMpeg2DemuxBitStreamReader.o'88        )89        self.assertEqual(90            as_json['architectures'][1]['objects'][1]['name'],91            'TatvikMpeg2DemuxPESDecoder.o'92        )93        self.assertEqual(94            as_json['architectures'][1]['objects'][2]['name'],95            'TatvikMpeg2TSDemuxer.o'96        )97        self.assertEqual(98            as_json['architectures'][1]['objects'][3]['name'],99            'TatvikTransportStreamParser.o'100        )101class TestExtractArchiveWithOjects(Test):102    settings = TestSettings(103        tool='retdec-macho-extractor',104        input='archive',105        args='--objects'106    )107    def test_check_extract_json(self):108        self.assertIn('0\tarmv7\tarm', self.retdec_macho_extractor.output)109        self.assertIn('1\tarm64\tarm64', self.retdec_macho_extractor.output)110        self.assertIn(111            '0\tTatvikMpeg2DemuxBitStreamReader.o',112            self.retdec_macho_extractor.output113        )114        self.assertIn(115            '1\tTatvikMpeg2DemuxPESDecoder.o',116            self.retdec_macho_extractor.output117        )118        self.assertIn(119            '2\tTatvikMpeg2TSDemuxer.o',120            self.retdec_macho_extractor.output121        )122        self.assertIn(123            '3\tTatvikTransportStreamParser.o',124            self.retdec_macho_extractor.output125        )126class TestExtractArchivePlain(Test):127    settings = TestSettings(128        tool='retdec-macho-extractor',129        input='archive',130        args='--list'131    )132    def test_check_extract_plain(self):133        self.assertIn('0\tarmv7\tarm', self.retdec_macho_extractor.output)134        self.assertIn('1\tarm64\tarm64', self.retdec_macho_extractor.output)135class TestExtractPrintErrorInJson(Test):136    settings = TestSettings(137        tool='retdec-macho-extractor',138        args='--json'139    )140    def setUp(self):141        pass142    def test_check_detection_list(self):143        self.assertNotEqual(self.retdec_macho_extractor.return_code, 0)144        as_json = json.loads(self.retdec_macho_extractor.output)145        self.assertEqual(as_json['error'], 'no input file')146class TestExtractArchiveDecompilationPick(Test):147    settings = TestSettings(148        input='archive',149        args=[ '--cleanup', '--cleanup --arch arm' ]150    )151    def setUp(self):152        pass153    def test_check_objet_list(self):154        self.assertNotEqual(self.decompiler.return_code, 0)155        self.assertIn(156            '0\tTatvikMpeg2DemuxBitStreamReader.o',157            self.decompiler.output158        )159        self.assertIn(160            '1\tTatvikMpeg2DemuxPESDecoder.o',161            self.decompiler.output162        )163        self.assertIn(164            '2\tTatvikMpeg2TSDemuxer.o',165            self.decompiler.output166        )167        self.assertIn(168            '3\tTatvikTransportStreamParser.o',169            self.decompiler.output170        )171class TestExtractArchiveDecompilationListArchs(Test):172    settings = TestSettings(173        input='archive',174        args='--cleanup --arch x86'175    )176    def setUp(self):177        pass178    def test_check_arch_list(self):179        self.assertNotEqual(self.decompiler.return_code, 0)180        self.assertIn(181            'Invalid --arch option \'x86\'. File contains these architecture families:',182            self.decompiler.output183        )184        self.assertIn('armv7\tarm', self.decompiler.output)185        self.assertIn('arm64\tarm64', self.decompiler.output)186class TestExtractArchiveDecompilation(Test):187    settings = TestSettings(188        input='archive',189        args=[ '--ar-index 3', '--ar-index 3 --arch arm' ]190    )191    def test_check_decompilation(self):192        assert self.out_c.has_func( '_GetPositionCall' )193        assert self.out_c.has_func( '_MovePositionCall' )194class TestExtractDecompileArchiveJson(Test):195    settings = TestSettings(196        tool='retdec-archive-decompiler.py',197        input='archive',198        args='--list --json'199    )200    def test_check_list(self):201        as_json = json.loads(self.retdec_archive_decompiler_py.output)202        self.assertEqual(as_json['architectures'][0]['name'], 'armv7')203        self.assertEqual(as_json['architectures'][0]['index'], 0)204        self.assertEqual(as_json['architectures'][0]['cpuFamily'], 'arm')205        self.assertEqual(206            as_json['architectures'][0]['objects'][0]['name'],207            'TatvikMpeg2DemuxBitStreamReader.o'208        )209        self.assertEqual(210            as_json['architectures'][0]['objects'][1]['name'],211            'TatvikMpeg2DemuxPESDecoder.o'212        )213        self.assertEqual(214            as_json['architectures'][0]['objects'][2]['name'],215            'TatvikMpeg2TSDemuxer.o'216        )217        self.assertEqual(218            as_json['architectures'][0]['objects'][3]['name'],219            'TatvikTransportStreamParser.o'220        )221        self.assertEqual(as_json['architectures'][1]['name'], 'arm64')222        self.assertEqual(as_json['architectures'][1]['index'], 1)223        self.assertEqual(as_json['architectures'][1]['cpuFamily'], 'arm64')224        self.assertEqual(225            as_json['architectures'][1]['objects'][0]['name'],226            'TatvikMpeg2DemuxBitStreamReader.o'227        )228        self.assertEqual(229            as_json['architectures'][1]['objects'][1]['name'],230            'TatvikMpeg2DemuxPESDecoder.o'231        )232        self.assertEqual(233            as_json['architectures'][1]['objects'][2]['name'],234            'TatvikMpeg2TSDemuxer.o'235        )236        self.assertEqual(237            as_json['architectures'][1]['objects'][3]['name'],238            'TatvikTransportStreamParser.o'239        )240class TestExtractDecompileArchivePlainText(Test):241    settings = TestSettings(242        tool='retdec-archive-decompiler.py',243        input='archive',244        args='--list'245    )246    def test_check_list(self):247        self.assertIn(248            '0\tarmv7\tarm',249            self.retdec_archive_decompiler_py.output250        )251        self.assertIn(252            '1\tarm64\tarm64',253            self.retdec_archive_decompiler_py.output254        )255        self.assertIn(256            '0\tTatvikMpeg2DemuxBitStreamReader.o',257            self.retdec_archive_decompiler_py.output258        )259        self.assertIn(260            '1\tTatvikMpeg2DemuxPESDecoder.o',261            self.retdec_archive_decompiler_py.output262        )263        self.assertIn(264            '2\tTatvikMpeg2TSDemuxer.o',265            self.retdec_archive_decompiler_py.output266        )267        self.assertIn(268            '3\tTatvikTransportStreamParser.o',269            self.retdec_archive_decompiler_py.output...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
