def test_all_ok(self, requests_mock): post_mock = MagicMock(status_code=200, cookies={'sessionid': 42, 'csrftoken': 43}) requests_mock.post = MagicMock(return_value=post_mock) ResAuth.__init__(self.auth_mock, username='******', password='******', url='www.abc.com') self.assertEqual(self.auth_mock.sessionid, 42) self.assertEqual(self.auth_mock.csrftoken, 43)
def test_public_user(self, requests_mock): post_mock = MagicMock(status_code=200) requests_mock.post = MagicMock(return_value=post_mock) ResAuth.__init__(self.auth_mock, url='www.abc.com') self.assertEqual(self.auth_mock.sessionid, None) self.assertEqual(self.auth_mock.csrftoken, None)
def test_all_ok(self, requests_mock): post_mock = MagicMock(status_code=200, cookies={'sessionid': 42, 'csrftoken': 43}) requests_mock.post = MagicMock(return_value=post_mock) ResAuth.__init__(self.auth_mock, username='******', password='******', url='www.abc.com') self.assertEqual(self.auth_mock.sessionid, 42) self.assertEqual(self.auth_mock.csrftoken, 43)
def test_no_csrf_token(self, requests_mock): post_mock = MagicMock(status_code=200, cookies={'sessionid': 42}) requests_mock.post = MagicMock(return_value=post_mock) message = 'Missing sessionid or csrftoken. Invalid credentials?' with six.assertRaisesRegex(self, Exception, message): ResAuth.__init__(self.auth_mock, username='******', password='******', url='www.abc.com')
def test_no_csrf_token(self, requests_mock): magic_mock1 = MagicMock(status_code=200, cookies={'sessionid': 42}) requests_mock.post = MagicMock(return_value=magic_mock1) message = 'Missing sessionid or csrftoken. Invalid credentials?' with six.assertRaisesRegex(self, Exception, message): ResAuth.__init__(self.auth_mock, email='a', password='******', url='www.abc.com')
def test_public_user(self, requests_mock): post_mock = MagicMock(status_code=200) requests_mock.post = MagicMock(return_value=post_mock) ResAuth.__init__(self.auth_mock, url='www.abc.com') self.assertEqual(self.auth_mock.sessionid, None) self.assertEqual(self.auth_mock.csrftoken, None)
def test_bad_credentials(self, requests_mock): requests_mock.post = MagicMock(return_value=MagicMock(status_code=400)) message = r"Response HTTP status code .* Invalid credentials?" with self.assertRaisesRegex(ValueError, message): ResAuth.__init__( self.auth_mock, username="******", password="******", url="www.abc.com" )
def test_bad_url(self, requests_post_mock): requests_post_mock.side_effect = requests.exceptions.ConnectionError() with self.assertRaisesRegex( ValueError, "Server not accessible on www.abc.com. Wrong url?" ): ResAuth.__init__( self.auth_mock, username="******", password="******", url="www.abc.com" )
def test_bad_credentials(self, requests_mock): requests_mock.post = MagicMock(return_value=MagicMock(status_code=400)) message = r'Response HTTP status code .* Invalid credentials?' with six.assertRaisesRegex(self, ValueError, message): ResAuth.__init__(self.auth_mock, username='******', password='******', url='www.abc.com')
def test_no_csrf_token(self, requests_mock): post_mock = MagicMock(status_code=200, cookies={"sessionid": 42}) requests_mock.post = MagicMock(return_value=post_mock) message = "Missing sessionid or csrftoken. Invalid credentials?" with self.assertRaisesRegex(Exception, message): ResAuth.__init__( self.auth_mock, username="******", password="******", url="www.abc.com" )
def test_all_ok(self, requests_mock): post_mock = MagicMock( status_code=200, cookies={"sessionid": 42, "csrftoken": 43} ) requests_mock.post = MagicMock(return_value=post_mock) ResAuth.__init__( self.auth_mock, username="******", password="******", url="www.abc.com" ) self.assertEqual(self.auth_mock.sessionid, 42) self.assertEqual(self.auth_mock.csrftoken, 43)
def test_bad_url(self, requests_mock): requests_mock.post = MagicMock( side_effect=[requests.exceptions.ConnectionError()]) with six.assertRaisesRegex( self, ValueError, 'Server not accessible on www.abc.com. Wrong url?'): ResAuth.__init__(self.auth_mock, username='******', password='******', url='www.abc.com')
def test_call(self): res_auth = MagicMock(spec=ResAuth, sessionid=None, csrftoken=None, url="www.abc.com") resp = ResAuth.__call__(res_auth, MagicMock(headers={})) self.assertDictEqual(resp.headers, {'referer': 'www.abc.com'}) res_auth = MagicMock(spec=ResAuth, sessionid='my-id', csrftoken='my-token', url="abc.com") resp = ResAuth.__call__(res_auth, MagicMock(headers={})) self.assertDictEqual(resp.headers, { 'X-CSRFToken': 'my-token', 'referer': 'abc.com', 'Cookie': 'csrftoken=my-token; sessionid=my-id' })
def test_call(self): res_auth = MagicMock(spec=ResAuth, sessionid=None, csrftoken=None, url="www.abc.com") resp = ResAuth.__call__(res_auth, MagicMock(headers={})) self.assertDictEqual(resp.headers, {'referer': 'www.abc.com'}) res_auth = MagicMock(spec=ResAuth, sessionid='my-id', csrftoken='my-token', url="abc.com") resp = ResAuth.__call__(res_auth, MagicMock(headers={})) self.assertDictEqual(resp.headers, { 'X-CSRFToken': 'my-token', 'referer': 'abc.com', 'Cookie': 'csrftoken=my-token; sessionid=my-id' })
def test_call(self): res_auth = MagicMock( spec=ResAuth, sessionid=None, csrftoken=None, url="www.abc.com" ) resp = ResAuth.__call__(res_auth, MagicMock(headers={})) self.assertDictEqual(resp.headers, {"referer": "www.abc.com"}) res_auth = MagicMock( spec=ResAuth, sessionid="my-id", csrftoken="my-token", url="abc.com" ) resp = ResAuth.__call__(res_auth, MagicMock(headers={})) self.assertDictEqual( resp.headers, {"X-CSRFToken": "my-token", "referer": "abc.com"}, )
def test_res_auth(self, resolwe_mock, auth_mock, requests_mock): # Wrong URL: requests_mock.post = MagicMock(side_effect=[requests.exceptions.ConnectionError()]) with self.assertRaises(Exception) as exc: ResAuth.__init__(auth_mock, email='a', password='******', url='www.abc.com') self.assertRegex(exc.exception.args[0], r"Server not accessible on .*.") # pylint: disable=deprecated-method # Wrong credentials: magic_mock1 = MagicMock(status_code=400) requests_mock.post = MagicMock(return_value=magic_mock1) with self.assertRaises(Exception) as exc: ResAuth.__init__(auth_mock, email='a', password='******', url='www.abc.com') msg = r'Response HTTP status code .* Invalid credentials?' self.assertRegex(exc.exception.args[0], msg) # pylint: disable=deprecated-method # NO CSRF token: magic_mock1 = MagicMock(status_code=200, cookies={'sessionid': 42}) requests_mock.post = MagicMock(return_value=magic_mock1) with self.assertRaises(Exception) as exc: ResAuth.__init__(auth_mock, email='a', password='******', url='www.abc.com') msg = 'Missing sessionid or csrftoken. Invalid credentials?' self.assertRegex(exc.exception.args[0], msg) # pylint: disable=deprecated-method
def test_call(self): res_auth = MagicMock(spec=ResAuth, sessionid="", csrftoken="") ResAuth.__call__(res_auth, MagicMock(headers={}))
def test_all_ok(self, requests_mock): magic_mock1 = MagicMock(status_code=200, cookies={'sessionid': 42, 'csrftoken': 42}) requests_mock.post = MagicMock(return_value=magic_mock1) ResAuth.__init__(self.auth_mock, email='a', password='******', url='www.abc.com')
def test_bad_credentials(self, requests_mock): requests_mock.post = MagicMock(return_value=MagicMock(status_code=400)) message = r'Response HTTP status code .* Invalid credentials?' with six.assertRaisesRegex(self, ValueError, message): ResAuth.__init__(self.auth_mock, email='a', password='******', url='www.abc.com')
def test_bad_url(self, requests_mock): requests_mock.post = MagicMock(side_effect=[requests.exceptions.ConnectionError()]) with six.assertRaisesRegex(self, ValueError, r"Server not accessible on .*. Wrong url?"): ResAuth.__init__(self.auth_mock, email='a', password='******', url='www.abc.com')
def test_bad_url(self, requests_mock): requests_mock.post = MagicMock(side_effect=[requests.exceptions.ConnectionError()]) with self.assertRaisesRegex(ValueError, 'Server not accessible on www.abc.com. Wrong url?'): ResAuth.__init__(self.auth_mock, username='******', password='******', url='www.abc.com')