How to use req1 method in wpt

Best JavaScript code snippet using wpt

blocks.py

Source:blocks.py Github

copy

Full Screen

1from sulley import *2def run ():3 groups_and_num_test_cases()4 dependencies()5 repeaters()6 return_current_mutant()7 exhaustion()8 # clear out the requests.9 blocks.REQUESTS = {}10 blocks.CURRENT = None11########################################################################################################################12def groups_and_num_test_cases ():13 s_initialize("UNIT TEST 1")14 s_size("BLOCK", length=4, name="sizer")15 s_group("group", values=["\x01", "\x05", "\x0a", "\xff"])16 if s_block_start("BLOCK"):17 s_delim(">", name="delim")18 s_string("pedram", name="string")19 s_byte(0xde, name="byte")20 s_word(0xdead, name="word")21 s_dword(0xdeadbeef, name="dword")22 s_qword(0xdeadbeefdeadbeef, name="qword")23 s_random(0, 5, 10, 100, name="random")24 s_block_end()25 # count how many mutations we get per primitive type.26 req1 = s_get("UNIT TEST 1")27 print "PRIMITIVE MUTATION COUNTS (SIZES):"28 print "\tdelim: %d\t(%s)" % (req1.names["delim"].num_mutations(), sum(map(len, req1.names["delim"].fuzz_library)))29 print "\tstring: %d\t(%s)" % (req1.names["string"].num_mutations(), sum(map(len, req1.names["string"].fuzz_library)))30 print "\tbyte: %d" % req1.names["byte"].num_mutations()31 print "\tword: %d" % req1.names["word"].num_mutations()32 print "\tdword: %d" % req1.names["dword"].num_mutations()33 print "\tqword: %d" % req1.names["qword"].num_mutations()34 print "\tsizer: %d" % req1.names["sizer"].num_mutations()35 # we specify the number of mutations in a random field, so ensure that matches.36 assert(req1.names["random"].num_mutations() == 100)37 # we specify the number of values in a group field, so ensure that matches.38 assert(req1.names["group"].num_mutations() == 4)39 # assert that the number of block mutations equals the sum of the number of mutations of its components.40 assert(req1.names["BLOCK"].num_mutations() == req1.names["delim"].num_mutations() + \41 req1.names["string"].num_mutations() + \42 req1.names["byte"].num_mutations() + \43 req1.names["word"].num_mutations() + \44 req1.names["dword"].num_mutations() + \45 req1.names["qword"].num_mutations() + \46 req1.names["random"].num_mutations())47 s_initialize("UNIT TEST 2")48 s_group("group", values=["\x01", "\x05", "\x0a", "\xff"])49 if s_block_start("BLOCK", group="group"):50 s_delim(">", name="delim")51 s_string("pedram", name="string")52 s_byte(0xde, name="byte")53 s_word(0xdead, name="word")54 s_dword(0xdeadbeef, name="dword")55 s_qword(0xdeadbeefdeadbeef, name="qword")56 s_random(0, 5, 10, 100, name="random")57 s_block_end()58 # assert that the number of block mutations in request 2 is len(group.values) (4) times that of request 1.59 req2 = s_get("UNIT TEST 2")60 assert(req2.names["BLOCK"].num_mutations() == req1.names["BLOCK"].num_mutations() * 4)61########################################################################################################################62def dependencies ():63 s_initialize("DEP TEST 1")64 s_group("group", values=["1", "2"])65 if s_block_start("ONE", dep="group", dep_values=["1"]):66 s_static("ONE" * 100)67 s_block_end()68 if s_block_start("TWO", dep="group", dep_values=["2"]):69 s_static("TWO" * 100)70 s_block_end()71 assert(s_num_mutations() == 2)72 assert(s_mutate() == True)73 assert(s_render().find("TWO") == -1)74 assert(s_mutate() == True)75 assert(s_render().find("ONE") == -1)76 assert(s_mutate() == False)77########################################################################################################################78def repeaters ():79 s_initialize("REP TEST 1")80 if s_block_start("BLOCK"):81 s_delim(">", name="delim", fuzzable=False)82 s_string("pedram", name="string", fuzzable=False)83 s_byte(0xde, name="byte", fuzzable=False)84 s_word(0xdead, name="word", fuzzable=False)85 s_dword(0xdeadbeef, name="dword", fuzzable=False)86 s_qword(0xdeadbeefdeadbeef, name="qword", fuzzable=False)87 s_random(0, 5, 10, 100, name="random", fuzzable=False)88 s_block_end()89 s_repeat("BLOCK", min_reps=5, max_reps=15, step=5)90 data = s_render()91 length = len(data)92 s_mutate()93 data = s_render()94 assert(len(data) == length + length * 5)95 s_mutate()96 data = s_render()97 assert(len(data) == length + length * 10)98 s_mutate()99 data = s_render()100 assert(len(data) == length + length * 15)101 s_mutate()102 data = s_render()103 assert(len(data) == length)104########################################################################################################################105def return_current_mutant ():106 s_initialize("RETURN CURRENT MUTANT TEST 1")107 s_dword(0xdeadbeef, name="boss hog")108 s_string("bloodhound gang", name="vagina")109 if s_block_start("BLOCK1"):110 s_string("foo", name="foo")111 s_string("bar", name="bar")112 s_dword(0x20)113 s_block_end()114 s_dword(0xdead)115 s_dword(0x0fed)116 s_string("sucka free at 2 in morning 7/18", name="uhntiss")117 req1 = s_get("RETURN CURRENT MUTANT TEST 1")118 # calculate the length of the mutation libraries dynamically since they may change with time.119 num_str_mutations = req1.names["foo"].num_mutations()120 num_int_mutations = req1.names["boss hog"].num_mutations()121 for i in xrange(1, num_str_mutations + num_int_mutations - 10 + 1):122 req1.mutate()123 assert(req1.mutant.name == "vagina")124 req1.reset()125 for i in xrange(1, num_int_mutations + num_str_mutations + 1 + 1):126 req1.mutate()127 assert(req1.mutant.name == "foo")128 req1.reset()129 for i in xrange(num_str_mutations * 2 + num_int_mutations + 1):130 req1.mutate()131 assert(req1.mutant.name == "bar")132 req1.reset()133 for i in xrange(num_str_mutations * 3 + num_int_mutations * 4 + 1):134 req1.mutate()135 assert(req1.mutant.name == "uhntiss")136 req1.reset()137########################################################################################################################138def exhaustion ():139 s_initialize("EXHAUSTION 1")140 s_string("just wont eat", name="VIP")141 s_dword(0x4141, name="eggos_rule")142 s_dword(0x4242, name="danny_glover_is_the_man")143 req1 = s_get("EXHAUSTION 1")144 num_str_mutations = req1.names["VIP"].num_mutations()145 # if we mutate string halfway, then exhaust, then mutate one time, we should be in the 2nd primitive146 for i in xrange(num_str_mutations/2):147 req1.mutate()148 req1.mutant.exhaust()149 req1.mutate()150 assert(req1.mutant.name == "eggos_rule")151 req1.reset()152 # if we mutate through the first primitive, then exhaust the 2nd, we should be in the 3rd153 for i in xrange(num_str_mutations + 2):154 req1.mutate()155 req1.mutant.exhaust()156 req1.mutate()157 assert(req1.mutant.name == "danny_glover_is_the_man")158 req1.reset()159 # if we exhaust the first two primitives, we should be in the third160 req1.mutant.exhaust()161 req1.mutant.exhaust()...

