Projet

Général

Profil

0001-tests-add-a-text-property-on-FakedResponse-38865.patch

Nicolas Roche, 29 janvier 2020 15:12

Télécharger (1,25 ko)

Voir les différences:

Subject: [PATCH 1/2] tests: add a text property on FakedResponse (#38865)

 tests/utils.py | 11 +++++++++++
 1 file changed, 11 insertions(+)
tests/utils.py
6 6
from django.contrib.contenttypes.models import ContentType
7 7
from django.core.urlresolvers import reverse
8 8
from django.utils.six.moves.urllib import parse as urlparse
9
from django.utils.encoding import force_bytes, force_text
9 10

  
10 11
from passerelle.base.models import ApiUser, AccessRight
11 12
from passerelle.compat import json_loads
......
26 27

  
27 28

  
28 29
class FakedResponse(mock.Mock):
30
    def __init__(self, text=None, content=None, **kwargs):
31
        super(FakedResponse, self).__init__(**kwargs)
32
        if content is not None:
33
            self.content = content
34
        elif text is not None:
35
            self.content = force_bytes(text)
36

  
37
    @property
38
    def text(self):
39
        return force_text(self.content)
29 40

  
30 41
    def json(self):
31 42
        return json_loads(self.content)
32
-