File: unittest_example.py

package info (click to toggle)
python-pook 2.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 672 kB
  • sloc: python: 3,558; makefile: 13
file content (29 lines) | stat: -rw-r--r-- 781 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
import unittest

import requests

import pook


class TestUnitTestEngine(unittest.TestCase):
    @pook.on
    def test_request(self):
        pook.get("server.com/foo").reply(204)
        res = requests.get("http://server.com/foo")
        self.assertEqual(res.status_code, 204)

    def test_request_with_context_manager(self):
        with pook.use():
            pook.get("server.com/bar", reply=204)
            res = requests.get("http://server.com/bar")
            self.assertEqual(res.status_code, 204)

    @pook.on
    def test_no_match_exception(self):
        pook.get("server.com/bar", reply=204)
        try:
            requests.get("http://server.com/baz")
        except Exception:
            pass
        else:
            raise RuntimeError("expected to fail")