def test_getConfig(monkeypatch, fs): MockedFiles._mockCorrectFileSystem(fs) def mockFileSystemReadFileReturnNone(*args, **kwargs): return None def mockParserJsonReturnJson(*args, **kwargs): content = None with open('./workitems/correct/config.json', 'r') as reader: content = reader.read() reader.close() return json.loads(content) def mockValidationValidateConfigReturnTrue(*args, **kwargs): return True def mockValidationValidateConfigRaiseError(*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, "validateConfig", mockValidationValidateConfigReturnTrue) assert backlog._getConfig('.') == mockParserJsonReturnJson() monkeypatch.setattr(helpers.Validation, "validateConfig", mockValidationValidateConfigRaiseError) with pytest.raises(ValueError) as exc: backlog._getConfig('.') assert "configuration file not valid: there's an error" in str(exc.value)
def test_deploy(fs): MockedFiles._mockCorrectFileSystem(fs) def mock_return_None(*args, **kwargs): return None az = AzDevOps(org='foo', token='bar') az._create_project = MagicMock(return_value=mock_return_None) az._get_project = MagicMock(return_value=SimpleNamespace(id=1)) az._enable_epics = MagicMock(return_value=mock_return_None) az._create_work_item = MagicMock(return_value=mock_return_None) backlog = Backlog() config = backlog._getConfig('workitems/correct') work_items = backlog._buildWorkItems(MockedFiles._mockParsedFileList(), config) args = argparse.Namespace() args.org = 'foo' args.repo = 'testUser' args.project = 'testProject' args.backlog = 'correct' az.deploy(args, work_items) az._create_project.assert_called_with('testProject') az._enable_epics.assert_called() assert az._create_work_item.call_count == 20
def test_buildFeature(fs): MockedFiles._mockCorrectFileSystem(fs) def mockGetConfigReturnConfig(*args, **kwargs): content = None with open('./workitems/correct/config.json', 'r') as reader: content = reader.read() reader.close() return json.loads(content) def mockParserJsonReturnFeatureJson(*args, **kwargs): content = None with open('./workitems/correct/01_epic/02_feature/metadata.json', 'r') as reader: content = reader.read() reader.close() return json.loads(content) def mockBacklogBuildStoryReturnStory(*args, **kwargs): story = entities.UserStory() story.title = "Some Story" story.description = "Some Description" return story def mockFeature(*args, **kwargs): return MockedFiles._mockParsedFileList()[0]["features"][0] backlog = helpers.Backlog() backlog._getAndValidateJson = MagicMock(return_value=False) feature = backlog._buildFeature(mockFeature(), mockGetConfigReturnConfig()) assert feature is None backlog._getAndValidateJson = MagicMock( return_value=mockParserJsonReturnFeatureJson()) backlog._buildStory = MagicMock(return_value=None) feature = backlog._buildFeature(mockFeature(), mockGetConfigReturnConfig()) assert feature.title == "Foo bar" assert feature.description == "Lorem Ipsum 01_folder/02_folder" assert len(feature.tags) == 3 assert Lists.contains(feature.tags, lambda tag: tag.title == "01_Folder") is True assert Lists.contains(feature.tags, lambda tag: tag.title == "02_Folder") is True assert Lists.contains(feature.tags, lambda tag: tag.title == "AppDev") is True assert len(feature.userStories) == 0 backlog._buildStory = MagicMock( return_value=mockBacklogBuildStoryReturnStory()) feature = backlog._buildFeature(mockFeature(), mockGetConfigReturnConfig()) assert len( feature.userStories ) == 2 # should return 2 instances of the mocked feature since the mocked feature has 2 user stories assert feature.userStories[0].title == "Some Story" assert feature.userStories[0].description == "Some Description"
def test_buildEpic(fs): MockedFiles._mockCorrectFileSystem(fs) def mockGetConfigReturnConfig(*args, **kwargs): content = None with open('./workitems/correct/config.json', 'r') as reader: content = reader.read() reader.close() return json.loads(content) def mockParserJsonReturnEpicJson(*args, **kwargs): content = None with open('./workitems/correct/01_epic/02_feature/metadata.json', 'r') as reader: content = reader.read() reader.close() return json.loads(content) def mockBacklogBuildFeatureReturnFeature(*args, **kwargs): feature = entities.Feature() feature.title = "Some Feature" feature.description = "Some Description" return feature backlog = helpers.Backlog() backlog._getAndValidateJson = MagicMock(return_value=False) epic = backlog._buildEpic(MockedFiles._mockParsedFileList()[0], mockGetConfigReturnConfig()) assert epic is None backlog._getAndValidateJson = MagicMock( return_value=mockParserJsonReturnEpicJson()) backlog._buildFeature = MagicMock(return_value=None) epic = backlog._buildEpic(MockedFiles._mockParsedFileList()[0], mockGetConfigReturnConfig()) assert epic.title == "Foo bar" assert epic.description == "Lorem Ipsum 01_folder/02_folder" assert len(epic.tags) == 3 assert Lists.contains(epic.tags, lambda tag: tag.title == "01_Folder") is True assert Lists.contains(epic.tags, lambda tag: tag.title == "02_Folder") is True assert Lists.contains(epic.tags, lambda tag: tag.title == "AppDev") is True assert len(epic.features) == 0 backlog._buildFeature = MagicMock( return_value=mockBacklogBuildFeatureReturnFeature()) epic = backlog._buildEpic(MockedFiles._mockParsedFileList()[0], mockGetConfigReturnConfig()) assert len( epic.features ) == 3 # should return 3 instances of the mocked feature since the mocked epic has 3 features assert epic.features[0].title == "Some Feature" assert epic.features[0].description == "Some Description"
def test_deployAzure(fs): # patchedInit.return_value = None # patchedDeploy.return_value = None MockedFiles._mockCorrectFileSystem(fs) backlog = helpers.Backlog() config = backlog._getConfig('workitems/correct') workItems = backlog._buildWorkItems(MockedFiles._mockParsedFileList(), config) args = Namespace(org='testOrg', repo=None, project='testProject', backlog='correct', token='testToken') backlog._deployAzure(args, workItems)
def test_deployGitHub(patched_github, patched_deploy, fs): patched_github.return_value = MagicMock() patched_deploy.return_value = None MockedFiles._mockCorrectFileSystem(fs) backlog = helpers.Backlog() config = backlog._getConfig('workitems/correct') workItems = backlog._buildWorkItems(MockedFiles._mockParsedFileList(), config) args = Namespace(org='testOrg', repo=None, project='testProject', backlog='correct', token='testToken') backlog._deployGitHub(args, workItems) patched_deploy.assert_called_with(args, workItems)
def test_deployAzure(patched_deploy, fs, monkeypatch): monkeypatch.setattr(services.AzDevOps, "_auth", mock_auth) patched_deploy.return_value = None MockedFiles._mockCorrectFileSystem(fs) backlog = helpers.Backlog() config = backlog._getConfig('workitems/correct') work_items = backlog._buildWorkItems(MockedFiles._mockParsedFileList(), config) args = Namespace(org='testOrg', repo=None, project='testProject', backlog='correct', token='testToken') backlog._deployAzure(args, work_items) patched_deploy.assert_called_with(args, work_items)
def test_buildTask(fs): MockedFiles._mockCorrectFileSystem(fs) def mockGetConfigReturnConfig(*args, **kwargs): content = None with open('./workitems/correct/config.json', 'r') as reader: content = reader.read() reader.close() return json.loads(content) def mockParserJsonReturnTaskJson(*args, **kwargs): content = None with open('./workitems/correct/01_epic/02_feature/metadata.json', 'r') as reader: content = reader.read() reader.close() return json.loads(content) def mockTask(*args, **kwargs): return MockedFiles._mockParsedFileList( )[0]["features"][0]["stories"][0]["tasks"][0] backlog = helpers.Backlog() backlog._getAndValidateJson = MagicMock(return_value=False) task = backlog._buildTask(mockTask(), mockGetConfigReturnConfig()) assert task is None backlog._getAndValidateJson = MagicMock( return_value=mockParserJsonReturnTaskJson()) task = backlog._buildTask(mockTask(), mockGetConfigReturnConfig()) assert task.title == "Foo bar" assert task.description == "Lorem Ipsum 01_folder/02_folder" assert len(task.tags) == 3 assert Lists.contains(task.tags, lambda tag: tag.title == "01_Folder") is True assert Lists.contains(task.tags, lambda tag: tag.title == "02_Folder") is True assert Lists.contains(task.tags, lambda tag: tag.title == "AppDev") is True
def test_deploy_withRepo(fs): MockedFiles._mockCorrectFileSystem(fs) def mock_returnNone(*args, **kwargs): return None gh = GitHub(token='foo') gh._createOrgRepo = MagicMock(return_value=mock_returnNone) gh._createUserRepo = MagicMock(return_value=mock_returnNone) gh._deleteLabels = MagicMock(return_value=mock_returnNone) gh._createProject = MagicMock(return_value=mock_returnNone) gh._createColumns = MagicMock(return_value=mock_returnNone) gh._createMilestone = MagicMock(return_value=mock_returnNone) gh._createIssue = MagicMock(return_value=mock_returnNone) gh._createCard = MagicMock(return_value=mock_returnNone) gh._buildDescription = MagicMock(return_value=mock_returnNone) backlog = Backlog() config = backlog._getConfig('workitems/correct') workItems = backlog._buildWorkItems(MockedFiles._mockParsedFileList(), config) args = argparse.Namespace() args.org = None args.repo = 'testUser' args.project = 'testProject' args.backlog = 'correct' gh.deploy(args, workItems) gh._createUserRepo.assert_called_with('testProject') gh._deleteLabels.assert_called() assert gh._createProject.call_count == 4 assert gh._createColumns.call_count == 4 assert gh._createMilestone.call_count == 6 assert gh._createIssue.call_count == 4 assert gh._createCard.call_count == 4
def test_getFiles_CorrectFileSystem(fs): MockedFiles._mockCorrectFileSystem(fs) f = helpers.FileSystem() files = f.getFiles('./workitems/correct') assert len(files) == 20
def test_buildStory(fs): MockedFiles._mockCorrectFileSystem(fs) def mockGetConfigReturnConfig(*args, **kwargs): content = None with open('./workitems/correct/config.json', 'r') as reader: content = reader.read() reader.close() return json.loads(content) def mockParserJsonReturnUserStoryJson(*args, **kwargs): content = None with open('./workitems/correct/01_epic/02_feature/metadata.json', 'r') as reader: content = reader.read() reader.close() return json.loads(content) def mockBacklogBuildTaskReturnTask(*args, **kwargs): task = entities.Task() task.title = "Some Task" task.description = "Some Description" return task def mockUserStory(*args, **kwargs): return MockedFiles._mockParsedFileList( )[0]["features"][0]["stories"][0] backlog = helpers.Backlog() backlog._getAndValidateJson = MagicMock(return_value=False) story = backlog._buildStory(mockUserStory(), mockGetConfigReturnConfig()) assert story is None backlog._getAndValidateJson = MagicMock( return_value=mockParserJsonReturnUserStoryJson()) backlog._buildTask = MagicMock(return_value=None) story = backlog._buildStory(mockUserStory(), mockGetConfigReturnConfig()) assert story.title == "Foo bar" assert story.description == "Lorem Ipsum 01_folder/02_folder" assert len(story.tags) == 3 assert Lists.contains(story.tags, lambda tag: tag.title == "01_Folder") is True assert Lists.contains(story.tags, lambda tag: tag.title == "02_Folder") is True assert Lists.contains(story.tags, lambda tag: tag.title == "AppDev") is True assert len(story.tasks) == 0 backlog._buildTask = MagicMock( return_value=mockBacklogBuildTaskReturnTask()) story = backlog._buildStory(mockUserStory(), mockGetConfigReturnConfig()) print(mockUserStory()) assert len( story.tasks ) == 2 # should return 2 instances of the mocked story since the mocked story has 2 tasks assert story.tasks[0].title == "Some Task" assert story.tasks[0].description == "Some Description"