def test_match_user_creds(self): self.set_conf( JENKINS_USERNAME='******', JENKINS_PASSWORD='******', JENKINS_URL='jenkins.example.com', ) result = helga_jenkins.parse_credentials('alfredodeza', ['status', 'job'], None) assert result['username'] == 'admin' assert result['password'] == 'secret'
def test_unable_to_connect_missing_username(self): self.set_conf( { 'prod': { 'url': 'http://ci.example.com', 'credentials': { 'ktdreyer': { 'username': '******', 'token': 'lkjh234hjasdf00'} } } } ) # this fails because the nick 'alfredo' doesn't have a matching # configured username for "prod" with pytest.raises(RuntimeError) as error: helga_jenkins.parse_credentials('alfredo', ['prod', 'status', 'job']) assert "config key: 'username'" in str(error.value)
def test_regular_user_creds(self): self.set_conf( { 'prod': { 'username': '******', 'password': '******', 'url': 'http://ci.example.com'} } ) result = helga_jenkins.parse_credentials('alfredo', ['prod', 'status', 'job']) assert result['username'] == 'alfredo' assert result['password'] == 'secret' assert result['url'] == 'http://ci.example.com'
def test_match_regular_creds_over_user_creds(self): self.set_conf( JENKINS_USERNAME='******', JENKINS_PASSWORD='******', JENKINS_URL='jenkins.example.com', JENKINS_CREDENTIALS={ 'alfredodeza': { 'username': '******', 'token': 'asdf1234', } } ) result = helga_jenkins.parse_credentials('ktdreyer', ['status', 'job'], None) assert result['username'] == 'admin' assert result['password'] == 'secret'
def test_per_nick_credentials(self): self.set_conf( { 'prod': { 'username': '******', 'password': '******', 'url': 'http://ci.example.com', 'credentials': { 'ktdreyer': { 'username': '******', 'token': 'lkjh234hjasdf00'} } } } ) result = helga_jenkins.parse_credentials('ktdreyer', ['prod', 'status', 'job']) assert result['username'] == 'kdreyer' assert result['password'] == 'lkjh234hjasdf00' assert result['url'] == 'http://ci.example.com'
def test_url_is_not_defined(self): self.set_conf({'prod': {'username': '******'}}) with pytest.raises(RuntimeError) as error: helga_jenkins.parse_credentials('alfredo', ['prod', 'status', 'job'], None) assert '"url" is a required key' in str(error.value) assert 'for Jenkins instance "prod"' in str(error.value)
def test_name_collision(self): self.set_conf({'status': {'url': 'jenkins.example.com'}}) with pytest.raises(RuntimeError) as error: helga_jenkins.parse_credentials('foo', ['create', 'job'], None) assert 'has the same name' in str(error.value) assert "'status'" in str(error.value)