Giter Club home page Giter Club logo

Comments (14)

Birne94 avatar Birne94 commented on May 18, 2024 2

Have a look at the type conversions section of the docs.

You can use the !int operator (note the single !) here:

owner-id: !int "{owner-id:d}"

from tavern.

BusinessFawn avatar BusinessFawn commented on May 18, 2024

Hey Birne94,

Thank you so much for taking a look!

I forgot to include that scenario. Here is the output produced:

Traceback (most recent call last):
  File "C:/Users/businessFawn/Documents/bf-soup/62-partyTownCollection/Regression/get_after_post_with_config/run_test.py", line 59, in <module>
    regression_test_collection_get()
  File "C:/Users/businessFawn/Documents/bf-soup/62-partyTownCollection/Regression/get_after_post_with_config/run_test.py", line 35, in regression_test_collection_get
    run_tavern_test('yaml_files/test_collection_get.yaml', 'test API collections GET')
  File "C:/Users/businessFawn/Documents/bf-soup/62-partyTownCollection/Regression/get_after_post_with_config/run_test.py", line 27, in run_tavern_test
    success = run(test_file_path, '')
  File "C:\Users\businessFawn\Documents\bf-soup\Regression_62-partyTownCollection\lib\site-packages\tavern\core.py", line 148, in run
    for test_spec in yaml.load_all(infile, Loader=IncludeLoader):
  File "C:\Users\businessFawn\Documents\bf-soup\Regression_62-partyTownCollection\lib\site-packages\yaml\__init__.py", line 84, in load_all
    yield loader.get_data()
  File "C:\Users\businessFawn\Documents\bf-soup\Regression_62-partyTownCollection\lib\site-packages\yaml\constructor.py", line 31, in get_data
    return self.construct_document(self.get_node())
  File "C:\Users\businessFawn\Documents\bf-soup\Regression_62-partyTownCollection\lib\site-packages\yaml\constructor.py", line 46, in construct_document
    for dummy in generator:
  File "C:\Users\businessFawn\Documents\bf-soup\Regression_62-partyTownCollection\lib\site-packages\yaml\constructor.py", line 398, in construct_yaml_map
    value = self.construct_mapping(node)
  File "C:\Users\businessFawn\Documents\bf-soup\Regression_62-partyTownCollection\lib\site-packages\yaml\constructor.py", line 204, in construct_mapping
    return super().construct_mapping(node, deep=deep)
  File "C:\Users\businessFawn\Documents\bf-soup\Regression_62-partyTownCollection\lib\site-packages\yaml\constructor.py", line 129, in construct_mapping
    value = self.construct_object(value_node, deep=deep)
  File "C:\Users\businessFawn\Documents\bf-soup\Regression_62-partyTownCollection\lib\site-packages\yaml\constructor.py", line 86, in construct_object
    data = constructor(self, node)
  File "C:\Users\businessFawn\Documents\bf-soup\Regression_62-partyTownCollection\lib\site-packages\yaml\constructor.py", line 414, in construct_undefined
    node.start_mark)
yaml.constructor.ConstructorError: could not determine a constructor for the tag '!int'
  in "yaml_files/test_collection_get.yaml", line 26, column 29

If I'm doing something outside the expected please let me know or if there is any config information I can pass over to get this figured out.

Thanks!

from tavern.

Birne94 avatar Birne94 commented on May 18, 2024

Which version of tavern are you using? The feature was just added in a recent release. Try upgrading the package.

pip install --upgrade tavern should do it, if I am not mistaken.

from tavern.

BusinessFawn avatar BusinessFawn commented on May 18, 2024

You're absolutely right. That is my mistake. I was using the most recent version on Pypi, which at the time was 0.5.4. I have updated to 0.7.1 and casting is working as expected! I apologize for being behind!

Thanks!

from tavern.

BusinessFawn avatar BusinessFawn commented on May 18, 2024

Hello kind folk at Tavern!

It seems like there has been a resurgence in the issue of casting ints using the "!int '{value:d}'" syntax. This is running version tavern-0.9.2 (which is also available in the logs).

Might you all know why this is happening again? Something to note, is in test_regression_get_collection.tavern.yaml this line:
collection-url: "/collections/{createdCollectionID:d}"
works without issue, however,
collection-id: !int '{createdCollectionID:d}'
receives an error

Thanks!

Files:
test_regression_get_collection.tavern.yaml:

includes:
  - !include CollectionConfig/config.yaml

test_name: Perform a get on collection- 200
stages:
  - name: Get on collection
    request:
      url: "{baseURL:s}/{createdCollectionID:d}"
      method: GET
      headers:
        content-type: application/json
        x-api-key: "{x-api-key:s}"
    response:
      status_code: 200
      body:
        collection-properties:
          collection-id: !int '{createdCollectionID:d}'
          collection-url: "/collections/{createdCollectionID:d}"

