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_deploy(fs):
    MockedFiles._mock_correct_file_system(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._get_config('workitems/correct', 'azure')
    config["_repository_path"] = './workitems/correct'
    work_items = backlog._build_work_items(
        MockedFiles._mock_parsed_file_list(), config)

    args = argparse.Namespace()
    args.org = 'foo'
    args.repo = 'testUser'
    args.project = 'testProject'
    args.backlog = 'correct'

    az.deploy(args, work_items, config, [])

    az._create_project.assert_called_with('testProject', 'Sample description')
    az._enable_epics.assert_called()

    assert az._create_work_item.call_count == 20
def test_create_work_item():
    az = AzDevOps(org='foo', token='bar')
    project = SimpleNamespace(id=1)

    patch = [{
        "op": "add",
        "path": "/fields/System.Title",
        "value": 'foo'
    }, {
        "op": "add",
        "path": "/fields/System.Description",
        "value": 'bar'
    }]
    az._create_work_item(project, 'test', 'foo', 'bar')
    assert az.clients.get_work_item_tracking_client.return_value.create_work_item.called_with(
        patch, project, 'test')

    tags_patch = [{
        "op": "add",
        "path": "/fields/System.Title",
        "value": 'foo'
    }, {
        "op": "add",
        "path": "/fields/System.Description",
        "value": 'bar'
    }, {
        "op": "add",
        "path": "/fields/System.Tags",
        "value": 'foo; bar; baz'
    }]
    az._create_work_item(project, 'test', 'foo', 'bar', tags='foo; bar; baz')
    assert az.clients.get_work_item_tracking_client.return_value.create_work_item.called_with(
        tags_patch, project, 'test')

    parent_patch = [{
        "op": "add",
        "path": "/fields/System.Title",
        "value": 'foo'
    }, {
        "op": "add",
        "path": "/fields/System.Description",
        "value": 'bar'
    }, {
        "op": "add",
        "path": "/relations/-",
        "value": {
            "rel": "System.LinkTypes.Hierarchy-Reverse",
            "url": 'http://foobar.com'
        }
    }]
    az._create_work_item(project,
                         'test',
                         'foo',
                         'bar',
                         parent=SimpleNamespace(url="http://foobar.com"))
    assert az.clients.get_work_item_tracking_client.return_value.create_work_item.called_with(
        parent_patch, project, 'test')