pyhttp-app 2.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyhttp/__init__.py +9 -0
- pyhttp/__main__.py +222 -0
- pyhttp/app.py +1333 -0
- pyhttp/assertions.py +289 -0
- pyhttp/cli.py +364 -0
- pyhttp/console.py +82 -0
- pyhttp/curl.py +151 -0
- pyhttp/db.py +1483 -0
- pyhttp/jsengine.py +224 -0
- pyhttp/jsonc.py +54 -0
- pyhttp/mcp.py +316 -0
- pyhttp/mock.py +204 -0
- pyhttp/monitors.py +116 -0
- pyhttp/oauth2.py +153 -0
- pyhttp/openapi.py +365 -0
- pyhttp/pm.js +496 -0
- pyhttp/postman.py +412 -0
- pyhttp/runner.py +1089 -0
- pyhttp/scripts.py +352 -0
- pyhttp/static/app.js +2739 -0
- pyhttp/static/codegen.js +134 -0
- pyhttp/static/editor.js +421 -0
- pyhttp/static/features.css +630 -0
- pyhttp/static/features.js +2396 -0
- pyhttp/static/index.html +372 -0
- pyhttp/static/logo.svg +13 -0
- pyhttp/static/style.css +585 -0
- pyhttp/static/vendor/codemirror.js +28 -0
- pyhttp/static/vendor/fonts/Inter-OFL.txt +93 -0
- pyhttp/static/vendor/fonts/inter-latin-ext-wght-normal.woff2 +0 -0
- pyhttp/static/vendor/fonts/inter-latin-wght-normal.woff2 +0 -0
- pyhttp/static/viewer.js +434 -0
- pyhttp/templating.py +155 -0
- pyhttp/updater.py +387 -0
- pyhttp_app-2.0.1.dist-info/METADATA +654 -0
- pyhttp_app-2.0.1.dist-info/RECORD +40 -0
- pyhttp_app-2.0.1.dist-info/WHEEL +5 -0
- pyhttp_app-2.0.1.dist-info/entry_points.txt +2 -0
- pyhttp_app-2.0.1.dist-info/licenses/LICENSE.md +121 -0
- pyhttp_app-2.0.1.dist-info/top_level.txt +1 -0
pyhttp/pm.js
ADDED
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
// Postman-compatible `pm` runtime for pyhttp scripts. Runs inside an embedded
|
|
2
|
+
// JavaScript engine (QuickJS or V8) before the user's script. State comes in
|
|
3
|
+
// as __STATE (JSON from Python) and goes out through __result().
|
|
4
|
+
//
|
|
5
|
+
// Covered: pm.test / pm.expect (the chai subset Postman scripts use),
|
|
6
|
+
// pm.response (code, status, headers, json(), text(), to.have.status(...) ...),
|
|
7
|
+
// pm.request (method, url, headers, body; editable in pre-request scripts),
|
|
8
|
+
// pm.variables / pm.environment / pm.globals / pm.collectionVariables /
|
|
9
|
+
// pm.iterationData, pm.info, pm.cookies, console.*, setTimeout, btoa/atob,
|
|
10
|
+
// and the legacy `tests`, `postman.*`, `responseBody`, `responseCode` globals.
|
|
11
|
+
// Not available: pm.sendRequest, require(), lodash, CryptoJS (they need Node).
|
|
12
|
+
// (No 'use strict' here on purpose: the declarations must become globals that the
|
|
13
|
+
// user's script, evaluated separately, can see.)
|
|
14
|
+
|
|
15
|
+
var __S = __STATE;
|
|
16
|
+
var __R = { tests: [], logs: [], error: null, vars: { local: {}, env: {}, globals: {}, collection: {} },
|
|
17
|
+
unset: { env: [], globals: [], collection: [] }, request: null, nextRequest: undefined, timers: 0 };
|
|
18
|
+
|
|
19
|
+
// ----------------------------------------------------------------- helpers
|
|
20
|
+
function __type(v) {
|
|
21
|
+
if (v === null) return 'null';
|
|
22
|
+
if (Array.isArray(v)) return 'array';
|
|
23
|
+
if (v instanceof RegExp) return 'regexp';
|
|
24
|
+
if (v instanceof Date) return 'date';
|
|
25
|
+
return typeof v;
|
|
26
|
+
}
|
|
27
|
+
function __inspect(v, depth) {
|
|
28
|
+
depth = depth || 0;
|
|
29
|
+
var t = __type(v);
|
|
30
|
+
if (t === 'string') return depth ? JSON.stringify(v) : v;
|
|
31
|
+
if (t === 'undefined') return 'undefined';
|
|
32
|
+
if (t === 'function') return '[Function' + (v.name ? ': ' + v.name : '') + ']';
|
|
33
|
+
if (t === 'number' || t === 'boolean' || t === 'null') return String(v);
|
|
34
|
+
if (t === 'regexp' || t === 'date') return String(v);
|
|
35
|
+
if (v instanceof Error) return (v.stack || String(v));
|
|
36
|
+
try { return JSON.stringify(v, null, depth ? 0 : 2); } catch (e) { return String(v); }
|
|
37
|
+
}
|
|
38
|
+
function __fmt(args) {
|
|
39
|
+
var out = [];
|
|
40
|
+
for (var i = 0; i < args.length; i++) out.push(__inspect(args[i], 0));
|
|
41
|
+
return out.join(' ');
|
|
42
|
+
}
|
|
43
|
+
function __deepEqual(a, b) {
|
|
44
|
+
if (a === b) return true;
|
|
45
|
+
if (typeof a !== typeof b || a === null || b === null || typeof a !== 'object') return (a !== a && b !== b);
|
|
46
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
47
|
+
if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
|
|
48
|
+
var ka = Object.keys(a), kb = Object.keys(b);
|
|
49
|
+
if (ka.length !== kb.length) return false;
|
|
50
|
+
for (var i = 0; i < ka.length; i++) {
|
|
51
|
+
if (!Object.prototype.hasOwnProperty.call(b, ka[i]) || !__deepEqual(a[ka[i]], b[ka[i]])) return false;
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
function __getPath(obj, path) {
|
|
56
|
+
if (path === undefined || path === null || path === '') return obj;
|
|
57
|
+
var parts = String(path).replace(/\[(\d+)\]/g, '.$1').split('.').filter(Boolean);
|
|
58
|
+
var cur = obj;
|
|
59
|
+
for (var i = 0; i < parts.length; i++) {
|
|
60
|
+
if (cur === null || cur === undefined) return undefined;
|
|
61
|
+
cur = cur[parts[i]];
|
|
62
|
+
}
|
|
63
|
+
return cur;
|
|
64
|
+
}
|
|
65
|
+
function __hasPath(obj, path) {
|
|
66
|
+
var parts = String(path).replace(/\[(\d+)\]/g, '.$1').split('.').filter(Boolean);
|
|
67
|
+
var cur = obj;
|
|
68
|
+
for (var i = 0; i < parts.length; i++) {
|
|
69
|
+
if (cur === null || cur === undefined || typeof cur !== 'object' || !(parts[i] in cur)) return false;
|
|
70
|
+
cur = cur[parts[i]];
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
function __str(v) { return v === undefined || v === null ? '' : String(v); }
|
|
75
|
+
|
|
76
|
+
// --------------------------------------------------------------- console
|
|
77
|
+
var console = {};
|
|
78
|
+
['log', 'info', 'warn', 'error', 'debug'].forEach(function (k) {
|
|
79
|
+
console[k] = function () { __R.logs.push((k === 'log' || k === 'info' || k === 'debug' ? '' : k + ': ') + __fmt(arguments)); };
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// ------------------------------------------------------ chai-like expect
|
|
83
|
+
function AssertionError(message) { this.name = 'AssertionError'; this.message = message; this.stack = 'AssertionError: ' + message; }
|
|
84
|
+
AssertionError.prototype = Object.create(Error.prototype);
|
|
85
|
+
AssertionError.prototype.constructor = AssertionError;
|
|
86
|
+
|
|
87
|
+
function Assertion(obj, flags) {
|
|
88
|
+
this._obj = obj;
|
|
89
|
+
this._f = flags || { not: false, deep: false, any: false, all: true, nested: false };
|
|
90
|
+
}
|
|
91
|
+
Assertion.prototype._assert = function (cond, msg, negMsg) {
|
|
92
|
+
var ok = this._f.not ? !cond : cond;
|
|
93
|
+
if (!ok) throw new AssertionError(this._f.not ? negMsg : msg);
|
|
94
|
+
return this;
|
|
95
|
+
};
|
|
96
|
+
Assertion.prototype._eq = function (a, b) { return this._f.deep ? __deepEqual(a, b) : a === b; };
|
|
97
|
+
// language chains
|
|
98
|
+
['to', 'be', 'been', 'is', 'that', 'which', 'and', 'has', 'have', 'with', 'at', 'of', 'same', 'but', 'does', 'still', 'also'].forEach(function (w) {
|
|
99
|
+
Object.defineProperty(Assertion.prototype, w, { get: function () { return this; } });
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(Assertion.prototype, 'not', { get: function () { this._f.not = !this._f.not; return this; } });
|
|
102
|
+
Object.defineProperty(Assertion.prototype, 'deep', { get: function () { this._f.deep = true; return this; } });
|
|
103
|
+
Object.defineProperty(Assertion.prototype, 'nested', { get: function () { this._f.nested = true; return this; } });
|
|
104
|
+
Object.defineProperty(Assertion.prototype, 'any', { get: function () { this._f.any = true; this._f.all = false; return this; } });
|
|
105
|
+
Object.defineProperty(Assertion.prototype, 'all', { get: function () { this._f.all = true; this._f.any = false; return this; } });
|
|
106
|
+
Object.defineProperty(Assertion.prototype, 'own', { get: function () { return this; } });
|
|
107
|
+
Object.defineProperty(Assertion.prototype, 'ordered', { get: function () { this._f.ordered = true; return this; } });
|
|
108
|
+
// property-style assertions
|
|
109
|
+
Object.defineProperty(Assertion.prototype, 'ok', { get: function () { return this._assert(!!this._obj, 'expected ' + __inspect(this._obj, 1) + ' to be truthy', 'expected ' + __inspect(this._obj, 1) + ' to be falsy'); } });
|
|
110
|
+
Object.defineProperty(Assertion.prototype, 'true', { get: function () { return this._assert(this._obj === true, 'expected ' + __inspect(this._obj, 1) + ' to be true', 'expected ' + __inspect(this._obj, 1) + ' to not be true'); } });
|
|
111
|
+
Object.defineProperty(Assertion.prototype, 'false', { get: function () { return this._assert(this._obj === false, 'expected ' + __inspect(this._obj, 1) + ' to be false', 'expected ' + __inspect(this._obj, 1) + ' to not be false'); } });
|
|
112
|
+
Object.defineProperty(Assertion.prototype, 'null', { get: function () { return this._assert(this._obj === null, 'expected ' + __inspect(this._obj, 1) + ' to be null', 'expected ' + __inspect(this._obj, 1) + ' to not be null'); } });
|
|
113
|
+
Object.defineProperty(Assertion.prototype, 'undefined', { get: function () { return this._assert(this._obj === undefined, 'expected ' + __inspect(this._obj, 1) + ' to be undefined', 'expected ' + __inspect(this._obj, 1) + ' to not be undefined'); } });
|
|
114
|
+
Object.defineProperty(Assertion.prototype, 'NaN', { get: function () { return this._assert(this._obj !== this._obj, 'expected ' + __inspect(this._obj, 1) + ' to be NaN', 'expected ' + __inspect(this._obj, 1) + ' to not be NaN'); } });
|
|
115
|
+
Object.defineProperty(Assertion.prototype, 'exist', { get: function () { return this._assert(this._obj !== null && this._obj !== undefined, 'expected ' + __inspect(this._obj, 1) + ' to exist', 'expected ' + __inspect(this._obj, 1) + ' to not exist'); } });
|
|
116
|
+
Object.defineProperty(Assertion.prototype, 'empty', { get: function () {
|
|
117
|
+
var o = this._obj, isEmpty;
|
|
118
|
+
if (typeof o === 'string' || Array.isArray(o)) isEmpty = o.length === 0;
|
|
119
|
+
else if (o && typeof o === 'object') isEmpty = Object.keys(o).length === 0;
|
|
120
|
+
else isEmpty = o === null || o === undefined;
|
|
121
|
+
return this._assert(isEmpty, 'expected ' + __inspect(o, 1) + ' to be empty', 'expected ' + __inspect(o, 1) + ' not to be empty');
|
|
122
|
+
} });
|
|
123
|
+
Object.defineProperty(Assertion.prototype, 'arguments', { get: function () { return this; } });
|
|
124
|
+
function __lengthFn(self) {
|
|
125
|
+
var len = function (n) { var l = self._obj == null ? undefined : self._obj.length; return self._assert(l === n, 'expected ' + __inspect(self._obj, 1) + ' to have a length of ' + n + ' but got ' + l, 'expected ' + __inspect(self._obj, 1) + ' to not have a length of ' + n); };
|
|
126
|
+
var l = self._obj == null ? undefined : self._obj.length;
|
|
127
|
+
var la = new Assertion(l, self._f);
|
|
128
|
+
len.above = function (n) { la.above(n); return self; }; len.gt = len.greaterThan = len.above;
|
|
129
|
+
len.below = function (n) { la.below(n); return self; }; len.lt = len.lessThan = len.below;
|
|
130
|
+
len.least = function (n) { la.least(n); return self; }; len.gte = len.least;
|
|
131
|
+
len.most = function (n) { la.most(n); return self; }; len.lte = len.most;
|
|
132
|
+
len.within = function (a, b) { la.within(a, b); return self; };
|
|
133
|
+
return len;
|
|
134
|
+
}
|
|
135
|
+
Object.defineProperty(Assertion.prototype, 'length', { get: function () { return __lengthFn(this); } });
|
|
136
|
+
Object.defineProperty(Assertion.prototype, 'lengthOf', { get: function () { return __lengthFn(this); } });
|
|
137
|
+
// method-style assertions
|
|
138
|
+
Assertion.prototype.equal = Assertion.prototype.equals = Assertion.prototype.eq = function (v) {
|
|
139
|
+
return this._assert(this._eq(this._obj, v), 'expected ' + __inspect(this._obj, 1) + ' to ' + (this._f.deep ? 'deeply ' : '') + 'equal ' + __inspect(v, 1), 'expected ' + __inspect(this._obj, 1) + ' to not equal ' + __inspect(v, 1));
|
|
140
|
+
};
|
|
141
|
+
Assertion.prototype.eql = Assertion.prototype.eqls = function (v) {
|
|
142
|
+
return this._assert(__deepEqual(this._obj, v), 'expected ' + __inspect(this._obj, 1) + ' to deeply equal ' + __inspect(v, 1), 'expected ' + __inspect(this._obj, 1) + ' to not deeply equal ' + __inspect(v, 1));
|
|
143
|
+
};
|
|
144
|
+
Assertion.prototype.above = Assertion.prototype.gt = Assertion.prototype.greaterThan = function (n) { return this._assert(this._obj > n, 'expected ' + __inspect(this._obj, 1) + ' to be above ' + n, 'expected ' + __inspect(this._obj, 1) + ' to be at most ' + n); };
|
|
145
|
+
Assertion.prototype.below = Assertion.prototype.lt = Assertion.prototype.lessThan = function (n) { return this._assert(this._obj < n, 'expected ' + __inspect(this._obj, 1) + ' to be below ' + n, 'expected ' + __inspect(this._obj, 1) + ' to be at least ' + n); };
|
|
146
|
+
Assertion.prototype.least = Assertion.prototype.gte = function (n) { return this._assert(this._obj >= n, 'expected ' + __inspect(this._obj, 1) + ' to be at least ' + n, 'expected ' + __inspect(this._obj, 1) + ' to be below ' + n); };
|
|
147
|
+
Assertion.prototype.most = Assertion.prototype.lte = function (n) { return this._assert(this._obj <= n, 'expected ' + __inspect(this._obj, 1) + ' to be at most ' + n, 'expected ' + __inspect(this._obj, 1) + ' to be above ' + n); };
|
|
148
|
+
Assertion.prototype.within = function (a, b) { return this._assert(this._obj >= a && this._obj <= b, 'expected ' + __inspect(this._obj, 1) + ' to be within ' + a + '..' + b, 'expected ' + __inspect(this._obj, 1) + ' to not be within ' + a + '..' + b); };
|
|
149
|
+
Assertion.prototype.closeTo = Assertion.prototype.approximately = function (n, d) { return this._assert(Math.abs(this._obj - n) <= d, 'expected ' + this._obj + ' to be close to ' + n + ' +/- ' + d, 'expected ' + this._obj + ' not to be close to ' + n + ' +/- ' + d); };
|
|
150
|
+
Assertion.prototype.a = Assertion.prototype.an = function (type) {
|
|
151
|
+
var t = __type(this._obj);
|
|
152
|
+
var want = String(type).toLowerCase();
|
|
153
|
+
var ok = t === want || (want === 'object' && t === 'object');
|
|
154
|
+
return this._assert(ok, 'expected ' + __inspect(this._obj, 1) + ' to be ' + (/^[aeiou]/.test(want) ? 'an ' : 'a ') + want + ' but got ' + t, 'expected ' + __inspect(this._obj, 1) + ' not to be ' + (/^[aeiou]/.test(want) ? 'an ' : 'a ') + want);
|
|
155
|
+
};
|
|
156
|
+
Assertion.prototype.include = Assertion.prototype.includes = Assertion.prototype.contain = Assertion.prototype.contains = function (v) {
|
|
157
|
+
var o = this._obj, ok = false, self = this;
|
|
158
|
+
if (typeof o === 'string') ok = o.indexOf(String(v)) !== -1;
|
|
159
|
+
else if (Array.isArray(o)) ok = o.some(function (x) { return self._eq(x, v); });
|
|
160
|
+
else if (o && typeof o === 'object') {
|
|
161
|
+
if (v && typeof v === 'object') ok = Object.keys(v).every(function (k) { return k in o && self._eq(o[k], v[k]); });
|
|
162
|
+
else ok = Object.keys(o).some(function (k) { return self._eq(o[k], v); });
|
|
163
|
+
}
|
|
164
|
+
return this._assert(ok, 'expected ' + __inspect(o, 1) + ' to include ' + __inspect(v, 1), 'expected ' + __inspect(o, 1) + ' to not include ' + __inspect(v, 1));
|
|
165
|
+
};
|
|
166
|
+
Assertion.prototype.string = function (s) { return this._assert(typeof this._obj === 'string' && this._obj.indexOf(s) !== -1, 'expected ' + __inspect(this._obj, 1) + ' to contain ' + __inspect(s, 1), 'expected ' + __inspect(this._obj, 1) + ' to not contain ' + __inspect(s, 1)); };
|
|
167
|
+
Assertion.prototype.match = Assertion.prototype.matches = function (re) { if (typeof re === 'string') re = new RegExp(re); return this._assert(re.test(String(this._obj)), 'expected ' + __inspect(this._obj, 1) + ' to match ' + re, 'expected ' + __inspect(this._obj, 1) + ' not to match ' + re); };
|
|
168
|
+
Assertion.prototype.property = function (name, value) {
|
|
169
|
+
var has = this._f.nested ? __hasPath(this._obj, name) : (this._obj !== null && this._obj !== undefined && name in Object(this._obj));
|
|
170
|
+
var val = this._f.nested ? __getPath(this._obj, name) : (has ? this._obj[name] : undefined);
|
|
171
|
+
if (arguments.length > 1) {
|
|
172
|
+
this._assert(has && this._eq(val, value), 'expected ' + __inspect(this._obj, 1) + ' to have property ' + JSON.stringify(name) + ' of ' + __inspect(value, 1) + ', but got ' + __inspect(val, 1), 'expected ' + __inspect(this._obj, 1) + ' to not have property ' + JSON.stringify(name) + ' of ' + __inspect(value, 1));
|
|
173
|
+
} else {
|
|
174
|
+
this._assert(has, 'expected ' + __inspect(this._obj, 1) + ' to have property ' + JSON.stringify(name), 'expected ' + __inspect(this._obj, 1) + ' to not have property ' + JSON.stringify(name));
|
|
175
|
+
}
|
|
176
|
+
if (!this._f.not) { var a = new Assertion(val); return a; }
|
|
177
|
+
return this;
|
|
178
|
+
};
|
|
179
|
+
Assertion.prototype.ownProperty = Assertion.prototype.haveOwnProperty = Assertion.prototype.property;
|
|
180
|
+
Assertion.prototype.keys = Assertion.prototype.key = function () {
|
|
181
|
+
var want = Array.isArray(arguments[0]) ? arguments[0] : (arguments.length === 1 && arguments[0] && typeof arguments[0] === 'object') ? Object.keys(arguments[0]) : Array.prototype.slice.call(arguments);
|
|
182
|
+
var have = this._obj && typeof this._obj === 'object' ? Object.keys(this._obj) : [];
|
|
183
|
+
var ok;
|
|
184
|
+
if (this._f.any) ok = want.some(function (k) { return have.indexOf(k) !== -1; });
|
|
185
|
+
else if (this._f.contains) ok = want.every(function (k) { return have.indexOf(k) !== -1; });
|
|
186
|
+
else ok = want.every(function (k) { return have.indexOf(k) !== -1; }) && (this._f.containsKeys || have.length === want.length);
|
|
187
|
+
return this._assert(ok, 'expected ' + __inspect(this._obj, 1) + ' to have keys ' + want.join(', '), 'expected ' + __inspect(this._obj, 1) + ' to not have keys ' + want.join(', '));
|
|
188
|
+
};
|
|
189
|
+
Assertion.prototype.members = function (arr) {
|
|
190
|
+
var o = this._obj || [], self = this;
|
|
191
|
+
var ok = Array.isArray(o) && arr.every(function (x) { return o.some(function (y) { return self._eq(x, y); }); }) && (this._f.includeMembers || o.length === arr.length);
|
|
192
|
+
return this._assert(ok, 'expected ' + __inspect(o, 1) + ' to have the same members as ' + __inspect(arr, 1), 'expected ' + __inspect(o, 1) + ' to not have the same members as ' + __inspect(arr, 1));
|
|
193
|
+
};
|
|
194
|
+
Assertion.prototype.oneOf = function (list) { var self = this; return this._assert(list.some(function (x) { return self._eq(self._obj, x); }), 'expected ' + __inspect(this._obj, 1) + ' to be one of ' + __inspect(list, 1), 'expected ' + __inspect(this._obj, 1) + ' to not be one of ' + __inspect(list, 1)); };
|
|
195
|
+
Assertion.prototype.instanceOf = Assertion.prototype.instanceof = function (ctor) { return this._assert(this._obj instanceof ctor, 'expected ' + __inspect(this._obj, 1) + ' to be an instance of ' + (ctor && ctor.name), 'expected ' + __inspect(this._obj, 1) + ' to not be an instance of ' + (ctor && ctor.name)); };
|
|
196
|
+
Assertion.prototype.satisfy = Assertion.prototype.satisfies = function (fn) { return this._assert(!!fn(this._obj), 'expected ' + __inspect(this._obj, 1) + ' to satisfy ' + (fn.name || 'function'), 'expected ' + __inspect(this._obj, 1) + ' to not satisfy ' + (fn.name || 'function')); };
|
|
197
|
+
Assertion.prototype.throw = Assertion.prototype.throws = function (expected) {
|
|
198
|
+
var threw = false, err = null;
|
|
199
|
+
try { this._obj(); } catch (e) { threw = true; err = e; }
|
|
200
|
+
var ok = threw;
|
|
201
|
+
if (threw && expected !== undefined) {
|
|
202
|
+
if (typeof expected === 'string') ok = String(err && err.message || err).indexOf(expected) !== -1;
|
|
203
|
+
else if (expected instanceof RegExp) ok = expected.test(String(err && err.message || err));
|
|
204
|
+
else if (typeof expected === 'function') ok = err instanceof expected;
|
|
205
|
+
}
|
|
206
|
+
return this._assert(ok, 'expected function to throw' + (expected ? ' ' + __inspect(expected, 1) : ''), 'expected function to not throw');
|
|
207
|
+
};
|
|
208
|
+
Assertion.prototype.respondTo = function (m) { return this._assert(this._obj && typeof this._obj[m] === 'function', 'expected object to respond to ' + m, 'expected object to not respond to ' + m); };
|
|
209
|
+
Assertion.prototype.finite = function () { return this._assert(isFinite(this._obj), 'expected ' + this._obj + ' to be finite', 'expected ' + this._obj + ' to not be finite'); };
|
|
210
|
+
Object.defineProperty(Assertion.prototype, 'include', { get: function () { var self = this; var fn = function (v) { return Assertion.prototype.includes.call(self, v); }; fn.keys = function () { self._f.contains = true; return Assertion.prototype.keys.apply(self, arguments); }; fn.members = function (arr) { self._f.includeMembers = true; return Assertion.prototype.members.call(self, arr); }; return fn; } });
|
|
211
|
+
Object.defineProperty(Assertion.prototype, 'contain', { get: function () { return this.include; } });
|
|
212
|
+
|
|
213
|
+
// --------------------------------------------------------- property lists
|
|
214
|
+
function PropertyList(items, keyName, valueName) {
|
|
215
|
+
// items: [[key, value], ...]
|
|
216
|
+
this._items = items.map(function (p) { return { key: p[0], value: p[1] }; });
|
|
217
|
+
this._k = keyName || 'key'; this._v = valueName || 'value';
|
|
218
|
+
}
|
|
219
|
+
PropertyList.prototype._find = function (key) { var k = String(key).toLowerCase(); for (var i = 0; i < this._items.length; i++) if (String(this._items[i].key).toLowerCase() === k) return i; return -1; };
|
|
220
|
+
PropertyList.prototype.get = function (key) { var i = this._find(key); return i === -1 ? undefined : this._items[i].value; };
|
|
221
|
+
PropertyList.prototype.has = function (key, value) { var i = this._find(key); return i !== -1 && (value === undefined || String(this._items[i].value) === String(value)); };
|
|
222
|
+
PropertyList.prototype.add = function (item) { this._items.push({ key: item.key !== undefined ? item.key : item[this._k], value: item.value !== undefined ? item.value : item[this._v] }); };
|
|
223
|
+
PropertyList.prototype.upsert = function (item) { var k = item.key !== undefined ? item.key : item[this._k]; var v = item.value !== undefined ? item.value : item[this._v]; var i = this._find(k); if (i === -1) this._items.push({ key: k, value: v }); else this._items[i].value = v; };
|
|
224
|
+
PropertyList.prototype.remove = function (key) { if (typeof key === 'function') { this._items = this._items.filter(function (it) { return !key(it); }); return; } var i = this._find(key); if (i !== -1) this._items.splice(i, 1); };
|
|
225
|
+
PropertyList.prototype.clear = function () { this._items = []; };
|
|
226
|
+
PropertyList.prototype.each = function (fn) { this._items.forEach(function (it) { fn({ key: it.key, value: it.value }); }); };
|
|
227
|
+
PropertyList.prototype.map = function (fn) { return this._items.map(function (it) { return fn({ key: it.key, value: it.value }); }); };
|
|
228
|
+
PropertyList.prototype.filter = function (fn) { return this._items.filter(function (it) { return fn({ key: it.key, value: it.value }); }).map(function (it) { return { key: it.key, value: it.value }; }); };
|
|
229
|
+
PropertyList.prototype.all = function () { return this._items.map(function (it) { return { key: it.key, value: it.value }; }); };
|
|
230
|
+
PropertyList.prototype.count = function () { return this._items.length; };
|
|
231
|
+
PropertyList.prototype.idx = function (i) { var it = this._items[i]; return it ? { key: it.key, value: it.value } : undefined; };
|
|
232
|
+
PropertyList.prototype.toObject = function () { var o = {}; this._items.forEach(function (it) { o[it.key] = it.value; }); return o; };
|
|
233
|
+
PropertyList.prototype.toJSON = function () { return this.all(); };
|
|
234
|
+
PropertyList.prototype.toString = function () { return this._items.map(function (it) { return it.key + ': ' + it.value; }).join('\n'); };
|
|
235
|
+
PropertyList.prototype._pairs = function () { return this._items.map(function (it) { return [it.key, it.value]; }); };
|
|
236
|
+
|
|
237
|
+
// ----------------------------------------------------------- variables
|
|
238
|
+
var __V = __S.variables || {};
|
|
239
|
+
var __local = Object.assign({}, __V.local || {}), __env = Object.assign({}, __V.env || {}), __globals = Object.assign({}, __V.globals || {}),
|
|
240
|
+
__coll = Object.assign({}, __V.collection || {}), __data = Object.assign({}, __V.data || {});
|
|
241
|
+
function __scope(store, name) {
|
|
242
|
+
return {
|
|
243
|
+
get: function (k) { return Object.prototype.hasOwnProperty.call(store, k) ? store[k] : undefined; },
|
|
244
|
+
set: function (k, v) { var t = (v === null || v === undefined) ? '' : (typeof v === 'object' ? JSON.stringify(v) : String(v)); store[k] = t; if (name) { __R.vars[name][k] = t; var u = __R.unset[name]; if (u) { var i = u.indexOf(k); if (i !== -1) u.splice(i, 1); } } },
|
|
245
|
+
has: function (k) { return Object.prototype.hasOwnProperty.call(store, k); },
|
|
246
|
+
unset: function (k) { delete store[k]; if (name) { if (__R.vars[name]) delete __R.vars[name][k]; if (__R.unset[name]) __R.unset[name].push(k); } },
|
|
247
|
+
clear: function () { var self = this; Object.keys(store).forEach(function (k) { self.unset(k); }); },
|
|
248
|
+
toObject: function () { return Object.assign({}, store); },
|
|
249
|
+
toJSON: function () { return Object.assign({}, store); },
|
|
250
|
+
replaceIn: function (s) { return __replaceIn(s); },
|
|
251
|
+
name: __S.environmentName || '',
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function __resolve(k) {
|
|
255
|
+
var stores = [__local, __data, __env, __coll, __globals];
|
|
256
|
+
for (var i = 0; i < stores.length; i++) if (Object.prototype.hasOwnProperty.call(stores[i], k)) return stores[i][k];
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
function __replaceIn(s) {
|
|
260
|
+
return String(s).replace(/\{\{\s*([^{}]+?)\s*\}\}/g, function (m, k) { var v = __resolve(k); return v === undefined ? m : String(v); });
|
|
261
|
+
}
|
|
262
|
+
var __variables = __scope(__local, 'local');
|
|
263
|
+
__variables.get = function (k) { return __resolve(k); };
|
|
264
|
+
__variables.has = function (k) { return __resolve(k) !== undefined; };
|
|
265
|
+
__variables.toObject = function () { return Object.assign({}, __globals, __coll, __env, __data, __local); };
|
|
266
|
+
|
|
267
|
+
// ------------------------------------------------------------- request
|
|
268
|
+
var __req = __S.request || {};
|
|
269
|
+
var __headers = new PropertyList(__req.headers || []);
|
|
270
|
+
var __query = new PropertyList(__req.params || []);
|
|
271
|
+
var __reqState = { method: __req.method || 'GET', url: __req.url || '', body: __req.body || '', bodyType: __req.body_type || 'none', auth: __req.auth || null };
|
|
272
|
+
function __urlObj(s) {
|
|
273
|
+
var m = /^([a-z][a-z0-9+.-]*:)?\/\/([^/?#]*)([^?#]*)(\?[^#]*)?(#.*)?$/i.exec(s) || [];
|
|
274
|
+
return { protocol: (m[1] || '').replace(':', ''), host: m[2] || '', path: m[3] || '', query: m[4] || '', hash: m[5] || '' };
|
|
275
|
+
}
|
|
276
|
+
var __url = {
|
|
277
|
+
toString: function () { return __reqState.url; },
|
|
278
|
+
getHost: function () { return __urlObj(__reqState.url).host.split(':')[0]; },
|
|
279
|
+
getPort: function () { return __urlObj(__reqState.url).host.split(':')[1] || ''; },
|
|
280
|
+
getPath: function () { return __urlObj(__reqState.url).path; },
|
|
281
|
+
getQueryString: function () { return __query._pairs().map(function (p) { return encodeURIComponent(p[0]) + '=' + encodeURIComponent(p[1]); }).join('&'); },
|
|
282
|
+
getRaw: function () { return __reqState.url; },
|
|
283
|
+
update: function (s) { __reqState.url = String(s); },
|
|
284
|
+
query: __query,
|
|
285
|
+
get host() { return __urlObj(__reqState.url).host.split(':')[0].split('.'); },
|
|
286
|
+
get path() { return __urlObj(__reqState.url).path.split('/').filter(Boolean); },
|
|
287
|
+
get protocol() { return __urlObj(__reqState.url).protocol; },
|
|
288
|
+
toJSON: function () { return __reqState.url; },
|
|
289
|
+
};
|
|
290
|
+
var __body = {
|
|
291
|
+
get mode() { var t = __reqState.bodyType; return t === 'none' ? undefined : (t === 'form' ? 'urlencoded' : t === 'multipart' ? 'formdata' : t === 'binary' ? 'file' : t === 'graphql' ? 'graphql' : 'raw'); },
|
|
292
|
+
get raw() { return __reqState.body; },
|
|
293
|
+
set raw(v) { __reqState.body = String(v); },
|
|
294
|
+
update: function (v) { if (v && typeof v === 'object' && 'raw' in v) __reqState.body = String(v.raw); else __reqState.body = String(v); },
|
|
295
|
+
toString: function () { return __reqState.body; },
|
|
296
|
+
toJSON: function () { return { mode: this.mode, raw: __reqState.body }; },
|
|
297
|
+
};
|
|
298
|
+
var __request = {
|
|
299
|
+
headers: __headers,
|
|
300
|
+
get method() { return __reqState.method; },
|
|
301
|
+
set method(v) { __reqState.method = String(v).toUpperCase(); },
|
|
302
|
+
get url() { return __url; },
|
|
303
|
+
set url(v) { __reqState.url = String(v && v.toString ? v.toString() : v); },
|
|
304
|
+
body: __body,
|
|
305
|
+
get auth() { return __reqState.auth; },
|
|
306
|
+
name: __S.info ? __S.info.requestName : '',
|
|
307
|
+
id: __S.info ? __S.info.requestId : '',
|
|
308
|
+
addHeader: function (h) { __headers.add(h); },
|
|
309
|
+
removeHeader: function (k) { __headers.remove(k); },
|
|
310
|
+
upsertHeader: function (h) { __headers.upsert(h); },
|
|
311
|
+
addQueryParams: function (p) { (Array.isArray(p) ? p : [p]).forEach(function (x) { __query.add(x); }); },
|
|
312
|
+
removeQueryParams: function (p) { (Array.isArray(p) ? p : [p]).forEach(function (x) { __query.remove(typeof x === 'string' ? x : x.key); }); },
|
|
313
|
+
toJSON: function () { return { method: __reqState.method, url: __reqState.url, header: __headers.all(), body: __body.toJSON() }; },
|
|
314
|
+
to: null,
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
// ------------------------------------------------------------ response
|
|
318
|
+
var __resp = __S.response;
|
|
319
|
+
var __response = null;
|
|
320
|
+
if (__resp) {
|
|
321
|
+
var __respHeaders = new PropertyList(__resp.headers || []);
|
|
322
|
+
var __jsonCache, __jsonParsed = false;
|
|
323
|
+
var __reasons = { 200: 'OK', 201: 'Created', 202: 'Accepted', 204: 'No Content', 301: 'Moved Permanently', 302: 'Found', 304: 'Not Modified', 400: 'Bad Request', 401: 'Unauthorized', 403: 'Forbidden', 404: 'Not Found', 405: 'Method Not Allowed', 409: 'Conflict', 422: 'Unprocessable Entity', 429: 'Too Many Requests', 500: 'Internal Server Error', 502: 'Bad Gateway', 503: 'Service Unavailable' };
|
|
324
|
+
__response = {
|
|
325
|
+
code: __resp.code,
|
|
326
|
+
status: __resp.status || __reasons[__resp.code] || '',
|
|
327
|
+
responseTime: __resp.time_ms,
|
|
328
|
+
responseSize: __resp.size,
|
|
329
|
+
headers: __respHeaders,
|
|
330
|
+
cookies: new PropertyList((__resp.cookies || []).map(function (c) { return [c.name, c.value]; })),
|
|
331
|
+
text: function () { return __resp.body || ''; },
|
|
332
|
+
json: function () {
|
|
333
|
+
if (!__jsonParsed) { __jsonParsed = true; __jsonCache = JSON.parse(__resp.body || ''); }
|
|
334
|
+
return __jsonCache;
|
|
335
|
+
},
|
|
336
|
+
reason: function () { return this.status; },
|
|
337
|
+
dataURI: function () { return 'data:' + (__respHeaders.get('content-type') || 'text/plain') + ';base64,' + btoa(__resp.body || ''); },
|
|
338
|
+
toJSON: function () { return { code: __resp.code, status: this.status, header: __respHeaders.all(), responseTime: __resp.time_ms, body: __resp.body }; },
|
|
339
|
+
};
|
|
340
|
+
// pm.response.to.have.status(...) / to.be.ok etc.
|
|
341
|
+
function __respTo(negate) {
|
|
342
|
+
var self = __response;
|
|
343
|
+
var check = function (cond, msg, neg) { var ok = negate ? !cond : cond; if (!ok) throw new AssertionError(negate ? neg : msg); };
|
|
344
|
+
var have = {
|
|
345
|
+
status: function (s) {
|
|
346
|
+
if (typeof s === 'number') check(self.code === s, 'expected response to have status code ' + s + ' but got ' + self.code, 'expected response to not have status code ' + s);
|
|
347
|
+
else check(String(self.status).toLowerCase() === String(s).toLowerCase(), 'expected response to have status reason ' + JSON.stringify(s) + ' but got ' + JSON.stringify(self.status), 'expected response to not have status reason ' + JSON.stringify(s));
|
|
348
|
+
},
|
|
349
|
+
header: function (k, v) {
|
|
350
|
+
if (v === undefined) check(__respHeaders.has(k), 'expected response to have header with key ' + JSON.stringify(k), 'expected response to not have header with key ' + JSON.stringify(k));
|
|
351
|
+
else check(__respHeaders.has(k) && String(__respHeaders.get(k)) === String(v), 'expected response header ' + JSON.stringify(k) + ' to be ' + JSON.stringify(v) + ' but got ' + JSON.stringify(__respHeaders.get(k)), 'expected response header ' + JSON.stringify(k) + ' to not be ' + JSON.stringify(v));
|
|
352
|
+
},
|
|
353
|
+
body: function (b) {
|
|
354
|
+
if (b === undefined) check(!!(__resp.body && __resp.body.length), 'expected response to have a body', 'expected response to not have a body');
|
|
355
|
+
else if (b instanceof RegExp) check(b.test(__resp.body || ''), 'expected response body to match ' + b, 'expected response body to not match ' + b);
|
|
356
|
+
else check((__resp.body || '') === String(b), 'expected response body to equal ' + JSON.stringify(String(b).slice(0, 80)), 'expected response body to not equal ' + JSON.stringify(String(b).slice(0, 80)));
|
|
357
|
+
},
|
|
358
|
+
jsonBody: function (path, value) {
|
|
359
|
+
var data;
|
|
360
|
+
try { data = self.json(); } catch (e) { check(false, 'expected response body to be valid JSON', ''); return; }
|
|
361
|
+
if (path === undefined) { check(true, '', 'expected response body to not be valid JSON'); return; }
|
|
362
|
+
var has = __hasPath(data, path);
|
|
363
|
+
if (value === undefined) check(has, 'expected response JSON to have property ' + JSON.stringify(path), 'expected response JSON to not have property ' + JSON.stringify(path));
|
|
364
|
+
else check(has && __deepEqual(__getPath(data, path), value), 'expected response JSON property ' + JSON.stringify(path) + ' to equal ' + __inspect(value, 1) + ' but got ' + __inspect(__getPath(data, path), 1), 'expected response JSON property ' + JSON.stringify(path) + ' to not equal ' + __inspect(value, 1));
|
|
365
|
+
},
|
|
366
|
+
jsonSchema: function () { throw new Error('pm.response.to.have.jsonSchema is not supported in pyhttp'); },
|
|
367
|
+
};
|
|
368
|
+
var be = {};
|
|
369
|
+
var classes = { info: [100, 199], success: [200, 299], redirection: [300, 399], clientError: [400, 499], serverError: [500, 599], error: [400, 599] };
|
|
370
|
+
Object.keys(classes).forEach(function (name) {
|
|
371
|
+
Object.defineProperty(be, name, { get: function () { var r = classes[name]; check(self.code >= r[0] && self.code <= r[1], 'expected response code to be ' + name + ' (' + r[0] + '-' + r[1] + ') but got ' + self.code, 'expected response code to not be ' + name); return be; } });
|
|
372
|
+
});
|
|
373
|
+
var codes = { ok: 200, accepted: 202, withoutContent: 204, badRequest: 400, unauthorized: 401, forbidden: 403, notFound: 404, rateLimited: 429 };
|
|
374
|
+
Object.keys(codes).forEach(function (name) {
|
|
375
|
+
Object.defineProperty(be, name, { get: function () { check(self.code === codes[name], 'expected response to be ' + name + ' (' + codes[name] + ') but got ' + self.code, 'expected response to not be ' + name); return be; } });
|
|
376
|
+
});
|
|
377
|
+
return { have: have, be: be, get not() { return __respTo(!negate); } };
|
|
378
|
+
}
|
|
379
|
+
__response.to = __respTo(false);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// -------------------------------------------------------------- cookies
|
|
383
|
+
var __cookieList = new PropertyList(((__resp && __resp.cookies) || []).map(function (c) { return [c.name, c.value]; }));
|
|
384
|
+
var __cookies = { get: function (k) { return __cookieList.get(k); }, has: function (k) { return __cookieList.has(k); }, toObject: function () { return __cookieList.toObject(); }, jar: function () { throw new Error('pm.cookies.jar() is not supported in pyhttp; use the Cookies panel'); } };
|
|
385
|
+
|
|
386
|
+
// --------------------------------------------------------------- pm
|
|
387
|
+
var pm = {
|
|
388
|
+
info: Object.assign({ eventName: __S.eventName || 'test', iteration: 0, iterationCount: 1, requestName: '', requestId: '' }, __S.info || {}),
|
|
389
|
+
variables: __variables,
|
|
390
|
+
environment: __scope(__env, 'env'),
|
|
391
|
+
globals: __scope(__globals, 'globals'),
|
|
392
|
+
collectionVariables: __scope(__coll, 'collection'),
|
|
393
|
+
iterationData: Object.assign(__scope(__data, null), { get: function (k) { return __data[k]; } }),
|
|
394
|
+
request: __request,
|
|
395
|
+
response: __response,
|
|
396
|
+
cookies: __cookies,
|
|
397
|
+
expect: function (v, msg) { return new Assertion(v); },
|
|
398
|
+
test: function (name, fn) {
|
|
399
|
+
var passed = true, note = '';
|
|
400
|
+
try { if (typeof fn === 'function') { var r = fn(); if (r && typeof r.then === 'function') { __R.pending = (__R.pending || []).concat([{ name: String(name), promise: r }]); return; } } else if (fn !== undefined && !fn) { passed = false; note = 'condition was false'; } }
|
|
401
|
+
catch (e) { passed = false; note = (e && e.message) ? String(e.message) : String(e); }
|
|
402
|
+
__R.tests.push({ name: String(name), passed: passed, note: note });
|
|
403
|
+
},
|
|
404
|
+
sendRequest: function () { throw new Error('pm.sendRequest is not supported in pyhttp: put the extra request in the collection and use {{prev.json...}} or variables instead'); },
|
|
405
|
+
execution: { setNextRequest: function (n) { __R.nextRequest = n; }, skipRequest: function () { __R.skip = true; } },
|
|
406
|
+
visualizer: { set: function () {} },
|
|
407
|
+
require: function (m) { throw new Error('require(' + JSON.stringify(m) + ') is not available in pyhttp scripts'); },
|
|
408
|
+
};
|
|
409
|
+
pm.test.skip = function (name) { __R.tests.push({ name: String(name), passed: true, note: 'skipped' }); };
|
|
410
|
+
pm.expect.fail = function (msg) { throw new AssertionError(msg || 'expect.fail()'); };
|
|
411
|
+
pm.environment.name = __S.environmentName || '';
|
|
412
|
+
if (__response) { pm.response.to = __response.to; }
|
|
413
|
+
|
|
414
|
+
// ------------------------------------------------------------- legacy
|
|
415
|
+
var tests = {};
|
|
416
|
+
var postman = {
|
|
417
|
+
setEnvironmentVariable: function (k, v) { pm.environment.set(k, v); },
|
|
418
|
+
getEnvironmentVariable: function (k) { return pm.environment.get(k); },
|
|
419
|
+
clearEnvironmentVariable: function (k) { pm.environment.unset(k); },
|
|
420
|
+
setGlobalVariable: function (k, v) { pm.globals.set(k, v); },
|
|
421
|
+
getGlobalVariable: function (k) { return pm.globals.get(k); },
|
|
422
|
+
clearGlobalVariable: function (k) { pm.globals.unset(k); },
|
|
423
|
+
setNextRequest: function (n) { __R.nextRequest = n; },
|
|
424
|
+
getResponseHeader: function (k) { return __response ? __response.headers.get(k) : undefined; },
|
|
425
|
+
};
|
|
426
|
+
var responseBody = __resp ? (__resp.body || '') : undefined;
|
|
427
|
+
var responseCode = __resp ? { code: __resp.code, name: __response.status, detail: '' } : undefined;
|
|
428
|
+
var responseTime = __resp ? __resp.time_ms : undefined;
|
|
429
|
+
var responseHeaders = __resp ? __response.headers.toObject() : undefined;
|
|
430
|
+
var responseCookies = __cookieList.all();
|
|
431
|
+
var request = { url: __reqState.url, method: __reqState.method, headers: __headers.toObject(), data: __reqState.body, name: pm.info.requestName };
|
|
432
|
+
var environment = __env, globals = __globals, iteration = pm.info.iteration, data = __data;
|
|
433
|
+
var chai = { expect: pm.expect, AssertionError: AssertionError };
|
|
434
|
+
var expect = pm.expect;
|
|
435
|
+
|
|
436
|
+
// ------------------------------------------------------------ platform
|
|
437
|
+
var __timers = [];
|
|
438
|
+
function setTimeout(fn, ms) { var id = ++__R.timers; __timers.push({ id: id, fn: fn, at: Number(ms) || 0, args: Array.prototype.slice.call(arguments, 2) }); return id; }
|
|
439
|
+
function clearTimeout(id) { __timers = __timers.filter(function (t) { return t.id !== id; }); }
|
|
440
|
+
function setInterval() { throw new Error('setInterval is not supported in pyhttp scripts'); }
|
|
441
|
+
function setImmediate(fn) { return setTimeout(fn, 0); }
|
|
442
|
+
var __B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
443
|
+
function btoa(input) {
|
|
444
|
+
var str = String(input), out = '', i = 0;
|
|
445
|
+
while (i < str.length) {
|
|
446
|
+
var a = str.charCodeAt(i++), b = str.charCodeAt(i++), c = str.charCodeAt(i++);
|
|
447
|
+
if (a > 255 || b > 255 || c > 255) throw new Error('btoa: string contains characters outside Latin1');
|
|
448
|
+
var n = (a << 16) | ((b || 0) << 8) | (c || 0);
|
|
449
|
+
out += __B64[(n >> 18) & 63] + __B64[(n >> 12) & 63] + (isNaN(b) ? '=' : __B64[(n >> 6) & 63]) + (isNaN(c) ? '=' : __B64[n & 63]);
|
|
450
|
+
}
|
|
451
|
+
return out;
|
|
452
|
+
}
|
|
453
|
+
function atob(input) {
|
|
454
|
+
var str = String(input).replace(/[^A-Za-z0-9+/]/g, ''), out = '', i = 0;
|
|
455
|
+
while (i < str.length) {
|
|
456
|
+
var a = __B64.indexOf(str[i++]), b = __B64.indexOf(str[i++]), c = __B64.indexOf(str[i++]), d = __B64.indexOf(str[i++]);
|
|
457
|
+
var n = (a << 18) | (b << 12) | ((c & 63) << 6) | (d & 63);
|
|
458
|
+
out += String.fromCharCode((n >> 16) & 255);
|
|
459
|
+
if (c !== -1) out += String.fromCharCode((n >> 8) & 255);
|
|
460
|
+
if (d !== -1) out += String.fromCharCode(n & 255);
|
|
461
|
+
}
|
|
462
|
+
return out;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// ------------------------------------------------------------- finish
|
|
466
|
+
function __formatError(e) {
|
|
467
|
+
if (e instanceof AssertionError) return 'AssertionError: ' + e.message;
|
|
468
|
+
var s = (e && e.stack) ? String(e.stack) : String(e);
|
|
469
|
+
if (e && e.message && s.indexOf(e.message) === -1) s = (e.name || 'Error') + ': ' + e.message + '\n' + s;
|
|
470
|
+
return s;
|
|
471
|
+
}
|
|
472
|
+
function __runTimers() {
|
|
473
|
+
var guard = 0;
|
|
474
|
+
while (__timers.length && guard++ < 1000) {
|
|
475
|
+
__timers.sort(function (a, b) { return a.at - b.at; });
|
|
476
|
+
var t = __timers.shift();
|
|
477
|
+
try { t.fn.apply(null, t.args); } catch (e) { __R.error = __R.error || __formatError(e); }
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
// async pm.test callbacks (return a promise): settle them before collecting results
|
|
481
|
+
function __settle() {
|
|
482
|
+
var pending = __R.pending || [];
|
|
483
|
+
__R.pending = [];
|
|
484
|
+
pending.forEach(function (p) {
|
|
485
|
+
p.promise.then(function () { __R.tests.push({ name: p.name, passed: true, note: '' }); },
|
|
486
|
+
function (e) { __R.tests.push({ name: p.name, passed: false, note: (e && e.message) ? String(e.message) : String(e) }); });
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
function __result() {
|
|
490
|
+
__runTimers();
|
|
491
|
+
Object.keys(tests).forEach(function (k) { __R.tests.push({ name: k, passed: !!tests[k], note: tests[k] ? '' : 'legacy tests[] entry was false' }); });
|
|
492
|
+
if (__S.eventName === 'prerequest') {
|
|
493
|
+
__R.request = { method: __reqState.method, url: __reqState.url, headers: __headers._pairs(), params: __query._pairs(), body: __reqState.body };
|
|
494
|
+
}
|
|
495
|
+
return JSON.stringify(__R);
|
|
496
|
+
}
|