Synthesizing SVT Data

From PeformIQ Upgrade
Revision as of 09:13, 16 April 2008 by PeterHarding (talk | contribs)
Jump to navigation Jump to search

Overview

Preparing data for performance tests is a very important part of the preparation phase for a load test exercise. The following scripts provide simple examples of approaches to synthesize parameter data for use by the test scripts.

User Login IDs

#!/usr/bin/env python

print 'UserId'

for i in range(200):
   print "svt%03d" % i

Unquoting URL Data

#!/usr/bin/env python

import urllib                                                                                                                                                                       

encoded_data = """
%3CPromptEngineRuntimeContext%20xmlns%3D%22http%3A%2F%2Fwww.crystaldecisions.com%2Freport%22%20xmlns%3Axsi%3D%22http%3A%2F%2F
www.w3.org%2F2001%2FXMLSchema-instance%22%20xmlns%3Axsd%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%22%20xsi%3Atype%3D%22
PromptEngineRuntimeContext%22%20version%3D%222%22%3E%3CID%3E{MachineXID}%3C%2FID%3E%3CRenderOption%20xsi%3Atype%3D%22
BOwner%26gt%3B%26lt%3B%2FOwner%26gt%3B%26lt%3BDefinition%20xsi%3Atype%3D%22Parameter%22%20id%3D%225%22%26gt%3B%26lt%3B",                                                                         
"""                                                                                                                                                                                 

data = urllib.unquote(encoded_data)                                                                                                                                                               

print data                           

Generating Synthetic Credit Card Numbers

#!/usr/bin/env python
#
#
#
#-------------------------------------------------------------------------------

"""
Generate a abitrary collection of pseudo Credit card numbers which
satisfy the validation test
"""


import random

#-------------------------------------------------------------------------------

prefix      = '1234'
max_digits  = 16
max_numbers = 1000

#-------------------------------------------------------------------------------

def gen(prefix):
   no = prefix

   l = list(no)

   i = len(prefix)

   while (i < (max_digits - 1)):
      x = random.randint(0, 9)

      l.append(str(x))
      # print i, l, x
      i += 1

   no = ''.join(l)

   chk_digit = encode(no) 

   delta = 10 - chk_digit

   if delta == 10:
      delta = 0

   # print chk_digit, delta

   l.append(str(delta))

   no = ''.join(l)

   return no

#-------------------------------------------------------------------------------

def encode(no):
   n   = 0
   tot = 0

   for i in range(len(no)):
      v = int(no[i])

      if i % 2 == 0:
         inc = v * 2
         if v > 4:
            n += 1
      else:
         inc = v

      tot += inc

   tot += n

   chk = tot % 10

   return chk

#-------------------------------------------------------------------------------

def validate(ccnumber):
   cnt = 0
   tot = 0

   for i in range(len(ccnumber)):
      val = int(ccnumber[i])

      if i % 2 == 0:
         inc = val * 2
         if val > 4:
            cnt += 1
      else:
         inc = val

      tot += inc

   tot += cnt

   if ((tot % 10) == 0):
      return True
   else:
      return False

#-------------------------------------------------------------------------------

def test():
   for no in nos:
      print no

      if validate(no):
         print "Card number VALID"
      else:
         print "Card number INVALID"

#-------------------------------------------------------------------------------

def main():
   i = 0

   while i < max_numbers:
      cc_no = gen(prefix)
      
      if validate(cc_no):
         print cc_no
      else:
         print "Card number %s - INVALID" % cc_no
         cc_no = None

      if cc_no:
         i += 1
      else:
         pass


#-------------------------------------------------------------------------------

main()

#-------------------------------------------------------------------------------

Other Examples