def test_create_fail(self): """ when the session doesn't have a get method, a ValueError should be raised """ with self.assertRaises(ValueError): fake_session = None backend = session_backend(fake_session)
def test_get_empty(self): session = MockSession("", 200) backend = session_backend(session) text = backend("http://www.empty-example.com") self.assertIsNone(text)
def test_get_not_ok(self): session = MockSession("<html></html>", 404) backend = session_backend(session) text = backend("http://www.bad-example.com") self.assertIsNone(text)
def test_get_success(self): session = MockSession("<html></html>", 200) backend = session_backend(session) text = backend("http://www.example.com") self.assertIsNotNone(text)
def test_create_success(self): session = requests.Session() get = session_backend(session) self.assertIsInstance(get, types.FunctionType)