(self, target, timeout=120)
return ('status' in self.order and self.order['status'] in target)
Wait until the order achieves a target state (or states)

        Args:
            target : String or list of strings with the state(s) to wait
                     for. When given as a list, this function waits until any
                     of the states is achieved.
            timeout : Timeout in seconds.

        Returns:
            (bool) Whether the state was successfully reached.
Wait until the order achieves a target state (or states)
Wait until the order achieves a target state ( or states )
def wait_state(self, target, timeout=120):
        """Wait until the order achieves a target state (or states)

        Args:
            target : String or list of strings with the state(s) to wait
                     for. When given as a list, this function waits until any
                     of the states is achieved.
            timeout : Timeout in seconds.

        Returns:
            (bool) Whether the state was successfully reached.

        """
        assert (isinstance(target, str) or isinstance(target, list))

        state_seen = {
            'pending': False,
            'paid': False,
            'transmitting': False,
            'sent': False,
            'received': False,
            'cancelled': False,
            'expired': False
        }
        msg = {
            'pending': "- Waiting for payment confirmation...",
            'paid': "- Payment confirmed. Ready to launch transmission...",
            'transmitting': "- Order in transmission...",
            'sent': "- Order successfully transmitted",
            'received': "- Reception confirmed by the ground station",
            'cancelled': "- Transmission cancelled",
            'expired': "- Order expired"
        }
        requires = {
            'pending': [],
            'paid': ['pending'],
            'transmitting': ['pending', 'paid'],
            'sent': ['pending', 'paid', 'transmitting'],
            'received': ['pending', 'paid', 'transmitting', 'sent'],
            'cancelled': ['pending'],
            'expired': ['pending']
        }

        if (not isinstance(target, list)):
            target = [target]
        assert ([state in state_seen.keys() for state in target])

        s_time = time.time()
        while (True):
            self._fetch()

            if (not state_seen[self.order['status']]):
                state_seen[self.order['status']] = True

                # If the status is not polled fast enough, some intermediate
                # states may not be seen. Mark the implied states as observed
                # and print their messages.
                for prereq_state in requires[self.order['status']]:
                    if (not state_seen[prereq_state]):
                        state_seen[prereq_state] = True
                        print(msg[prereq_state])

                # Print the current state
                print(msg[self.order['status']])

            if (any([state_seen[x] for x in target])):
                break

            c_time = time.time()
            if ((c_time - s_time) > timeout):
                print("Timeout")
                break

            time.sleep(0.5)

        return ('status' in self.order and self.order['status'] in target)
def wait_state ( self , target , timeout = 120 ) : assert ( isinstance ( target , str ) or isinstance ( target , list ) ) state_seen = { 'pending' : False , 'paid' : False , 'transmitting' : False , 'sent' : False , 'received' : False , 'cancelled' : False , 'expired' : False } msg = { 'pending' : "- Waiting for payment confirmation..." , 'paid' : "- Payment confirmed. Ready to launch transmission..." , 'transmitting' : "- Order in transmission..." , 'sent' : "- Order successfully transmitted" , 'received' : "- Reception confirmed by the ground station" , 'cancelled' : "- Transmission cancelled" , 'expired' : "- Order expired" } requires = { 'pending' : [ ] , 'paid' : [ 'pending' ] , 'transmitting' : [ 'pending' , 'paid' ] , 'sent' : [ 'pending' , 'paid' , 'transmitting' ] , 'received' : [ 'pending' , 'paid' , 'transmitting' , 'sent' ] , 'cancelled' : [ 'pending' ] , 'expired' : [ 'pending' ] } if ( not isinstance ( target , list ) ) : target = [ target ] assert ( [ state in state_seen . keys ( ) for state in target ] ) s_time = time . time ( ) while ( True ) : self . _fetch ( ) if ( not state_seen [ self . order [ 'status' ] ] ) : state_seen [ self . order [ 'status' ] ] = True # If the status is not polled fast enough, some intermediate # states may not be seen. Mark the implied states as observed # and print their messages. for prereq_state in requires [ self . order [ 'status' ] ] : if ( not state_seen [ prereq_state ] ) : state_seen [ prereq_state ] = True print ( msg [ prereq_state ] ) # Print the current state print ( msg [ self . order [ 'status' ] ] ) if ( any ( [ state_seen [ x ] for x in target ] ) ) : break c_time = time . time ( ) if ( ( c_time - s_time ) > timeout ) : print ( "Timeout" ) break time . sleep ( 0.5 ) return ( 'status' in self . order and self . order [ 'status' ] in target )