DataGen

This section contains source code documentation of DataGen extensions.

datagen

Extension for data generators

class hydratk.extensions.datagen.datagen.Extension(core_instance=None)

Class Extension

_init_extension()

Method initializes extension

Parameters:none
Returns:void
_check_dependencies()

Method checks dependent modules

Parameters:none
Returns:bool
_uninstall()

Method returns additional uninstall data

Parameters:none
Returns:list (files), list (modules)
Return type:tuple
_register_actions()

Method registers actions

Parameters:none
Returns:void
_register_htk_actions()

Method registers command hooks

Parameters:none
Returns:void
_register_standalone_actions()

Method registers command hooks for standalone mode

Parameters:none
Returns:void
gen_asn1()

Method handles command gen-asn1

Encode text file, decode binary file according to ASN.1 specification

Parameters:none
Returns:void
gen_json()

Method handles command gen-json

Generate sample JSON file according to JSON specification

Parameters:none
Returns:void
gen_xml()

Method handles command gen-xml

Generate sample XML file according to WSDL/XSD specification

Parameters:none
Returns:void
gen_selenium()

Method handles command gen-selenium

Adapt Selenium script to Yoda format

Parameters:none
Returns:void

bootstrapper

Providing custom bootstrapper for datagen standalone app

hydratk.extensions.datagen.bootstrapper.run_app()

Methods runs datagen standalone application

Parameters:none
Returns:void

asn1

Module for ASN.1 codec

class hydratk.extensions.datagen.asn1codec.ASN1Codec

Class ASN1Codec

__init__()

Class constructor

Called when object is initialized

Parameters:none
path

path property getter

spec

spec property getter

elements

elements property getter

__str__()

Method overrides __str__

Parameters:none
Returns:str
import_spec(filename)

Method imports specification

Parameters:

filename (str) – filename

Returns:

result

Return type:

bool

Raises:
  • event – asn1_before_import_spec
  • event – asn1_after_import_spec
encode(infile, element, outfile=None)

Method encodes json file to binary

Parameters:
  • infile (str) – input filename
  • element (str) – element name
  • outfile (str) – output filename, default infile with suffix bin
Returns:

result

Return type:

bool

Raises:
  • event – asn1_before_encode
  • event – asn1_after_encode
decode(infile, element, outfile=None)

Method decodes binary file to json

Parameters:
  • infile (str) – input filename
  • element (str) – element name
  • outfile (str) – output filename, default infile with suffix json
Returns:

result

Return type:

bool

Raises:
  • event – asn1_before_decode
  • event – asn1_after_decode
_update_datatypes(obj)

Method updates datatypes

It is used in encoder, some datatypes can’t be encoded The object is traversed recursively

Parameters:obj (json) – particular json object
Returns:json object
Return type:json
_split_records(input)

Method splits records from input file

Parameters:input (str) – file contents
Returns:list of records
Return type:list
__weakref__

list of weak references to the object (if defined)

_create_dict(obj, val=None, output=None)

Method creates dictionary according to spec

It is used in decoder, objects are ordered as specified The object is traversed recursively

Parameters:
  • obj (obj) – particular ASN1 object
  • val (obj) – element value
  • output (dict) – particular output
Returns:

ordered dictionary object

Return type:

dict

jsongen

Module for sample JSON generation from JSON schema

class hydratk.extensions.datagen.jsongen.JSONGen

Class JSONGen

__init__()

Class constructor

Called when object is initialized

Parameters:none
path

path property getter

schema

schema property getter

import_schema(filename)

Method imports schema

Parameters:

filename (str) – filename

Returns:

result

Return type:

bool

Raises:
  • event – jsongen_before_import_spec
  • event – jsongen_after_import_spec
tojson(outfile=None)

Method creates sample json file

Parameters:

outfile (str) – output filename, default sample.json

Returns:

result

Return type:

bool

Raises:
  • error – ValueError
  • event – jsongen_before_write
  • event – jsongen_after_write
