How to use _err method in assertpy

Best Python code snippet using assertpy_python

users.js

Source:users.js Github

copy

Full Screen

1const db = require('../helpers/db')2const table = 'users'3module.exports = {4 getUser: (data = []) => {5 return new Promise((resolve, reject) => {6 db.query(`SELECT * FROM ${table} LIMIT ? OFFSET ?`, data, (err, results, _fields) => {7 if (err) {8 reject(err)9 } else {10 resolve(results)11 }12 })13 })14 },15 countUsers: () => {16 return new Promise((resolve, reject) => {17 db.query(`SELECT COUNT(*) as count FROM ${table}`, (err, results, _fields) => {18 if (err) {19 reject(err)20 } else {21 resolve(results[0].count)22 }23 })24 })25 },26 validateUser: (arr, cb) => {27 db.query(`SELECT * FROM ${table} WHERE email LIKE '%${arr[0]}%'`, (_err, result, _fields) => {28 cb(result)29 })30 },31 getUserByCondition: (data = {}) => {32 return new Promise((resolve, reject) => {33 db.query(`SELECT * FROM ${table} WHERE ?`, data, (err, results, _fields) => {34 if (err) {35 reject(err)36 } else {37 resolve(results)38 }39 })40 })41 },42 createUsers: (data = {}) => {43 return new Promise((resolve, reject) => {44 db.query(`INSERT INTO ${table} SET ?`, data, (err, results, _fields) => {45 if (err) {46 reject(err)47 } else {48 resolve(results)49 }50 })51 })52 },53 createSeller: (arr, cb) => {54 db.query(`INSERT INTO ${table} (role_id, email, password) VALUES (${arr[0]}, '${arr[1]}', '${arr[2]}')`, (_err, result, _fields) => {55 cb(result)56 })57 },58 createDetailUsers: (arr, cb) => {59 db.query(`INSERT INTO user_details (email, name, balance, user_id) VALUES ('${arr[0]}', '${arr[1]}', 500000, ${arr[2]})`, (_err, results, _fields) => {60 cb(results)61 })62 },63 createDetailSeller: (arr, cb) => {64 db.query(`INSERT INTO store (name, phone_number, user_id, email) VALUES ('${arr[0]}', ${arr[1]}, ${arr[2]}, '${arr[3]}')`, (_err, results, _fields) => {65 cb(results)66 })67 },68 getProfile: (id, cb) => {69 db.query(`SELECT * FROM ${table} WHERE id=${id}`, (_err, result, _field) => {70 cb(result)71 })72 },73 getDetailProfile: (id, cb) => {74 db.query(`SELECT * FROM user_details WHERE user_id=${id}`, (_err, result, _field) => {75 cb(result)76 })77 },78 postPictModel: (arr, cb) => {79 db.query(`UPDATE user_details SET picture='${arr[1]}' where user_id=${arr[0]} `, (_err, result, _field) => {80 cb(result)81 })82 },83 updateEmail: (arr, cb) => {84 db.query(`UPDATE ${table} SET email='${arr[1]}' where id=${arr[0]}`)85 },86 updatePartialProfile: (arr, id) => {87 return new Promise((resolve, reject) => {88 db.query('UPDATE user_details SET ? WHERE user_id = ?', [arr, id], (_err, result, _fields) => {89 if (_err) {90 reject(_err)91 } else {92 resolve(result)93 }94 })95 })96 },97 addAddress: (arr, cb) => {98 db.query(`INSERT INTO user_address (addr_name, recipient, address, city, telephone, postal_code, status, user_id) VALUES ('${arr[0]}', '${arr[1]}', '${arr[2]}', '${arr[3]}', ${arr[4]}, ${arr[5]}, '${arr[6]}', ${arr[7]})`, (_err, result, _fields) => {99 cb(result)100 })101 },102 editAddress: (arr, id) => {103 return new Promise((resolve, reject) => {104 db.query(`UPDATE user_address SET ? WHERE id = ${id}`, arr, (_err, result, _fields) => {105 if (_err) {106 reject(_err)107 } else {108 resolve(result)109 }110 })111 })112 },113 addCheckout: (arr, cb) => {114 db.query(`INSERT INTO checkout (user_id) VALUES (${arr[0]})`, (_err, result, _field) => {115 cb(result)116 })117 },118 getCheckout: (arr, cb) => {119 db.query(`SELECT * FROM checkout WHERE user_id=${arr[0]}`, (_err, result, _field) => {120 cb(result)121 })122 },123 getCart: (id, cb) => {124 db.query(`SELECT product, quantity, price, total_price FROM cart WHERE user_id=${id}`, (_err, result, _field) => {125 cb(result)126 })127 },128 getNewCart: (id, cb) => {129 db.query(`SELECT * FROM cart WHERE user_id=${id}`, (_err, result, _field) => {130 cb(result)131 })132 },133 getAddress: (id, cb) => {134 db.query(`SELECT * FROM user_address WHERE user_id=${id} ORDER BY status asc`, (_err, result, _field) => {135 cb(result)136 })137 },138 getAddressCount: (id, cb) => {139 db.query(`SELECT COUNT(*) AS count FROM user_address WHERE user_id=${id} ORDER BY status asc`, (_err, result, _field) => {140 cb(result)141 })142 },143 getAddressByUser: (id) => {144 return new Promise((resolve, reject) => {145 db.query(`SELECT * FROM user_address WHERE user_id=${id} ORDER BY id asc`, (_err, result, _field) => {146 if (_err) {147 reject(_err)148 } else {149 resolve(result)150 }151 })152 })153 },154 getPriAddress: (id, cb) => {155 db.query(`SELECT * FROM user_address WHERE user_id=${id} AND status='primary'`, (_err, result, _field) => {156 cb(result)157 })158 },159 getPriAddressByUser: (id) => {160 return new Promise((resolve, reject) => {161 db.query(`SELECT * FROM user_address WHERE user_id=${id} AND status='primary'`, (_err, result, _field) => {162 if (_err) {163 reject(_err)164 } else {165 resolve(result)166 }167 })168 })169 },170 getPriAddressById: (id) => {171 return new Promise((resolve, reject) => {172 db.query(`SELECT * FROM user_address WHERE id=${id} AND status='primary'`, (_err, result, _field) => {173 if (_err) {174 reject(_err)175 } else {176 resolve(result)177 }178 })179 })180 },181 deleteAddress: (id) => {182 return new Promise((resolve, reject) => {183 db.query(`DELETE FROM user_address WHERE id=${id}`, (_err, result, _field) => {184 if (_err) {185 reject(_err)186 } else {187 resolve(result)188 }189 })190 })191 },192 deleteCart: (id, cb) => {193 db.query(`DELETE FROM cart WHERE user_id=${id}`, (_err, result, _field) => {194 cb(result)195 })196 },197 updateOrderId: (arr, cb) => {198 db.query(`UPDATE order_details SET order_id=${arr[0]}, isBuy=1 WHERE user_id=${arr[1]} AND isBuy=0`, (_err, result, _field) => {199 cb(result)200 })201 },202 createTransaction: (arr, cb) => {203 db.query(`INSERT INTO transaction (item, amount, delivery, summary, order_no, no_tracking, user_id) VALUES ('${arr[0]}', ${arr[1]}, 30000, ${arr[2]}, ${arr[3]}, '${arr[4]}', ${arr[5]})`, (_err, result, _field) => {204 cb(result)205 })206 },207 updateTransaction: (arr, cb) => {208 db.query(`UPDATE transaction SET item='${arr[0]}', amount=${arr[1]}, delivery=30000, summary=${arr[2]}, order_no=${arr[3]}, no_tracking='${arr[4]}', isBuy=1 WHERE user_id=${arr[5]} AND isBuy = 0`, (_err, result, _field) => {209 cb(result)210 })211 },212 createTransactionId: (arr, cb) => {213 db.query(`INSERT INTO transaction (user_id) VALUES (${arr[0]})`, (_err, result, _field) => {214 cb(result)215 })216 },217 deleteTransaction: (id, cb) => {218 db.query(`DELETE FROM transaction WHERE user_id=${id} AND isBuy=0`, (_err, result, _field) => {219 cb(result)220 })221 },222 updateBalance: (arr, cb) => {223 db.query(`UPDATE user_details SET balance=${arr[1]} WHERE user_id=${arr[0]}`, (_err, result, _field) => {224 cb(result)225 })226 },227 getHistoryTransaction: (id, cb) => {228 db.query(`SELECT * FROM transaction WHERE user_id=${id} ORDER BY id desc`, (_err, result, _field) => {229 cb(result)230 })231 },232 getHistoryDetail: (id, cb) => {233 db.query(`SELECT * FROM transaction WHERE id=${id}`, (_err, result, _field) => {234 cb(result)235 })236 },237 getHistoryCount: (id, cb) => {238 db.query(`SELECT COUNT(*) AS count FROM transaction WHERE user_id=${id}`, (_err, result, _field) => {239 cb(result)240 })241 },242 createOrderDetail: (arr, cb) => {243 db.query(`INSERT INTO order_details (order_id, user_id, product_id, quantity, price, total_price) VALUES ('${arr[0]}', ${arr[1]}, ${arr[2]}, ${arr[3]}, ${arr[4]}, ${arr[5]}, ${arr[6]})`, (_err, result, _fields) => {244 cb(result)245 })246 },247 createNewOrderDetail: (arr = {}) => {248 return new Promise((resolve, reject) => {249 db.query('INSERT INTO order_details SET ?', arr, (_err, result, _fields) => {250 if (_err) {251 reject(_err)252 } else {253 resolve(result)254 }255 })256 })257 }...

Full Screen

Full Screen

update_aliases.js

Source:update_aliases.js Github

copy

Full Screen

1"use strict";2Object.defineProperty(exports, "__esModule", {3 value: true4});5exports.updateAliases = void 0;6var Either = _interopRequireWildcard(require("fp-ts/lib/Either"));7var _elasticsearch = require("@elastic/elasticsearch");8var _catch_retryable_es_client_errors = require("./catch_retryable_es_client_errors");9function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }10function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }11/*12 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one13 * or more contributor license agreements. Licensed under the Elastic License14 * 2.0 and the Server Side Public License, v 1; you may not use this file except15 * in compliance with, at your election, the Elastic License 2.0 or the Server16 * Side Public License, v 1.17 */18/**19 * Calls the Update index alias API `_alias` with the provided alias actions.20 */21const updateAliases = ({22 client,23 aliasActions24}) => () => {25 return client.indices.updateAliases({26 body: {27 actions: aliasActions28 }29 }, {30 maxRetries: 031 }).then(() => {32 // Ignore `acknowledged: false`. When the coordinating node accepts33 // the new cluster state update but not all nodes have applied the34 // update within the timeout `acknowledged` will be false. However,35 // retrying this update will always immediately result in `acknowledged:36 // true` even if there are still nodes which are falling behind with37 // cluster state updates.38 // The only impact for using `updateAliases` to mark the version index39 // as ready is that it could take longer for other Kibana instances to40 // see that the version index is ready so they are more likely to41 // perform unnecessary duplicate work.42 return Either.right('update_aliases_succeeded');43 }).catch(err => {44 if (err instanceof _elasticsearch.errors.ResponseError) {45 var _err$body, _err$body$error, _err$body2, _err$body2$error, _err$body3, _err$body3$error, _err$body3$error$reas, _err$body4, _err$body4$error, _err$body5, _err$body5$error, _err$body6, _err$body6$error, _err$body6$error$reas;46 if ((err === null || err === void 0 ? void 0 : (_err$body = err.body) === null || _err$body === void 0 ? void 0 : (_err$body$error = _err$body.error) === null || _err$body$error === void 0 ? void 0 : _err$body$error.type) === 'index_not_found_exception') {47 return Either.left({48 type: 'index_not_found_exception',49 index: err.body.error.index50 });51 } else if ((err === null || err === void 0 ? void 0 : (_err$body2 = err.body) === null || _err$body2 === void 0 ? void 0 : (_err$body2$error = _err$body2.error) === null || _err$body2$error === void 0 ? void 0 : _err$body2$error.type) === 'illegal_argument_exception' && err !== null && err !== void 0 && (_err$body3 = err.body) !== null && _err$body3 !== void 0 && (_err$body3$error = _err$body3.error) !== null && _err$body3$error !== void 0 && (_err$body3$error$reas = _err$body3$error.reason) !== null && _err$body3$error$reas !== void 0 && _err$body3$error$reas.match(/The provided expression \[.+\] matches an alias, specify the corresponding concrete indices instead./)) {52 return Either.left({53 type: 'remove_index_not_a_concrete_index'54 });55 } else if ((err === null || err === void 0 ? void 0 : (_err$body4 = err.body) === null || _err$body4 === void 0 ? void 0 : (_err$body4$error = _err$body4.error) === null || _err$body4$error === void 0 ? void 0 : _err$body4$error.type) === 'aliases_not_found_exception' || (err === null || err === void 0 ? void 0 : (_err$body5 = err.body) === null || _err$body5 === void 0 ? void 0 : (_err$body5$error = _err$body5.error) === null || _err$body5$error === void 0 ? void 0 : _err$body5$error.type) === 'resource_not_found_exception' && err !== null && err !== void 0 && (_err$body6 = err.body) !== null && _err$body6 !== void 0 && (_err$body6$error = _err$body6.error) !== null && _err$body6$error !== void 0 && (_err$body6$error$reas = _err$body6$error.reason) !== null && _err$body6$error$reas !== void 0 && _err$body6$error$reas.match(/required alias \[.+\] does not exist/)) {56 return Either.left({57 type: 'alias_not_found_exception'58 });59 }60 }61 throw err;62 }).catch(_catch_retryable_es_client_errors.catchRetryableEsClientErrors);63};...

Full Screen

Full Screen

generateTrigger.js

Source:generateTrigger.js Github

copy

Full Screen

1const fs = require('fs');2const path = require('path');3const EMA = require('../indicators/ema');4const generateZigZag = require('./zigZag/generateZigZag');5const getCycleMagnitude = require('./zigZag/zzGenerators/cycleMagnitude');6const getCycleDuration = require('./zigZag/zzGenerators/cycleDuration');7function generateTrigger(seedData, { writeToFiles = true }) {8 const { rsi, data } = seedData;9 const rsiAvgSmall = new EMA({10 values: rsi.map(({ value }) => value * 1.7),11 period: 8,12 });13 const rsiAvgBig = new EMA({14 values: rsi.map(({ value }) => value * 1.7),15 period: 34,16 });17 const rsiAvg = rsiAvgSmall.map((val, i) => val - rsiAvgBig[i]).filter(Boolean);18 const bulletValues = rsiAvg.map((val, i) => {19 if (rsiAvg[i + 1]) {20 return (val - rsiAvg[i + 1]) * 10;21 }22 return '';23 });24 const bullet = new EMA({25 values: bulletValues,26 period: 5,27 });28 const zigZag = generateZigZag({29 times: data.map(({ time }) => time),30 data: bullet,31 reversalAmount: 10,32 });33 const { states, metrics, plots } = zigZag;34 const bulletFastEma = new EMA({35 values: bullet,36 period: 8,37 });38 const bulletSlowEma = new EMA({39 values: plots.map(val => val * 3),40 period: 34,41 });42 const zzDurations = getCycleDuration(metrics);43 const zzMagnitudes = getCycleMagnitude(metrics);44 if (writeToFiles) {45 fs.writeFile(46 path.resolve('./server/models/techAnalysis/trigger/trigger-bullet.txt'),47 bullet.map(val => val + '\n').join(''), // eslint-disable-line48 _err => {49 if (_err) throw new Error('_err: ', _err);50 },51 );52 fs.writeFile(53 path.resolve('./server/models/techAnalysis/trigger/trigger-bulletFastEma.txt'),54 bulletFastEma.map(val => val + '\n').join(''), // eslint-disable-line55 _err => {56 if (_err) throw new Error('_err: ', _err);57 },58 );59 fs.writeFile(60 path.resolve('./server/models/techAnalysis/trigger/trigger-bulletSlowEma.txt'),61 bulletSlowEma.map(val => val + '\n').join(''), // eslint-disable-line62 _err => {63 if (_err) throw new Error('_err: ', _err);64 },65 );66 fs.writeFile(67 path.resolve('./server/models/techAnalysis/trigger/trigger-zigZag-mode.txt'),68 states.map(val => (val.mode === 'uptrend' ? `${1}\n` : `${-1}\n`)).join(''), // eslint-disable-line69 _err => {70 if (_err) throw new Error('_err: ', _err);71 },72 );73 fs.writeFile(74 path.resolve('./server/models/techAnalysis/trigger/trigger-zigZag-plots.txt'),75 plots.map(val => val + '\n').join(''), // eslint-disable-line76 _err => {77 if (_err) throw new Error('_err: ', _err);78 },79 );80 fs.writeFile(81 path.resolve('./server/models/techAnalysis/trigger/trigger-zigZag-metrics.txt'),82 metrics.map(val => JSON.stringify(val, null, 2) + '\n').join(''), // eslint-disable-line83 _err => {84 if (_err) throw new Error('_err: ', _err);85 },86 );87 fs.writeFile(88 path.resolve('./server/models/techAnalysis/trigger/trigger-zigZag-magnitude.txt'),89 metrics.map(val => val.magnitude + '\n').join(''), // eslint-disable-line90 _err => {91 if (_err) throw new Error('_err: ', _err);92 },93 );94 fs.writeFile(95 path.resolve('./server/models/techAnalysis/trigger/trigger-zigZag-duration.txt'),96 metrics97 .map(val =>98 val.slope > 0 ? `${val.endState.duration}\n` : `${val.endState.duration * -1}\n`,99 )100 .join(''), // eslint-disable-line101 _err => {102 if (_err) throw new Error('_err: ', _err);103 },104 );105 fs.writeFile(106 path.resolve('./server/models/techAnalysis/trigger/trigger-zigZag-cycleDuration.txt'),107 zzDurations.map(val => `${val}\n`).join(''), // eslint-disable-line108 _err => {109 if (_err) throw new Error('_err: ', _err);110 },111 );112 fs.writeFile(113 path.resolve('./server/models/techAnalysis/trigger/trigger-zigZag-cycleMagnitude.txt'),114 zzMagnitudes.map(val => `${val}\n`).join(''), // eslint-disable-line115 _err => {116 if (_err) throw new Error('_err: ', _err);117 },118 );119 }120 return {121 average: rsiAvg,122 averageSmall: rsiAvgSmall,123 averageBig: rsiAvgBig,124 zigZag,125 zzDurations,126 zzMagnitudes,127 };128}...

Full Screen

Full Screen

database_query.js

Source:database_query.js Github

copy

Full Screen

1const db = require('./db')2module.exports = {3 createData: (table, data) => {4 return new Promise((resolve, reject) => {5 db.query('INSERT INTO ?? SET ?', [table, data], (_err, result, _field) => {6 console.log(_err)7 if (!_err) {8 resolve(result)9 }10 reject(_err)11 })12 })13 },14 getDataById: (table, id) => {15 return new Promise((resolve, reject) => {16 db.query('SELECT * FROM ?? WHERE ?', [table, id], (_err, result, _field) => {17 if (!_err) {18 resolve(result)19 }20 reject(_err)21 })22 })23 },24 getDataByIdTwo: (table, id1, id2) => {25 return new Promise((resolve, reject) => {26 db.query('SELECT * FROM ?? WHERE ? AND ?', [table, id1, id2], (_err, result, _field) => {27 if (!_err) {28 resolve(result)29 }30 reject(_err)31 })32 })33 },34 deleteDataById: (table, id) => {35 return new Promise((resolve, reject) => {36 db.query('DELETE FROM ?? WHERE id=?', [table, id], (_err, result, _field) => {37 if (_err) {38 reject(_err)39 } else {40 resolve(result)41 }42 })43 })44 },45 updateData: (table, id, data) => {46 return new Promise((resolve, reject) => {47 db.query('UPDATE ?? SET ? WHERE id= ?', [table, data, id], (_err, result, _field) => {48 console.log(_err)49 if (_err) {50 reject(_err)51 } else {52 resolve(result)53 }54 })55 })56 },57 listData: (data, sortTo) => {58 return new Promise((resolve, reject) => {59 db.query(`SELECT * FROM ?? WHERE name LIKE ? ORDER BY name ${sortTo} LIMIT ? OFFSET ?`,60 data, (_err, result, _field) => {61 if (_err) {62 reject(_err)63 } else {64 resolve(result)65 }66 })67 })68 },69 countData: (data) => {70 return new Promise((resolve, reject) => {71 db.query('SELECT COUNT("*") as count FROM ?? WHERE name LIKE ?', data, (_err, result, _field) => {72 if (_err) {73 reject(_err)74 } else {75 resolve(result)76 }77 })78 })79 },80 updateDataPart: (table, id, data) => {81 return new Promise((resolve, reject) => {82 db.query('UPDATE ?? SET ? WHERE ?', [table, data, id], (_err, result, _field) => {83 console.log(_err)84 if (_err) {85 reject(_err)86 } else {87 resolve(result)88 }89 })90 })91 },92 listDataDymc: (data, sortBy, sortTo) => {93 return new Promise((resolve, reject) => {94 db.query(`SELECT * FROM ?? WHERE name LIKE ? ORDER BY ${sortBy} ${sortTo} LIMIT ? OFFSET ?`,95 data, (_err, result, _field) => {96 if (_err) {97 reject(_err)98 } else {99 resolve(result)100 }101 })102 })103 },104 updateTwoCondst: (table, id1, id2, data) => {105 return new Promise((resolve, reject) => {106 db.query('UPDATE ?? SET ? WHERE ? AND ?', [table, data, id1, id2], (_err, result, _field) => {107 console.log(_err)108 if (_err) {109 reject(_err)110 } else {111 resolve(result)112 }113 })114 })115 },116 deleteData: (table, id) => {117 return new Promise((resolve, reject) => {118 db.query('DELETE FROM ?? WHERE ?', [table, id], (_err, result, _field) => {119 if (_err) {120 reject(_err)121 } else {122 resolve(result)123 }124 })125 })126 },127 getAllData: (table) => {128 return new Promise((resolve, reject) => {129 db.query('SELECT id, name, picture FROM ??', [table], (_err, result, _field) => {130 if (_err) {131 reject(_err)132 } else {133 resolve(result)134 }135 })136 })137 },138 listAdress: (data) => {139 return new Promise((resolve, reject) => {140 db.query('SELECT * FROM user_adress WHERE user_id = ? ORDER BY primary_adress DESC LIMIT ? OFFSET ?',141 data, (_err, result, _field) => {142 console.log(_err)143 if (_err) {144 reject(_err)145 } else {146 resolve(result)147 }148 })149 })150 }...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run assertpy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful