def test_get_credentials_empty_configuration(self): test_obj = JenkinsConfigParser() sample_config=StringIO("") test_obj.readfp(sample_config) self.assertEqual(test_obj.get_credentials("http://localhost:8080"), None, "Empty config files should provide empty credentials")
def test_empty_section(self): test_url = "http://localhost:8080" sample_config=StringIO("[http://localhost:8080]") test_obj = JenkinsConfigParser() test_obj.readfp(sample_config) self.assertEqual(test_obj.get_credentials(test_url), None, "Undefined credentials should be reported as empty")
def test_get_credentials_empty_configuration(): test_obj = JenkinsConfigParser() sample_config = StringIO("") if six.PY3: test_obj.read_file(sample_config) else: test_obj.readfp(sample_config) assert test_obj.get_credentials("http://localhost:8080") is None
def test_get_credentials_no_password(self): test_url = "http://localhost:8080" sample_config=StringIO("[http://localhost:8080]\n" + "username=jdoe\n") test_obj = JenkinsConfigParser() test_obj.readfp(sample_config) self.assertRaises(InvalidUserParamsError, test_obj.get_credentials, test_url)
def test_empty_section(): test_url = "http://localhost:8080" sample_config = StringIO("[http://localhost:8080]") test_obj = JenkinsConfigParser() if six.PY3: test_obj.read_file(sample_config) else: test_obj.readfp(sample_config) assert test_obj.get_credentials(test_url) is None
def test_get_credentials_anonymous(self): test_url = "http://localhost:8080" sample_config=StringIO("[http://localhost:8080]\n" + "username=\n" + "password=\n") test_obj = JenkinsConfigParser() test_obj.readfp(sample_config) self.assertEqual(test_obj.get_credentials(test_url), None, "Config explicitly declares empty username and password which should \ be reported as empty credentials")
def test_get_credentials_anonymous(): test_url = "http://localhost:8080" sample_config = StringIO("""[http://localhost:8080] username= password= """) test_obj = JenkinsConfigParser() if six.PY3: test_obj.read_file(sample_config) else: test_obj.readfp(sample_config) assert test_obj.get_credentials(test_url) is None
def test_get_credentials_no_username(): test_url = "http://localhost:8080" sample_config = StringIO("""[http://localhost:8080] password=Password123 """) test_obj = JenkinsConfigParser() if six.PY3: test_obj.read_file(sample_config) else: test_obj.readfp(sample_config) with pytest.raises(InvalidUserParamsError): test_obj.get_credentials(test_url)
def test_get_credentials(self): test_url = "http://localhost:8080" expected_username = "******" expected_password = "******" sample_config=StringIO("[http://localhost:8080]\n" + "username=jdoe\n" + "password=Password123\n") test_obj = JenkinsConfigParser() test_obj.readfp(sample_config) actual_credentials = test_obj.get_credentials(test_url) self.assertEqual(actual_credentials[0], expected_username) self.assertEqual(actual_credentials[1], expected_password)
def test_get_credentials(): test_url = "http://localhost:8080" expected_username = "******" expected_password = "******" sample_config = StringIO("""[http://localhost:8080] username=jdoe password=Password123 """) test_obj = JenkinsConfigParser() if six.PY3: test_obj.read_file(sample_config) else: test_obj.readfp(sample_config) actual_credentials = test_obj.get_credentials(test_url) assert actual_credentials[0] == expected_username assert actual_credentials[1] == expected_password