Skip to content

Remote file format validator extension#257

Open
j796160836 wants to merge 1 commit intosvanoort:masterfrom
j796160836:johnny-validate-remote-file
Open

Remote file format validator extension#257
j796160836 wants to merge 1 commit intosvanoort:masterfrom
j796160836:johnny-validate-remote-file

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