_tojson_rec(schema=None)

Method creates sample json document

It is used in recursive traversal

Parameters:schema (json) – json schema object
Returns:sample json
Return type:str
Raises:error – ValueError
__weakref__

list of weak references to the object (if defined)

_import_ref_schema(uri)

Method imports referenced schema

local schema is required, http is not supported

Parameters:uri (str) – file uri, absolute path or filename
Returns:json schema
Return type:json
Raises:error – ValueError

xmlgen

Module for sample XML generation from WSDL/XSD

class hydratk.extensions.datagen.xmlgen.XMLGen

Class XMLGen

__init__()

Class constructor

Called when object is initialized

Parameters:none
path

path property getter

client

client property getter

import_spec(filename)

Method imports specification

Parameters:

filename (str) – filename

Returns:

result

Return type:

bool

Raises:
  • event – xmlgen_before_import_spec
  • event – xmlgen_after_import_spec
toxml(root, outfile=None, envelope=False)

Method creates sample xml file

Parameters:
  • root (str) – root element name
  • outfile (str) – output filename, default sample.xml
  • envelope (bool) – create SOAP envelope
Returns:

result

Return type:

bool

Raises:
  • event – xmlgen_before_write
  • event – xmlgen_after_write
_toxml_rec(root, obj=None, ns_cur=None)

Method creates sample xml document

It is used in recursive traversal

Parameters:
  • root (str) – root element name
  • obj (obj) – suds element object
  • ns_cur (str) – current namespace
Returns:

xml document

Return type:

xml

Raises:

error – ValueError

_get_element_type(element)

Method gets element XSD type

It is used to determine if element is Simple or Complex

Parameters:element (str) – element name
Returns:element type
Return type:str
Raises:error – ValueError
_get_element_ns(element)

Method gets element XSD namespace

It is used to construct XML element with correct namespaces

Parameters:element (str) – element name
Returns:element namespace
Return type:str
Raises:error – ValueError
__weakref__

list of weak references to the object (if defined)

_create_dummy_wsdl(xsd)

Method creates dummy WSDL file

Workaround method: Library suds is designed for SOAP and imports WSDL only Dummy WSDL imports given XSD and is parsed automatically File is stored in same folder as XSD file (with suffix .wsdl)

Parameters:xsd (str) – XSD filename
Returns:WSDL filename
Return type:str
Raises:error – ValueError

serializer

Module for class serialization

class hydratk.extensions.datagen.serializer.Serializer

Class Serializer

static tostr(obj)

Method serializes class instance to string

By default the serializer gets all instance attributes (set in constructor) and writes them in default order. Class can have special class attributes (not set in constructor) _order - list of instance attributes names, it defines serialization order, missing attributes are omitted (not serialized) _naming - dictionary (key - attribute name, value - new name used in serialization)

Parameters:obj (obj) – class instance
Returns:str
static toxml(obj, xml_declaration=False)

Method serializes class instance to xml string

Parameters:
  • obj (obj) – class instance
  • xml_declaration (bool) – include XML declaration
Returns:

str

static tojson(obj)

Method serializes class instance to json string

Method is not supported for Python 2.6

Parameters:obj (obj) – class instance
Returns:str
Raises:error – NotImplementedError
static _get_attrs(obj)

Method returns class instance attributes

Parameters:obj (obj) – class instance
Returns:dict
static _has_attrs(obj)

Method checks if object has instance attributes

Parameters:obj (obj) – class instance
Returns:bool
static _tostr(obj, level=1)

Method serializes given object to string

It is used in recursive traversal Processing per object type (class instance, list, dictionary, simple type)

Parameters:
  • obj (obj) – object of any type (not just class instance)
  • level (int) – indentation level
Returns:

str

static _toxml(obj, title=None)

Method serializes given object to xml string

It is used in recursive traversal Processing per object type (class instance, list, dictionary, simple type)

Parameters:
  • obj (obj) – object of any type (not just class instance)
  • title (str) – item title for list elements (multiple cardinality)
