Exemplo n.º 1
0
def test_state_id_by_name__empty_name():
    rpc = mock.Mock()

    result = states.state_id_by_name(rpc, '')

    assert result == 0
    rpc.state_list.assert_not_called()
Exemplo n.º 2
0
def action_update(rpc, patch_id, state=None, archived=None, commit=None):
    patch = rpc.patch_get(patch_id)
    if patch == {}:
        sys.stderr.write("Error getting information on patch ID %d\n" %
                         patch_id)
        sys.exit(1)

    params = {}

    if state:
        state_id = state_id_by_name(rpc, state)
        if state_id == 0:
            sys.stderr.write("Error: No State found matching %s*\n" % state)
            sys.exit(1)
        params['state'] = state_id

    if commit:
        params['commit_ref'] = commit

    if archived:
        params['archived'] = archived == 'yes'

    success = False
    try:
        success = rpc.patch_set(patch_id, params)
    except xmlrpclib.Fault as f:
        sys.stderr.write("Error updating patch: %s\n" % f.faultString)

    if not success:
        sys.stderr.write("Patch not updated\n")
Exemplo n.º 3
0
def test_state_id_by_name__no_matches():
    rpc = mock.Mock()
    rpc.state_list.return_value = [
        {'id': 1, 'name': 'bar'},
        {'id': 2, 'name': 'baz'},
    ]

    result = states.state_id_by_name(rpc, 'foo')

    assert result == 0
    rpc.state_list.assert_called_once_with('foo', 0)
Exemplo n.º 4
0
    def resolve_ids(self, rpc):
        """Resolve State, Project, and Person IDs based on filter strings."""
        if self.state != "":
            id = state_id_by_name(rpc, self.state)
            if id == 0:
                sys.stderr.write("Note: No State found matching %s*, "
                                 "ignoring filter\n" % self.state)
            else:
                self.d['state_id'] = id

        if self.project is not None:
            id = project_id_by_name(rpc, self.project)
            if id == 0:
                sys.stderr.write("Note: No Project found matching %s, "
                                 "ignoring filter\n" % self.project)
            else:
                self.d['project_id'] = id