Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GMP7: Make resource_id optional when creating tags #124

Merged
merged 3 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
container task into an own method [PR 108](https://github.com/greenbone/python-gvm/pull/108)
* Refresh the dependencies specified via the Pipfile.lock file to their latest
versions [PR 113](https://github.com/greenbone/python-gvm/pull/113)
* Make resource_id optional when creating tags (Gmpv7) [PR 124](https://github.com/greenbone/python-gvm/pull/124)

### Removed
* Removed hosts_ordering argument from `modify_target` [PR 88](https://github.com/greenbone/python-gvm/pull/88)
Expand Down
12 changes: 7 additions & 5 deletions gvm/protocols/gmpv7.py
Original file line number Diff line number Diff line change
Expand Up @@ -1636,9 +1636,9 @@ def clone_schedule(self, schedule_id):
def create_tag(
self,
name,
resource_id,
resource_type,
*,
resource_id=None,
value=None,
comment=None,
active=None
Expand All @@ -1648,7 +1648,8 @@ def create_tag(
Arguments:
name (str): Name of the tag. A full tag name consisting of namespace
and predicate e.g. `foo:bar`.
resource_id (str): ID of the resource the tag is to be attached to.
resource_id (str, optional): ID of the resource the tag is to be
attached to.
resource_type (str): Entity type the tag is to be attached to
value (str, optional): Value associated with the tag
comment (str, optional): Comment for the tag
Expand All @@ -1660,14 +1661,15 @@ def create_tag(
if not name:
raise RequiredArgument("create_tag requires name argument")

if not resource_id:
raise RequiredArgument("create_tag requires resource_id argument")

if not resource_type:
raise RequiredArgument("create_tag requires resource_type argument")

cmd = XmlCommand("create_tag")
cmd.add_element("name", name)

if not resource_id:
resource_id = ''

_xmlresource = cmd.add_element(
"resource", attrs={"id": str(resource_id)}
)
Expand Down
28 changes: 20 additions & 8 deletions tests/protocols/gmpv7/test_create_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,27 @@ def test_create_tag_missing_name(self):
)

def test_create_tag_missing_resource_id(self):
with self.assertRaises(RequiredArgument):
self.gmp.create_tag(
name='foo', resource_id=None, resource_type='task'
)
self.gmp.create_tag(name='foo', resource_id=None, resource_type='task')

with self.assertRaises(RequiredArgument):
self.gmp.create_tag(
name='foo', resource_id='', resource_type='task'
)
self.connection.send.has_been_called_with(
'<create_tag>'
'<name>foo</name>'
'<resource id="">'
'<type>task</type>'
'</resource>'
'</create_tag>'
)

self.gmp.create_tag(name='foo', resource_id='', resource_type='task')

self.connection.send.has_been_called_with(
'<create_tag>'
'<name>foo</name>'
'<resource id="">'
'<type>task</type>'
'</resource>'
'</create_tag>'
)

def test_create_tag_missing_resource_type(self):
with self.assertRaises(RequiredArgument):
Expand Down