def test_request_critical_css(self, requests_get_mock, settings): class ResponseMock: status_code = 200 text = 'foo' url = 'http://foo.bar.com' def raise_for_status(self): return False settings.PENTHOUSE_URL = 'http://foobar:3000/' settings.PENTHOUSE_CONFIG = {} settings.SESSION_COOKIE_SECURE = False site = Site.objects.create(domain='test.com') settings.SITE_ID = site.id requests_get_mock.return_value = ResponseMock() api = PenthouseApi() api.request_critical_css('/foo', 'css/test.css') requests_get_mock.assert_called_once_with( 'http://foobar:3000/', { 'url': 'http://test.com/foo', 'css': 'http://test.com/css/test.css' }, )
def test_request_critical_css_raises(self, requests_get_mock, settings): settings.PENTHOUSE_URL = 'http://foobar:3000/' settings.SESSION_COOKIE_SECURE = False site = Site.objects.create(domain='test.com') settings.SITE_ID = site.id requests_get_mock.side_effect = requests.RequestException() api = PenthouseApi() with pytest.raises(PenthouseException): api.request_critical_css('/foo', 'css/test.css')
def test_request_critical_css_raises_invalid_status( self, requests_get_mock): class ResponseMock: status_code = 401 text = 'foo' url = 'http://foo.bar.com' def raise_for_status(self): return False requests_get_mock.return_value = ResponseMock() api = PenthouseApi() with pytest.raises(PenthouseException): api.request_critical_css('/foo', 'css/test.css')