Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote file format validator extension #257

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

j796160836
Copy link

Remote file format validator

Fetch the target value url and determine it's file format.

It has two functions:

  1. Detect file type with pre-defined types.
  2. Determine file type strings contatins specific keyword.

Installation

This extension needs python-magic to work

Use this Command to install

$pip install python-magic

On Mac OSX need libmagic

brew install libmagic

Usage

Use remote_file_format with test or contains keyword to validate the JSON format.

Example: Given this JSON:

[
  {
    "name": "track1",
    "audio_url": "http://path/to/mp3.mp3"
  }
]

We can do a test case for like this

- test:
    - name: "audio-list"
    - url: "/my-audio-list"
    - method: "GET"
    - validators:
        - compare: {jsonpath_mini: "0.name", comparator: "type", expected: "string"}
        - compare: {jsonpath_mini: "0.audio_url", comparator: "type", expected: "string"}
        - remote_file_format: {jsonpath_mini: '0.audio_url', test: 'is_mp3'}
        - remote_file_format: {jsonpath_mini: '0.audio_url', contains: 'Audio'}

Finaily, don't forget to add --import_extensions arguments when excute the test, enjoy!

$ resttest.py https://my.domain/ test.yaml --import_extensions 'remote_file_format_validator'

@svanoort-jenkins
Copy link
Collaborator

Can one of the admins verify this patch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants