File size: 1,369 Bytes
0163a2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import requests
import unittest
import importlib
import json
from pathlib import Path

utils = importlib.import_module("extensions.sd-webui-controlnet.tests.utils", "utils")


def render(poses):
    return requests.post(
        utils.BASE_URL + "/controlnet/render_openpose_json", json=poses
    ).json()


with open(Path(__file__).parent / "pose.json", "r") as f:
    pose = json.load(f)


with open(Path(__file__).parent / "animal_pose.json", "r") as f:
    animal_pose = json.load(f)


class TestDetectEndpointWorking(unittest.TestCase):
    def test_render_single(self):
        res = render([pose])
        self.assertEqual(res["info"], "Success")
        self.assertEqual(len(res["images"]), 1)

    def test_render_multiple(self):
        res = render([pose, pose])
        self.assertEqual(res["info"], "Success")
        self.assertEqual(len(res["images"]), 2)

    def test_render_no_pose(self):
        res = render([])
        self.assertNotEqual(res["info"], "Success")

    def test_render_invalid_pose(self):
        res = render([{"foo": 10, "bar": 100}])
        self.assertNotIn("info", res)
        self.assertNotIn("images", res)

    def test_render_animals(self):
        res = render([animal_pose])
        self.assertEqual(res["info"], "Success")
        self.assertEqual(len(res["images"]), 1)


if __name__ == "__main__":
    unittest.main()