def test_has_permission_valid_key(self): class DummyClass(object): pass view = DummyClass() timestamp = now() user = UserFactory.create() app = APIv2AppFactory.create(owner=user.userprofile) request_factory = RequestFactory() request = request_factory.get('/', data={'api-key': app.key}) request.user = AnonymousUser() mozillians_permission = MozilliansPermission() with patch('mozillians.api.v2.permissions.now') as now_mock: now_mock.return_value = timestamp with patch('mozillians.api.v2.permissions.statsd.incr') as incr_mock: ok_(mozillians_permission.has_permission(request, view)) incr_mock.assert_has_calls([ call('apiv2.auth.success'), call('apiv2.requests.app.{0}'.format(app.id)), call('apiv2.requests.total'), call('apiv2.resources.DummyClass') ]) ok_(APIv2App.objects.filter(id=app.id, last_used=timestamp).exists())
def test_delete_apikey_invalid(self): user = UserFactory.create() key_owner = UserFactory.create() api_key = APIv2AppFactory.create(owner=key_owner.userprofile) with self.login(user) as client: url = reverse('phonebook:apikey_delete', kwargs={'api_pk': api_key.pk}) response = client.get(url, follow=True) eq_(response.status_code, 404)
def test_delete_apikey_valid(self, success_mock): key_owner = UserFactory.create() api_key = APIv2AppFactory.create(owner=key_owner.userprofile) with self.login(key_owner) as client: url = reverse('phonebook:apikey_delete', kwargs={'api_pk': api_key.pk}) response = client.get(url, follow=True) ok_(success_mock.called) eq_(response.status_code, 200) self.assertTemplateUsed(response, 'phonebook/apikeys.html')
def test_delete_apikey_valid(self, success_mock): key_owner = UserFactory.create() api_key = APIv2AppFactory.create(owner=key_owner.userprofile) with self.login(key_owner) as client: url = reverse('phonebook:apikey_delete', kwargs={'api_pk': api_key.pk}) response = client.get(url, follow=True) ok_(success_mock.called) eq_(response.status_code, 200) self.assertJinja2TemplateUsed(response, 'phonebook/apikeys.html')
def test_has_permission_assigned_key(self): class DummyClass(object): pass view = DummyClass() request_factory = RequestFactory() request = request_factory.get('/') user = UserFactory.create() app = APIv2AppFactory.create(owner=user.userprofile) timestamp = now() request.user = user mozillians_permission = MozilliansPermission() with patch('mozillians.api.v2.permissions.now') as now_mock: now_mock.return_value = timestamp ok_(mozillians_permission.has_permission(request, view)) ok_(APIv2App.objects.filter(id=app.id, last_used=timestamp).exists())