Bulk Test Data Generator
Project description
Introduction
D-Thok is a python package to generate mock Test data in csv, json and xml format which can be used for any Mock Service, Performance Testing etc. It required input parameter as schema file where required structure is defined with data type, number of records, required format and file name.
Index
Setup | Installation | Execution |
---|---|
Input Data Type |
alphabets
| alpha-numeric
| numeric
| code
| title
| firstName
| lastName
| date_of_birth
| choices
| PhoneNumber
| email
| streetName
| postcode
| country
| city
| date
| company
| boolean
| accountNumber
| constant
|
Output File Format | csv | json | xml |
Input Datatype
Required input schema definition have to provided with all required Field name and required datatype in JSON format. Here is Sample input Schema definition file,
[
{
"EmployeeID" : "code||PALO-%%-##LTD!@",
"Salutation" : "alphabet||title",
"Firstname" : "alphabet|20|firstName",
"Lastname" : "alphabet|20|lastName",
"DOB" : "date_of_birth|MinAge=30,MaxAge=40|%m-%d-%Y",
"Gender" : "choices|('Male', 'Female')|",
"Mobile" : "PhoneNumber||India",
"emailId" : "alphanum||email",
"Address" :
{
"AddressType" : "choices|('RES', 'OFF', 'WRK')|",
"Street-1" : "alphabet|20|streetName",
"Street-2" : "alphanum|20|streetName",
"Postalcode" : "numeric|6|postcode",
"country" : "alphabet||country",
"city" : "alphabet||city"
},
"DOJ" : "date|StartDate=20100223,EndDate=20200330|%Y-%m-%d",
"Client" : "alphabet||company",
"Active" : "boolean||",
"AccountNum" : "alphanum|NONE|accountNumber",
"Salary" : "constant|Monthly|",
"DeskNumber" : "constant|null|"
}
]
Below are the sample data type syntax that can be used in input file.
alphabets
To generate random alphabetic String
Syntax:
"<Node Name>" : "alphabet|<length>"
e.g.
"ProductName" : "alphabet|30"
alphanum
To generate random alphanumeric String
Syntax:
"<Node Name>" : "alphanum|<length>"
e.g.
"ProductNumber" : "alphanum|30"
numeric
To generate random numeric value
Syntax:
"<Node Name>" : "numeric|<length>"
e.g.
"ProductID" : "numeric|30"
code
If you want to generate a code with some Prefix String
Syntax:
"<Node Name>" : "code||<Prefix String><regex>"
- Number signs (‘#’) are replaced with a random digit (0 to 9)
- Number signs (‘#’) are replaced with a random digit (0 to 9)
- Percent signs (‘%’) are replaced with a random non-zero digit (1 to 9)
- Exclamation marks (‘!’) are replaced with a random digit or an empty string
- At symbols (‘@’) are replaced with a random non-zero digit or an empty string
e.g.
"EmployeeID" : "code||PALO-%%-##LTD!@"
Output:
"EmployeeID": "PALO-26-12LTD8"
title
To generate random salutations like Dr. or Mr. or Mrs. or Mx.
Syntax:
"<Node Name>" : "alphabet||title"
e.g.
"Salutation" : "alphabet||title"
Output:
"Salutation": "Mr."
firstName
Use to generate random firstName
Syntax:
"<Node Name>" : "alphabet|<Max length>|firstName"
e.g.
"Firstname" : "alphabet|20|firstName",
Output:
"Firstname": "Samantha"
lastName
Use to generate random lastname
Syntax:
"<Node Name>" : "alphabet|<Max length>|lastName"
e.g.
"LastName" : "alphabet|20|lastName"
Output:
"LastName": "Daniel"
date_of_birth
Use to generate random date_of_birth
Syntax:
"<Node Name>" : "date_of_birth|MinAge=<age>,MaxAge=<age>|<DateFormat>"
e.g.
"DOB" : "date_of_birth|MinAge=30,MaxAge=40|%m-%d-%Y"
Output:
"DOB": "04-14-1981"
choices
If we want to select a value randomly from given choices
Syntax:
"<Node Name>" : "choices|(<'value1', 'value2'>)|"
e.g.
"AddressType": "choices|('RES', 'OFF', 'WRK')|"
Output:
"AddressType": "RES"
PhoneNumber
Random Phone Number based on country
Syntax:
"<Node Name>" : "PhoneNumber||<Country Name>"
e.g.
"Mobile" : "PhoneNumber||India"
Output:
"Mobile": "+917880010426"
Random Email Address
Syntax:
"<Node Name>" : "alphanum||email"
e.g.
"emailId" : "alphanum||email"
Output:
"emailId": "ncooper@hopkins.com"
streetName
Random Street Address Name
Syntax:
"<Node Name>" : "alphabet|<length>|streetName"
e.g.
"Street-1": "alphabet|20|streetName"
Output:
"Street-1": "Douglas Crossing"
postcode
Random postcode
Syntax:
"<Node Name>" : "numeric|<length>|postcode"
e.g.
"Postalcode": "numeric|6|postcode"
Output:
"Postalcode": "20494"
country
Random country
Syntax:
"<Node Name>" : "alphabet||country"
e.g.
"country": "alphabet||country"
Output:
"country": "Singapore"
city
Random city
Syntax:
"<Node Name>" : "alphabet||city"
e.g.
"City": "alphabet||city"
Output:
"city": "Bangalore"
date
Generate Random Date between two date
Syntax:
"<Node Name>" : "date|StartDate=<date in yyyyMMdd>,EndDate=<date in yyyyMMdd>|<required Date Format>"
e.g.
"DOJ": "date|StartDate=20100223,EndDate=20200330|%Y-%m-%d"
Output:
"DOJ": "2011-07-04"
company
Generate Random Company Name
Syntax:
"<Node Name>" : "alphabet||company"
e.g.
"Client": "alphabet||company"
Output:
"Client": "Williams-Harris"
boolean
Randomly choose boolean value
Syntax:
"<Node Name>" : "boolean||"
e.g.
"Active": "boolean||"
Output:
"Active": "False"
accountNumber
Generate random Basic or Internal account number
Syntax:
"<Node Name>" : "alphanum|<Account Type>|accountNumber"
- NONE - Generate a Basic Bank Account Number (BBAN)
- Internal - Generate an International Bank Account Number (IBAN)
e.g.
"AccountNum": "alphanum|NONE|accountNumber"
Output:
"AccountNum": "JRMR05894987945503"
constant
If you want to use Constant values for all the records
Syntax:
"<Node Name>" : "constant|<Required Value>|"
- NONE - Generate a Basic Bank Account Number (BBAN)
- Internal - Generate an International Bank Account Number (IBAN)
e.g.
"Salary": "constant|Monthly|"
Output:
"Salary": "Monthly"
Installation
Run the following to install:
pip install dthok
Note: Python version should be >=3.6
Execution
- Command structure to generate required bulk file,
dthok -f <input Payload file path> -n <No. of Records> -fmt <Output file format (csv, json or xml)> -o <Output file name>
For Example:
dthok -f /test1.json -n 10 -fmt json -o MyTestData
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.