vendredi 9 août 2019

How to distribute the code across the files in radish testing framework?

I'm using the radish-bdd frame work to write the test case. There are some cases where is it generalized like triggering curl command given the URL. But i have some use cases where it is specific to one service.

There are two python files. steps.py

# -*- coding: utf-8 -*-
import re
from radish import given, when, then

@when(re.compile(r"Curl is called with url (.*) form (.*)"))
def form_url_is_invoked(step, url, form):
    print("The data receoved from the type pod {} {}".format(form,url))
    form_string = ""
    lists = form.split("&")
    for i in lists:
        form_string = form_string + (" \"-F\" \"{}\"".format(i))
    import os
    s = os.system('curl {} {}'.format(form_string, url))
    print("Response",s)
    print("")

@when(re.compile(r"Curl is called with url (.*) body (.*) header (.*) type (.*)"))
def url_is_invoked(step, url, body, header, type):
    import os
    print("The data receoved from the type pod {} {} {} ".format(body,url, type))
    header = header if header else "Content-Type: application/json"
    string_f = "curl -H \"{}\" -X {} -d {} {}".format(header,type,body,url)
    s = os.system('{}'.format(string_f))
    print(s)
    print("")

This is generalized file.

cellplan.py

import re
from radish import given, when, then

@when(re.compile(r"Cellplan is triggered with (.*) file (.*) at path given url (.*)"))
def form_url_is_invoked(step, filename, path, url):
    form  = "destination=CELLPLAN&files=@{}/{}".format(path,filename)
    print("Print",form)
    step.form_url_is_invoked(url,form)

In the feature file i would have like

@FUNCTIONAL
Feature: Test CCTF scripts for functional
    In order to trigger cellplan.
    Scenario I trigger cellplan


    @ID_CSFLCMTST202
    @FID_CSFID002
    Scenario: First functional Scenario 3
      When Cellplan is triggered with Range_Validation_Azimuth.csv file /root/gokul at path given url http://cellccttf-cell-antenna-parser.default.svc.cluster.local:9600/plan/update

When the test cases are executed, cellplan.py is called i would like to know to can we call the functions from steps.py so there is maximum re-use of the code?

Aucun commentaire:

Enregistrer un commentaire