class AuthorisationDetailViewTests(unittest.TestCase): def setUp(self): self.client = TestClient(router) self.device = Device.create(apns_token='ec1752bd70320e4763f7165d73e2636cca9e25cf') self.token = Token.create(device=self.device, token='e4763f7165d73e2636cca9e', scope=Token.ALL_SCOPE) def tearDown(self): if self.token: self.token.delete_instance() self.device.delete_instance() def test_get(self): headers = { 'AUTHORIZATION': 'token e4763f7165d73e2636cca9e' } response = self.client.get('/authorisations/636cca9e', {}, headers) self.assertEqual(response.status_code, 200) self.assertEqual(json.loads(response.content), { 'url': '/authorisations/636cca9e', 'scopes': ['all'], 'token_last_eight': '636cca9e' }) def test_delete(self): headers = { 'AUTHORIZATION': 'token e4763f7165d73e2636cca9e' } response = self.client.delete('/authorisations/636cca9e', {}, headers) self.assertEqual(response.status_code, 204) self.assertEqual(Token.select().count(), 0) self.token = None
class TestClientTests(unittest.TestCase): def setUp(self): def view(request): return Response('{} {}'.format(request.method, request.path)) self.client = TestClient(view) def test_http(self): response = self.client.http('METHOD', '/path/') self.assertEqual(response.content, 'METHOD /path/') def test_get(self): response = self.client.get('/') self.assertEqual(response.content, 'GET /') def test_put(self): response = self.client.put('/') self.assertEqual(response.content, 'PUT /') def test_post(self): response = self.client.post('/') self.assertEqual(response.content, 'POST /') def test_delete(self): response = self.client.delete('/resource') self.assertEqual(response.content, 'DELETE /resource')