def test_template_builders(self): expected_json = """ { "builders": [ { "source": "/source/path", "target": "/target/path", "type": "file" }, { "source": "/source/path", "target": "/target/path", "type": "file" } ] } """ t = Template() t.add_builder([ builder.File( target="/target/path", source="/source/path", ), builder.File( target="/target/path", source="/source/path", ) ]) to_json = t.to_json() assert to_json == json.dumps(json.loads(expected_json), sort_keys=True, indent=2, separators=(',', ': '))
def test_source_and_content_missing(self): b = builder.File( target="dummy_artifact", ) with pytest.warns(UserWarning) as record: b.to_dict() assert len(record) == 1 assert 'Both source and content not specified, artifact will be empty.' == str(record[0].message)
def test_source_and_content_mutually_exclusive(self): b = builder.File( target="dummy_artifact", source="/tmp/source.txt", content="Lorem ipsum dolor sit amet", ) with pytest.raises(ValueError) as excinfo: b.to_dict() assert 'only one of the following can be specified: source, content' in str(excinfo.value)
def test_support_named_builds(self): expected_json = """ { "builders": [ { "type": "file", "name": "linuxFileBuilder", "source": "/tmp/source/path", "target": "/tmp/target/path" }, { "type": "file", "name": "windowsFileBuilder", "source": "C:/Source/Path", "target": "C:/Target/Path" } ] } """ b = [ builder.File( name="linuxFileBuilder", source="/tmp/source/path", target="/tmp/target/path", ), builder.File( name="windowsFileBuilder", source='C:/Source/Path', target='C:/Target/Path', ) ] t = Template() t.add_builder(b) to_json = t.to_json() assert to_json == json.dumps(json.loads(expected_json), sort_keys=True, indent=2, separators=(',', ': '))
def test_required_fields_missing(self): b = builder.File() with pytest.raises(ValueError) as excinfo: b.to_dict() assert 'required' in str(excinfo.value)