File: test_decorator.py

package info (click to toggle)
python-httpretty 0.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 620 kB
  • ctags: 690
  • sloc: python: 2,842; makefile: 60
file content (48 lines) | stat: -rw-r--r-- 1,071 bytes parent folder | download | duplicates (3)
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
# coding: utf-8
from unittest import TestCase
from sure import expect
from httpretty import httprettified, HTTPretty

try:
    import urllib.request as urllib2
except ImportError:
    import urllib2


@httprettified
def test_decor():
    HTTPretty.register_uri(
        HTTPretty.GET, "http://localhost/",
        body="glub glub")

    fd = urllib2.urlopen('http://localhost/')
    got1 = fd.read()
    fd.close()

    expect(got1).to.equal(b'glub glub')


@httprettified
class ClassDecorator(TestCase):

    def test_decorated(self):
        HTTPretty.register_uri(
            HTTPretty.GET, "http://localhost/",
            body="glub glub")

        fd = urllib2.urlopen('http://localhost/')
        got1 = fd.read()
        fd.close()

        expect(got1).to.equal(b'glub glub')

    def test_decorated2(self):
        HTTPretty.register_uri(
            HTTPretty.GET, "http://localhost/",
            body="buble buble")

        fd = urllib2.urlopen('http://localhost/')
        got1 = fd.read()
        fd.close()

        expect(got1).to.equal(b'buble buble')