| Conditions | 1 |
| Total Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
| 20 | @pytest.fixture |
||
| 21 | def client(): |
||
| 22 | '''Overrides default client fixture adding a mocked |
||
| 23 | up login method and a json() helper |
||
| 24 | ''' |
||
| 25 | from django.test.client import Client |
||
| 26 | |||
| 27 | class _Client(Client): |
||
| 28 | def login( |
||
| 29 | self, user=None, |
||
| 30 | backend="django.contrib.auth.backends.ModelBackend", |
||
| 31 | **credentials): |
||
| 32 | if user is None: |
||
| 33 | return super(_Client, self).login(**credentials) |
||
| 34 | |||
| 35 | with mock.patch('django.contrib.auth.authenticate') as authenticate: |
||
| 36 | user.backend = backend |
||
| 37 | authenticate.return_value = user |
||
| 38 | return super(_Client, self).login(**credentials) |
||
| 39 | |||
| 40 | @property |
||
| 41 | def json(self): |
||
| 42 | return PartialMethodCaller( |
||
| 43 | obj=self, content_type='application/json;charset="utf-8"') |
||
| 44 | |||
| 45 | return _Client() |
||
| 46 | |||
| 58 |