name: config.yaml
description: Collection constants.

variables:
  baseURL: example.com
  x-api-key: lololol
  createdCollectionID: 1

Testing started at 12:38 ...
C:\venv\62-partytown-Regression\Scripts\python.exe C:\Users\bf.IdeaIC2018.1\config\plugins\python-ce\helpers\pycharm_jb_pytest_runner.py --path C:/Users/bf/Documents/somewhere/IndividualRepos/62-partytown-Regression/Source/TestCases/test_regression_get_collection.tavern.yaml
Launching py.test with arguments C:/Users/bf/Documents/somewhere/IndividualRepos/62-partytown-Regression/Source/TestCases/test_regression_get_collection.tavern.yaml in C:\Users\bf\Documents\somewhere\IndividualRepos\62-partytown-Regression\Source\TestCases

============================= test session starts =============================
platform win32 -- Python 3.6.4, pytest-3.5.0, py-1.5.3, pluggy-0.6.0
rootdir: C:\Users\bf\Documents\somewhere\IndividualRepos\62-partytown-Regression\Source\TestCases, inifile:
plugins: tavern-0.9.2
test_regression_get_collection.tavern.yaml:None (test_regression_get_collection.tavern.yaml)
C:\venv\62-partytown-Regression\lib\site-packages\tavern\testutils\pytesthook.py:74: in collect
all_tests = list(yaml.load_all(self.fspath.open(), Loader=IncludeLoader))
C:\venv\62-partytown-Regression\lib\site-packages\yaml_init_.py:84: in load_all
yield loader.get_data()
C:\venv\62-partytown-Regression\lib\site-packages\yaml\constructor.py:31: in get_data
return self.construct_document(self.get_node())
C:\venv\62-partytown-Regression\lib\site-packages\yaml\constructor.py:46: in construct_document
for dummy in generator:
C:\venv\62-partytown-Regression\lib\site-packages\yaml\constructor.py:398: in construct_yaml_map
value = self.construct_mapping(node)
C:\venv\62-partytown-Regression\lib\site-packages\yaml\constructor.py:204: in construct_mapping
return super().construct_mapping(node, deep=deep)
C:\venv\62-partytown-Regression\lib\site-packages\yaml\constructor.py:129: in construct_mapping
value = self.construct_object(value_node, deep=deep)
C:\venv\62-partytown-Regression\lib\site-packages\yaml\constructor.py:86: in construct_object
data = constructor(self, node)
C:\venv\62-partytown-Regression\lib\site-packages\yaml\constructor.py:414: in construct_undefined
node.start_mark)
E yaml.constructor.ConstructorError: could not determine a constructor for the tag '!int'
E in "C:\Users\bf\Documents\somewhere\IndividualRepos\62-partytown-Regression\Source\TestCases\test_regression_get_collection.tavern.yaml", line 24, column 26
collected 0 items / 1 errors

=================================== ERRORS ====================================
_________ ERROR collecting test_regression_get_collection.tavern.yaml _________
C:\venv\62-partytown-Regression\lib\site-packages\tavern\testutils\pytesthook.py:74: in collect
all_tests = list(yaml.load_all(self.fspath.open(), Loader=IncludeLoader))
C:\venv\62-partytown-Regression\lib\site-packages\yaml_init_.py:84: in load_all
yield loader.get_data()
C:\venv\62-partytown-Regression\lib\site-packages\yaml\constructor.py:31: in get_data
return self.construct_document(self.get_node())
C:\venv\62-partytown-Regression\lib\site-packages\yaml\constructor.py:46: in construct_document
for dummy in generator:
C:\venv\62-partytown-Regression\lib\site-packages\yaml\constructor.py:398: in construct_yaml_map
value = self.construct_mapping(node)
C:\venv\62-partytown-Regression\lib\site-packages\yaml\constructor.py:204: in construct_mapping
return super().construct_mapping(node, deep=deep)
C:\venv\62-partytown-Regression\lib\site-packages\yaml\constructor.py:129: in construct_mapping
value = self.construct_object(value_node, deep=deep)
C:\venv\62-partytown-Regression\lib\site-packages\yaml\constructor.py:86: in construct_object
data = constructor(self, node)
C:\venv\62-partytown-Regression\lib\site-packages\yaml\constructor.py:414: in construct_undefined
node.start_mark)
E yaml.constructor.ConstructorError: could not determine a constructor for the tag '!int'
E in "C:\Users\bf\Documents\somewhere\IndividualRepos\62-partytown-Regression\Source\TestCases\test_regression_get_collection.tavern.yaml", line 24, column 26
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.24 seconds ===========================

from tavern.