Returns:

str

static _tojson(obj)

Method serializes given object to ordered dictionary

It is used in recursive traversal Processing per object type (class instance, list, dictionary, simple type)

Parameters:obj (obj) – object of any type (not just class instance)
Returns:dict
__weakref__

list of weak references to the object (if defined)

selenium

Adapter for Selenium scripts to Yoda

class hydratk.extensions.datagen.adapters.selenium.adapter.Adapter

Class Adapter

__init__()

Class constructor

Called when object is initialized

Parameters:
  • browser (str) – browser to be used
  • timeout (str) – timeout fow wait commands
suite

suite property getter

tests

tests property getter

browser

browser property getter

timeout

timeout property getter

parse_test_suite(suite, outfile=None)

Method parses test suite file

Parameters:
  • suite (str) – suite filename
  • outfile (str) – output filename, <test suite>.jedi
Returns:

result

Return type:

bool

Raises:
  • event – adapter_before_parse_suite
  • event – adapter_after_parse_suite
parse_test(test)

Method parses test file

Parameters:

test (str) – test filename

Returns:

url (str), steps (list)

Return type:

tuple

Raises:
  • event – adapter_before_parse_test
  • event – adapter_after_parse_test
adapt_suite(suite, tests)

Method adapts suite to scenario

Parameters:
  • suite (dict) – suite
  • tests (list) – tests
Returns:

str

adapt_test(idx, test)

Method adapts test to case

Parameters:
  • idx (int) – index
  • test (dict) – test
Returns:

str

adapt_step(idx, step, url)

Method adapts step to condition

Parameters:
  • idx (int) – index
  • step (dict) – step
  • url (str) – base url
Returns:

str

handle_command(step, url)

Method handles command

Parameters:
  • step (dict) – step
  • url (str) – base url
Returns:

test (str), validate (str)

Return type:

tuple

cmd_alert(step, *args)

Method handles commands alert

Parameters:
  • step (dict) – step
  • args (args) – arguments
Returns:

test (str), validate (str)

Return type:

tuple

cmd_close(step, *args)

Method handles command close

Parameters:
  • step (dict) – step
  • args (args) – arguments
Returns:

test (str), validate (str)

Return type:

tuple

cmd_echo(step, *args)

Method handles command echo

Parameters:
  • step (dict) – step
  • args (args) – arguments
Returns:

test (str), validate (str)

Return type:

tuple

cmd_go_back(step, *args)

Method handles command goBack

Parameters:
  • step (dict) – step
  • args (args) – arguments
Returns:

test (str), validate (str)

Return type:

tuple

cmd_open(step, url, *args)

Method handles command open

Parameters:
  • step (dict) – step
  • url (str) – base url
  • args (args) – arguments
Returns:

test (str), validate (str)

Return type:

tuple

cmd_pause(step, *args)

Method handles command pause

Parameters:
  • step (dict) – step
  • args (args) – arguments
Returns:

test (str), validate (str)

Return type:

tuple

cmd_refresh(step, *args)

Method handles command goBack

Parameters:
  • step (dict) – step
  • args (args) – arguments
Returns:

test (str), validate (str)

Return type:

tuple

cmd_set(step, *args)

Method handles various commands set

Parameters:
  • step (dict) – step
  • args (args) – arguments
Returns:

test (str), validate (str)

Return type:

tuple

__weakref__

list of weak references to the object (if defined)

cmd_store(step, *args)

Method handles various commands store

Parameters:
  • step (dict) – step
  • args (args) – arguments
Returns:

test (str), validate (str)

Return type:

tuple

cmd_verify(step, *args)

Method handles various commands verify, assert

Parameters:
  • step (dict) – step
  • args (args) – arguments
Returns:

test (str), validate (str)

Return type:

tuple

cmd_wait(step, *args)

Method handles various commands wait

Parameters:
  • step (dict) – step
  • args (args) – arguments
Returns:

test (str), validate (str)

Return type:

tuple