File: util.py

package info (click to toggle)
python-pynetbox 7.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,296 kB
  • sloc: python: 4,343; makefile: 3
file content (33 lines) | stat: -rw-r--r-- 841 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import json


class Response:
    def __init__(self, fixture=None, status_code=200, ok=True, content=None):
        self.status_code = status_code
        self.content = json.dumps(content) if content else self.load_fixture(fixture)
        self.ok = ok

    def load_fixture(self, path):
        if not path:
            return "{}"
        with open("tests/fixtures/{}".format(path), "r") as f:
            return f.read()

    def json(self):
        return json.loads(self.content)


def openapi_mock():
    """Mock function to simulate Api.openapi()"""
    return {
        "paths": {
            "/api/test/test/": {
                "get": {
                    "parameters": [
                        {"name": "test"},
                        {"name": "name"},
                    ]
                },
            },
        },
    }