rooty123 avatar rooty123 commented on May 18, 2024

Hi,
I have the same issue with 0.9.3 version:
yaml.constructor.ConstructorError: could not determine a constructor for the tag '!int'
in "leads.yaml", line 82, column 24

from tavern.

rooty123 avatar rooty123 commented on May 18, 2024

After upgrading to 0.9.4 now I get different error:

request:
revision_id: !int "{revision_id:d}"

ValueError: invalid literal for int() with base 10: '{revision_id:d}'

revision_id is variable saved from previous response

from tavern.

michaelboulton avatar michaelboulton commented on May 18, 2024

There was an error with the type conversions that should be fixed in 0.9.5 (whenever it gets release on Travis), but I'm not sure what you mean when you say it was saved from the previous response - could you give an example of what you're trying to do?

from tavern.

rooty123 avatar rooty123 commented on May 18, 2024

I mean I use multistage testing, and saved values like this:

save:
        body:
          revision_id: id

from tavern.

michaelboulton avatar michaelboulton commented on May 18, 2024

Ah, sorry I completely misread you. I think this is the same issue as #85, I've left a comment there explaining that you need to convert the value when you use it in a subsequent test

from tavern.

rooty123 avatar rooty123 commented on May 18, 2024

Even with version 0.9.5 I get the same error:

Traceback (most recent call last):
  File "/usr/local/bin/tavern-ci", line 11, in <module>
    load_entry_point('tavern==0.9.5', 'console_scripts', 'tavern-ci')()
  File "/usr/local/lib/python2.7/dist-packages/tavern/entry.py", line 112, in main
    exit(not run(**vargs))
  File "/usr/local/lib/python2.7/dist-packages/tavern/core.py", line 168, in run
    run_test(in_file, test_spec, global_cfg)
  File "/usr/local/lib/python2.7/dist-packages/tavern/core.py", line 85, in run_test
    r = get_request_type(stage, test_block_config, sessions)
  File "/usr/local/lib/python2.7/dist-packages/tavern/plugins.py", line 82, in get_request_type
    r = RestRequest(session, rspec, test_block_config)
  File "/usr/local/lib/python2.7/dist-packages/tavern/request/rest.py", line 166, in __init__
    request_args = get_request_args(rspec, test_block_config)
  File "/usr/local/lib/python2.7/dist-packages/tavern/request/rest.py", line 75, in get_request_args
    fspec = format_keys(rspec, test_block_config["variables"])
  File "/usr/local/lib/python2.7/dist-packages/tavern/util/dict_util.py", line 31, in format_keys
    formatted[key] = format_keys(val[key], variables)
  File "/usr/local/lib/python2.7/dist-packages/tavern/util/dict_util.py", line 31, in format_keys
    formatted[key] = format_keys(val[key], variables)
  File "/usr/local/lib/python2.7/dist-packages/tavern/util/dict_util.py", line 31, in format_keys
    formatted[key] = format_keys(val[key], variables)
  File "/usr/local/lib/python2.7/dist-packages/tavern/util/dict_util.py", line 42, in format_keys
    formatted = val.constructor(value)
ValueError: invalid literal for int() with base 10: '{revision_id:d}'

from tavern.

michaelboulton avatar michaelboulton commented on May 18, 2024

There is a test for saving and converting types here: https://github.com/taverntesting/tavern/blob/master/tests/integration/test_typetokens.tavern.yaml#L308-L336

I think I need to see more of your code before figuring out why it's not working

from tavern.

rooty123 avatar rooty123 commented on May 18, 2024

My test:

- name: Get Quiz to acquire revision_id
    request:
      url: "{protocol:s}://{host:s}:{port:d}/rpc"
      json:
        service: "go.micro.srv.quiz"
        method: "Quiz.GetQuiz"
        request:
          hash: "{unique_hash:s}"
      method: POST
      headers:
        content-type: application/json
    response:
      status_code: 200
      body:
        state: "published"
      headers:
        content-type: application/json
      save:
        body:
          revision_id: revision_id

- name: Create Completed Lead
    request:
      url: "{protocol:s}://{host:s}:{port:d}/rpc"
      json:
        service: "go.micro.srv.leads"
        method: "Leads.SaveLead"
        request:
          state: "new"
          revision_id: !int "{revision_id:d}"   <- fails here
        method: POST
      headers:
        content-type: application/json
        Authorization: "{test_login_token:s}"
    response:
      status_code: 200
      body:
        {}
      headers:
        content-type: application/json
      save:
        body:
          lead_id: id

from tavern.

GowthamX avatar GowthamX commented on May 18, 2024

Hi,
can we save a header returned in a response into a common.yml file or any other file which i can reuse in different test?
Declaring variable within test works, but since within test different test names are not reported in html reports.

from tavern.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.