File: helpers.py

package info (click to toggle)
python-homematicip 1.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,796 kB
  • sloc: python: 15,164; makefile: 17; sh: 4
file content (28 lines) | stat: -rw-r--r-- 678 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
import json


class FakeResponse:
    def __init__(self, status=200, body={}, content_type="application/json"):
        self.status = status
        self.body = body
        self.content_type = content_type

    async def json(self):
        return json.dumps(self.body)

    async def release(self):
        pass


def mockreturn(
    return_status=None, return_body={}, content_type="application/json", exception=None
):
    async def mocked(path, data, headers):
        if exception:
            raise exception
        else:
            return FakeResponse(
                status=return_status, body=return_body, content_type=content_type
            )

    return mocked