def test_buildWorkItems(fs): backlog = helpers.Backlog() backlog._buildEpic = MagicMock(return_value=None) workitems = backlog._buildWorkItems(MockedFiles._mockParsedFileList(), MockedFiles._mockConfig()) backlog._buildEpic.assert_any_call(MockedFiles._mockParsedFileList()[0], MockedFiles._mockConfig()) backlog._buildEpic.assert_any_call(MockedFiles._mockParsedFileList()[1], MockedFiles._mockConfig()) backlog._buildEpic.assert_any_call(MockedFiles._mockParsedFileList()[2], MockedFiles._mockConfig()) assert workitems == [] epic = entities.Epic() epic.title = "Foobar" epic.description = "Some Description" backlog._buildEpic = MagicMock(return_value=epic) workitems = backlog._buildWorkItems([MockedFiles._mockParsedFileList()[0]], MockedFiles._mockConfig()) assert len(workitems) == 1 assert workitems[0] == epic assert workitems[0].title == "Foobar" assert workitems[0].description == "Some Description"
def test_validateRoles(): v = helpers.Validation() assert v._validateRoles( './somepath/metadata.json', {}, MockedFiles._mockConfig() ) == (False, "'roles' property not found in metadata './somepath/metadata.json'") assert v._validateRoles('./somepath/metadata.json', { 'roles': 'lorem ipsum' }, MockedFiles._mockConfig()) == ( False, "'roles' property is not in correct format in metadata './somepath/metadata.json'" ) assert v._validateRoles('./somepath/metadata.json', { 'roles': ['lorem ipsum'] }, MockedFiles._mockConfig()) == ( False, "invalid role 'lorem ipsum' in metadata './somepath/metadata.json'") assert v._validateRoles('./somepath/metadata.json', {'roles': ['AppDev']}, MockedFiles._mockConfig()) is True
def test_validateTags(): v = helpers.Validation() assert v._validateTags( './somepath/metadata.json', {}, MockedFiles._mockConfig()) == ( False, "'tags' property not found in metadata './somepath/metadata.json'") assert v._validateTags('./somepath/metadata.json', { 'tags': 'lorem ipsum' }, MockedFiles._mockConfig()) == ( False, "'tags' property is not in correct format in metadata './somepath/metadata.json'" ) assert v._validateTags( './somepath/metadata.json', {'tags': ['lorem ipsum']}, MockedFiles._mockConfig()) == ( False, "invalid tag 'lorem ipsum' in metadata './somepath/metadata.json'") assert v._validateTags('./somepath/metadata.json', {'tags': ['01_Folder']}, MockedFiles._mockConfig()) is True
def test_getAndValidateJson(monkeypatch, fs): MockedFiles._mockCorrectFileSystem(fs) def mockFileSystemReadFileReturnNone(*args, **kwargs): return None def mockParserJsonReturnJson(*args, **kwargs): content = None with open('./workitems/correct/01_epic/metadata.json', 'r') as reader: content = reader.read() reader.close() return json.loads(content) def mockValidationValidateMetadataReturnTrue(*args, **kwargs): return True def mockValidationValidateMetadataReturnFalse(*args, **kwargs): return (False, "there's an error") monkeypatch.setattr(helpers.FileSystem, "readFile", mockFileSystemReadFileReturnNone) monkeypatch.setattr(helpers.Parser, "json", mockParserJsonReturnJson) backlog = helpers.Backlog() monkeypatch.setattr(helpers.Validation, "validateMetadata", mockValidationValidateMetadataReturnTrue) assert backlog._getAndValidateJson( '.', MockedFiles._mockConfig()) == mockParserJsonReturnJson() monkeypatch.setattr(helpers.Validation, "validateMetadata", mockValidationValidateMetadataReturnFalse) with pytest.raises(ValueError) as exc: backlog._getAndValidateJson('.', MockedFiles._mockConfig()) assert "metadata not valid: there's an error" in str(exc.value)
def test_validateMetadata(): v = helpers.Validation() assert v.validateMetadata( './somepath/metadata.json', None, MockedFiles._mockConfig()) == ( False, "metadata in './somepath/metadata.json' is empty") v._validateTitle = MagicMock(return_value=(False, "no title")) assert v.validateMetadata('./somepath/metadata.json', { 'description': 'lorem desc', 'tags': ['01_Folder'], 'roles': [] }, MockedFiles._mockConfig()) == (False, "no title") v._validateTitle = MagicMock(return_value=True) v._validateDescription = MagicMock(return_value=(False, "no description")) assert v.validateMetadata('./somepath/metadata.json', { 'title': 'lorem ipsum', 'tags': ['01_Folder'], 'roles': [] }, MockedFiles._mockConfig()) == (False, "no description") v._validateTitle = MagicMock(return_value=True) v._validateDescription = MagicMock(return_value=True) v._validateTags = MagicMock(return_value=(False, "no tags")) assert v.validateMetadata('./somepath/metadata.json', { 'title': 'lorem ipsum', 'description': 'lorem desc', 'roles': [] }, MockedFiles._mockConfig()) == (False, "no tags") v._validateTitle = MagicMock(return_value=True) v._validateDescription = MagicMock(return_value=True) v._validateTags = MagicMock(return_value=True) v._validateRoles = MagicMock(return_value=(False, "no roles")) assert v.validateMetadata('./somepath/metadata.json', { 'title': 'lorem ipsum', 'description': 'lorem desc', 'tags': ['01_Folder'] }, MockedFiles._mockConfig()) == (False, "no roles") v._validateTitle = MagicMock(return_value=True) v._validateDescription = MagicMock(return_value=True) v._validateTags = MagicMock(return_value=True) v._validateRoles = MagicMock(return_value=True) assert v.validateMetadata( './somepath/metadata.json', { 'title': 'lorem ipsum', 'description': 'lorem desc', 'tags': ['01_Folder'], 'roles': [] }, MockedFiles._mockConfig()) is True
def mock_get_config_return_config(*args, **kwargs): return MockedFiles._mockConfig()
def mockGetConfigReturnConfig(*args, **kwargs): return MockedFiles._mockConfig()