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
Raises:ValueError
path

path property getter

compile(spec)

Method compiles ASN.1 specification for validation

Parameters:

spec (str) – specification filename

Returns:

result

Return type:

bool

Raises:
  • event – asn1_before_compile
  • event – asn1_after_compile
decode(spec, element, input, iformat='ber', output=None)

Method decodes ASN.1 file to readable GSER format

Parameters:
  • spec (str) – specification filename
  • element (str) – element title
  • input (str) – input filename
  • iformat (str) – input format ber|der|oer|aper|uper|xer
  • output (str) – output filename
Returns:

result

Return type:

bool

Raises:
  • event – asn1_before_decode
  • event – asn1_after_decode
__weakref__

list of weak references to the object (if defined)

encode(spec, element, input, oformat='ber', output=None)

Method encodes ASN.1 file from readable GSER format

Parameters:
  • spec (str) – specification filename
  • element (str) – element title
  • input (str) – input filename
  • oformat (str) – output format ber|der|oer|aper|uper|xer
  • output (str) – output filename
Returns:

result

Return type:

bool

Raises:
  • event – asn1_before_encode
  • event – asn1_after_encode
transcode(spec, element, input, iformat, oformat, output=None)

Method transcodes ASN.1 file to different format

Parameters:
  • spec (str) – specification filename
  • element (str) – element title
  • input (str) – input filename
  • iformat (str) – input format ber|der|oer|aper|uper|xer|gser
  • oformat (str) – output format ber|der|oer|aper|uper|xer|gser
  • output (str) – output filename
Returns:

result

Return type:

bool

Raises:
  • event – asn1_before_transcode
  • event – asn1_after_transcode

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