Exemple #1
0
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"
Exemple #2
0
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_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
Exemple #4
0
def test_parseWorkItems(monkeypatch):
    def mockParseWorkItemsReturnFileList(*args, **kwargs):
        return MockedFiles._mockParsedFileList()

    monkeypatch.setattr(helpers.Parser, "fileHierarchy",
                        mockParseWorkItemsReturnFileList)

    backlog = helpers.Backlog()
    assert backlog._parseWorkItems('.') == MockedFiles._mockParsedFileList()
Exemple #5
0
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)
Exemple #6
0
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)
Exemple #7
0
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_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
Exemple #9
0
def test_fileHierarchy():
    p = helpers.Parser()
    parsedFiles = p.fileHierarchy(MockedFiles._mockFileList())

    assert parsedFiles == MockedFiles._mockParsedFileList()
Exemple #10
0
 def mockParseWorkItemsReturnFileList(*args, **kwargs):
     return MockedFiles._mockParsedFileList()
Exemple #11
0
 def mock_parse_work_items_return_parsed_file_list(*args, **kwargs):
     return MockedFiles._mockParsedFileList()
Exemple #12
0
 def mockTask(*args, **kwargs):
     return MockedFiles._mockParsedFileList(
     )[0]["features"][0]["stories"][0]["tasks"][0]
Exemple #13
0
 def mockUserStory(*args, **kwargs):
     return MockedFiles._mockParsedFileList(
     )[0]["features"][0]["stories"][0]
Exemple #14
0
 def mockFeature(*args, **kwargs):
     return MockedFiles._mockParsedFileList()[0]["features"][0]