class All_api_methods_testing(unittest.TestCase): u = api.Utopia("http://127.0.0.1:" + API_PORT + "/api/1.0", TOKEN) pattern = re.compile("^([A-Z0-9]){32}") getInvoicesParams = '{ "cardId": "", "invoiceId": "", "pk": "", "transactionId": "", "status": "", ' \ '"startDateTime": "", "endDateTime": "", "referenceNumber": "" }' def setUp(self): self.status = False def test_cancelInvoice(self) -> 'reference_number': """Method cancelInvoice allows to cancel the already created invoice. The method is called with mandatory 'InvoiceId' parameter. Parameter InvoiceId contains the ID value for the invoice that needs to be declined. To get the ID of the required invoice it is mandatory to call the getInvoices method for receiving the list of invoices with their detailed information. In response the declineInvoice method returns in the Response block the results of completing this request.""" invoice = None # Action _, awaiting_requests = self.u.getFinanceHistory( "AWAITING_REQUESTS", "", "", "", "", "", "") if len(awaiting_requests) < 5: _, invoice_ref_num = self.u.sendInvoice("API request", CONTACT_CARD, 10) time.sleep(3) # wait for network confirmation _, invoice = self.u.getInvoiceByReferenceNumber(invoice_ref_num) else: invoice = awaiting_requests[0] status, result = self.u.cancelInvoice(invoice["invoiceid"]) time.sleep(3) # wait for network confirmation # Assertion AssertResultIsRefNum(self, status, result)
def main(): """Подготовительный скрипт для запуска на контакте теста всех методов. Сначала подготавливаем данные - получаем список файлов размером более 2Мб. Потом получаем список своих uns записей, получаем uns записей которыен уже в статес отправки. Их преобразуем в список ников. Далее идёт процесс: * сначала отправки двух писем с аттачами, * потом отправка 2ух uns если их нет в спискее исходящих * и отправка двух инвойсов на карту контакту""" # Settings token = "5E1A9443A7DA0B4C3D300D5F59AF793C" apiPort = "20008" contactPk = "79622FD2FD85B96BBD85A505EE3368680A3A40E528B9B5C5F214300FE6440E4D" contactCard = "D579006B546BDD56" ## Action # Prepare data for script u = api.Utopia("http://127.0.0.1:" + apiPort + "/api/1.0", token) _, local_files = u.getFilesFromManager() gt_2Mb_files = [ file for file in local_files if file['totalSize'] > 2000000 ] _, my_uns_records = u.unsRegisteredNames() _, outgoing_uns_transfers = u.outgoingUnsTransfer() outgoing_uns_names = [uns['nick'] for uns in outgoing_uns_transfers] # Send 2 emails with attachments print( u.sendEmailMessage( [contactPk], "Python API 1", "API method sendEmailMessage testing \n with attach", gt_2Mb_files[0]['id'])) print( u.sendEmailMessage( [contactPk], "Python API 2", "API method sendEmailMessage testing \n with attach", gt_2Mb_files[-1]['id'])) # Transfer 2 uns records i = 0 while i < 2: uns = [ uns['nick'] for uns in my_uns_records if str(uns['nick']).upper() not in outgoing_uns_names ] print(u.requestUnsTransfer(uns[i], contactPk)) i += 1 # Send 2 Invoices print(u.sendInvoice('Invoice #1', contactCard, 1.1)) print(u.sendInvoice('Invoice #2', contactCard, 1.2)) del u
def run(): try: ws.send("ping") u = api.Utopia( "http://127.0.0.1:" + settings.API_PORT + "/api/1.0", settings.TOKEN) print(u.getSystemInfo()) del u except: print("*** WebSocket is not available")
import time import api import settings u = api.Utopia("http://127.0.0.1:" + settings.API_PORT + "/api/1.0", settings.TOKEN) channelid = '49B12FECF93F5A1815202B76E35E6A76' # Channel for sending spam messages msgs_count = 5000 timeout = 5 # Time in minutes sending_by = "count" # 'time' or 'count' long_text = "тестовый текст тестовый текст тестовый текст тестовый текст тестовый текст тестовый текст тестовый текст тестовый текст тестовый текст тестовый текст тестовый текст тестовый текст тестовый текст тестовый текст тестовый текст тестовый тестовый текст тестовый текст" current_time = time.strftime("%H:%M:%S", time.gmtime()).split(":") end_time = "{}:{:>02}:{}".format(current_time[0], int(current_time[1]) + timeout, current_time[2]) if (sending_by == "time"): while (time.strftime("%H:%M:%S", time.gmtime()) != end_time): print( u.sendChannelMessage( channelid, "Spammer message: current GMT-0 time is {}; end time is {}". format(time.strftime("%d.%m.%Y %H:%M:%S", time.gmtime()), end_time))) time.sleep(0.5) else: for i in range(msgs_count): start_time = time.strftime("%H:%M:%S", time.gmtime()).split(":") current_time = "{} {}:{:>02}:{}".format( time.strftime("%d.%m.%Y", time.gmtime()),