Full Screen

Full Screen

test-pool.js

Source:test-pool.js Github

copy

Full Screen

1'use strict';2var request = require('../index');3var http = require('http');4var tape = require('tape');5var s = http.createServer(function (req, res) {6 res.statusCode = 200;7 res.end('asdf');8});9tape('setup', function (t) {10 s.listen(0, function () {11 s.url = 'http://localhost:' + this.address().port;12 t.end();13 });14});15tape('pool', function (t) {16 request({17 url: s.url,18 pool: false19 }, function (err, res, body) {20 t.equal(err, null);21 t.equal(res.statusCode, 200);22 t.equal(body, 'asdf');23 var agent = res.request.agent;24 t.equal(agent, false);25 t.end();26 });27});28tape('forever', function (t) {29 var r = request({30 url: s.url,31 forever: true,32 pool: { maxSockets: 1024 }33 }, function (err, res, body) {34 // explicitly shut down the agent35 if (typeof r.agent.destroy === 'function') {36 r.agent.destroy();37 } else {38 // node < 0.1239 Object.keys(r.agent.sockets).forEach(function (name) {40 r.agent.sockets[name].forEach(function (socket) {41 socket.end();42 });43 });44 }45 t.equal(err, null);46 t.equal(res.statusCode, 200);47 t.equal(body, 'asdf');48 var agent = res.request.agent;49 t.equal(agent.maxSockets, 1024);50 t.end();51 });52});53tape('forever, should use same agent in sequential requests', function (t) {54 var r = request.defaults({55 forever: true56 });57 var req1 = r(s.url);58 var req2 = r(s.url + '/somepath');59 req1.abort();60 req2.abort();61 if (typeof req1.agent.destroy === 'function') {62 req1.agent.destroy();63 }64 if (typeof req2.agent.destroy === 'function') {65 req2.agent.destroy();66 }67 t.equal(req1.agent, req2.agent);68 t.end();69});70tape('forever, should use same agent in sequential requests(with pool.maxSockets)', function (t) {71 var r = request.defaults({72 forever: true,73 pool: { maxSockets: 1024 }74 });75 var req1 = r(s.url);76 var req2 = r(s.url + '/somepath');77 req1.abort();78 req2.abort();79 if (typeof req1.agent.destroy === 'function') {80 req1.agent.destroy();81 }82 if (typeof req2.agent.destroy === 'function') {83 req2.agent.destroy();84 }85 t.equal(req1.agent.maxSockets, 1024);86 t.equal(req1.agent, req2.agent);87 t.end();88});89tape('forever, should use same agent in request() and request.verb', function (t) {90 var r = request.defaults({91 forever: true,92 pool: { maxSockets: 1024 }93 });94 var req1 = r(s.url);95 var req2 = r.get(s.url);96 req1.abort();97 req2.abort();98 if (typeof req1.agent.destroy === 'function') {99 req1.agent.destroy();100 }101 if (typeof req2.agent.destroy === 'function') {102 req2.agent.destroy();103 }104 t.equal(req1.agent.maxSockets, 1024);105 t.equal(req1.agent, req2.agent);106 t.end();107});108tape('should use different agent if pool option specified', function (t) {109 var r = request.defaults({110 forever: true,111 pool: { maxSockets: 1024 }112 });113 var req1 = r(s.url);114 var req2 = r.get({115 url: s.url,116 pool: { maxSockets: 20 }117 });118 req1.abort();119 req2.abort();120 if (typeof req1.agent.destroy === 'function') {121 req1.agent.destroy();122 }123 if (typeof req2.agent.destroy === 'function') {124 req2.agent.destroy();125 }126 t.equal(req1.agent.maxSockets, 1024);127 t.equal(req2.agent.maxSockets, 20);128 t.notEqual(req1.agent, req2.agent);129 t.end();130});131tape('cleanup', function (t) {132 s.close(function () {133 t.end();134 });...

Full Screen

Full Screen

tests.py

Source:tests.py Github

copy

Full Screen

1"""2 This file demonstrates writing tests using the unittest module. These will pass3 when you run "manage.py test".4 Replace this with more appropriate tests for your application.5"""6from django.test import TestCase7from django.contrib.auth.models import User8from django.core.exceptions import ObjectDoesNotExist9from login.models import patient, doctor10from docview.models import request_call11import math12class SimpleTest(TestCase):13 def test_basic_addition(self):14 """15 Tests that 1 + 1 always equals 2.16 """17 self.assertEqual(1 + 1, 2)18class Req_Call_Test(TestCase):19 def setUp(self):20 self.u1 = User.objects.create(username='user1')21 self.u2 = User.objects.create(username='user2')22 self.pat1 = patient.objects.create(user=self.u2, age="18", sex="M")23 self.doc1 = doctor.objects.create(user=self.u1, \24 address="36 China Town", phone_no=123456789, ug_year=2010, \25 ug_regno=1995, pg_year=2012, pg_regno=23123, pref_time="08:00:00")26 self.req1 = request_call.objects.create(patient=self.pat1, doc=self.doc1)27 def testUserDoctor(self):28 try:29 req1 = request_call.objects.get(patient=self.pat1, doc=self.doc1)30 self.assertEqual(req1.sent, self.req1.sent)31 self.assertEqual(req1.acknowledged, self.req1.acknowledged)32 self.assertEqual(req1.calldone, self.req1.calldone)33 self.assertEqual(req1.prescription_sent, self.req1.prescription_sent)34 self.assertEqual(False, self.req1.sent)35 self.assertEqual(False, self.req1.acknowledged)36 self.assertEqual(False, self.req1.calldone)37 self.assertEqual(False, self.req1.prescription_sent)38 self.assertEqual(req1.date_booked, self.req1.date_booked)39 span = req1.date_booked - self.req1.date_booked;40 hours = math.floor(((span).seconds) / 3600)41 minutes = math.floor(((span).seconds) / 60)42 self.assertEqual(hours, 0.0)43 self.assertEqual(minutes, 0.0)44 self.assertEqual((span).seconds,0.0)45 except ObjectDoesNotExist:46 raise ObjectDoesNotError('Request_call object not found.')47 #print "request_call object was either not created or could not be extracted"48 49 def tearDown(self):50 self.req1.delete() 51 self.pat1.delete() 52 self.doc1.delete()53 self.u1.delete()...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');3 console.log(data);4});5 console.log(data);6});7wpt.getTestStatus('1234567890', function(err, data) {8 console.log(data);9});10wpt.getTestResults('1234567890', function(err, data) {11 console.log(data);12});13var WebPageTest = function(host, key) {14 this.host = host;15 this.key = key;16};17WebPageTest.prototype = {18 runTest: function(url, options, callback) {19 if (typeof options === 'function') {20 callback = options;21 options = {};22 }23 var params = { url: url };24 for (var key in options) {25 params[key] = options[key];26 }27 this.req1('runtest', params, callback);28 },29 getTestStatus: function(testId, callback) {30 this.req1('testStatus', { test: testId }, callback);31 },32 getTestResults: function(testId, callback) {33 this.req1('getTestResults', { test: testId }, callback);34 },35 req1: function(method, params, callback) {36 params.f = 'json';37 params.k = this.key;38 var querystring = require('querystring');39 var http = require('http');40 var options = {41 path: '/runtest.php?' + querystring.stringify(params)42 };43 http.get(options, function(res) {44 var data = '';45 res.on('data', function(chunk) {46 data += chunk;47 });48 res.on('end', function() {49 callback(null, JSON.parse(data));50 });51 }).on('error', function(e) {52 callback(e);53 });54 }55};56module.exports = WebPageTest;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2req1.on('data', function(data) {3 console.log(data);4});5req1.on('end', function() {6 console.log('end');7});8req1.on('error', function(err) {9 console.log(err);10});11req1.end();12var http = require('http');13var util = require('util');14var EventEmitter = require('events').EventEmitter;15var wpt = function() {16 this.host = 'www.webpagetest.org';17 this.port = 80;18 this.path = '/runtest.php?k=API_KEY&f=json&url=';19};20wpt.prototype.req1 = function(url) {21 var em = new EventEmitter();22 var req = http.request({23 }, function(res) {24 res.on('data', function(data) {25 em.emit('data', data);26 });27 res.on('end', function() {28 em.emit('end');29 });30 });31 req.on('error', function(err) {32 em.emit('error', err);33 });34 return req;35};36module.exports = new wpt();37var http = require('http');38var options = {39};40callback = function(response) {41 var str = '';42 response.on('data', function (chunk) {43 str += chunk;44 });45 response.on('end', function () {46 console.log(str);47 });48}49http.request(options, callback).end();50 at errnoException (net.js:904:11)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var req1 = wpt.req1();3req1.on('data', function(data) {4 console.log(data);5});6req1.end();7var http = require('http');8module.exports = {9 req1: function() {10 var options = {11 };12 return http.request(options, function(response) {13 response.on('data', function(data) {14 return data;15 });16 });17 }18};19var express = require('express');20var app = express();21var path = require('path');22app.get('/', function(req, res) {23 res.sendFile(path.join(__dirname + '/index.html'));24});25app.listen(8080);26var http = require('http');27var server = http.createServer(function(req, res) {28 res.writeHead(200, {'Content-Type': 'application/json'});29 res.end('{"name":"John Doe"}');30});31server.listen(3000);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var options = {3};4wpt.req1(options, function (err, data) {5 if (err) {6 console.log('error:', err);7 } else {8 console.log('data:', data);9 }10});11var wpt = require('wpt');12var options = {13};14wpt.req2(options, function (err, data) {15 if (err) {16 console.log('error:', err);17 } else {18 console.log('data:', data);19 }20});21var wpt = require('wpt');22var options = {23};24wpt.req3(options, function (err, data) {25 if (err) {26 console.log('error:', err);27 } else {28 console.log('data:', data);29 }30});31var wpt = require('wpt');32var options = {33};34wpt.req4(options, function (err, data) {35 if (err) {36 console.log('error:', err);37 } else {38 console.log('data:', data);39 }40});41var wpt = require('wpt');42var options = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var wptObj = new wpt('API_KEY');3wptObj.req1(url, function(err, data) {4 if (err) {5 console.log('Error: ', err);6 } else {7 console.log('Data: ', data);8 }9});10var request = require('request');11module.exports = function Wpt(apiKey) {12 this.apiKey = apiKey;13};14module.exports.prototype.req1 = function(url, callback) {15 var options = {16 headers: {17 }18 };19 request(options, function(error, response, body) {20 if (!error && response.statusCode == 200) {21 callback(null, body);22 } else {23 callback(error, null);24 }25 });26};27Error: { [Error: connect ECONNREFUSED] code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect' }28Error: { [Error: connect ECONNREFUSED] code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var req1 = new wpt('mykey');3 console.log(data);4});5var request = require('request');6var wpt = function(key) {7 this.key = key;8};9wpt.prototype.runTest = function(url, cb) {10 var options = {11 headers: {12 }13 };14 request(options, function(error, response, body) {15 if (!error && response.statusCode == 200) {16 cb(body);17 } else {18 cb(error);19 }20 });21};22module.exports = wpt;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require("webpagetest");2var webPageTest = new wpt("www.webpagetest.org", "A.7a8b9c10d11e12f13g14h15i16j17k18l19m20n21o22p23q24r25s26t27u28v29w30x31y32z33");3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9{ statusCode: 200,10 { statusCode: 200,11 { testId: '170516_6T_1e1f',

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt2 = new wpt('API_KEY');3 console.log(data);4});5var wpt = require('wpt');6var wpt2 = new wpt('API_KEY');7 console.log(data);8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.2e7f8c1d6e7dbf3e3c24a3c8f1d0f3b3');3var url = 'www.google.com';4wpt.runTest(url, {location: 'Dulles:Chrome'}, function(err, data) {5 console.log(data);6});

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 wpt 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