def test_load_spec_fails_file_not_found(capsys): filename = 'non_existent.yml' dirname = os.path.dirname(__file__) path = os.path.join(dirname, filename) with pytest.raises(SystemExit): spec_inspector.render_template(path) out, _ = capsys.readouterr() assert spec_inspector.FILE_OPEN_ERROR_MSG.format(path, '') in out
def test_render_template(tmpdir): spec_path = tmpdir.join('spec.yml') spec_path.write(""" fred: can_login: yes my_group: can_login: no admin: can_login: yes is_superuser: yes options: - CREATEDB - CREATEROLE - REPLICATION service1: can_login: yes schemas: - service1_schema """) spec = spec_inspector.render_template(spec_path.strpath) spec = yaml.load(spec) assert len(spec) == 4 assert set(spec.keys()) == {'admin', 'my_group', 'service1', 'fred'}
def test_load_spec_fails_missing_templated_envvars(capsys, tmpdir): envvar_name = 'MISSING_ENVVAR' assert envvar_name not in os.environ spec = """ fred: can_login: yes options: - PASSWORD: "******" """ % envvar_name spec_path = tmpdir.join('spec.yml') spec_path.write(spec) with pytest.raises(SystemExit): spec_inspector.render_template(spec_path.strpath) out, err = capsys.readouterr() expected = spec_inspector.MISSING_ENVVAR_MSG.format('') assert expected in out assert envvar_name in out
def test_load_spec_with_templated_variables(tmpdir, set_envvar): spec_path = tmpdir.join('spec.yml') spec_path.write(""" fred: can_login: yes options: - PASSWORD: "******" """) spec = spec_inspector.render_template(spec_path.strpath) spec = yaml.load(spec) password_option = spec['fred']['options'][0] assert password_option['PASSWORD'] == 'a_password'
def test_verify_spec_fails_role_defined_multiple_times(tmpdir): spec_path = tmpdir.join('spec.yml') spec_path.write(""" jfinance: owns: schemas: - finance_documents jfinance: owns: schemas: - even_more_finance_documents patty: owns: schemas: - tupperwear """) rendered_template = spec_inspector.render_template(spec_path.strpath) errors = spec_inspector.ensure_no_duplicate_roles(rendered_template) expected = spec_inspector.DUPLICATE_ROLE_DEFINITIONS_ERR_MSG.format('jfinance') assert [expected] == errors