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_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_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_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_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_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_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_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_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')