Projet

Général

Profil

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

Nicolas Roche, 25 janvier 2020 19:45

Télécharger (1,21 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

  
......
25 26

  
26 27

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

  
36
    @property
37
    def text(self):
38
        return force_text(self.content)
28 39

  
29 40
    def json(self):
30 41
        return json.loads(self.content)
31
-