File: utilities.py

package info (click to toggle)
pysmartapp 0.3.5-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 360 kB
  • sloc: python: 1,358; makefile: 3
file content (20 lines) | stat: -rw-r--r-- 553 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"""Testing utilities."""
import json


def get_fixture(file: str, ext: str = 'json'):
    """Load a fixtures file."""
    file_name = F"tests/fixtures/{file}.{ext}"
    with open(file_name, encoding="utf-8") as open_file:
        if ext == 'json':
            return json.load(open_file)
        return open_file.read()


def get_dispatch_handler(smartapp):
    """Get a handler to mock in the dispatcher."""
    async def handler(req, resp, app):
        handler.fired = True
        assert app == smartapp
    handler.fired = False
    return handler