Skip to content

Commit

Permalink
Refactor all GMP tests
Browse files Browse the repository at this point in the history
Drop obsolete tests and adjust tests for enum imports.
  • Loading branch information
bjoernricks committed May 31, 2024
1 parent ddf654a commit 5e67903
Show file tree
Hide file tree
Showing 223 changed files with 95 additions and 5,833 deletions.
8 changes: 0 additions & 8 deletions tests/protocols/gmpv208/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,3 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
#

from gvm.protocols.gmpv208 import Gmp

from .. import GmpTestCase


class Gmpv208TestCase(GmpTestCase):
gmp_class = Gmp
4 changes: 0 additions & 4 deletions tests/protocols/gmpv208/entities/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import AlertCondition, AlertEvent, AlertMethod
from gvm.protocols.gmp.requests import AlertCondition, AlertEvent, AlertMethod


class GmpCreateAlertTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import AlertCondition, AlertEvent, AlertMethod
from gvm.protocols.gmp.requests import AlertCondition, AlertEvent, AlertMethod


class GmpModifyAlertTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import RequiredArgument
from gvm.protocols.gmpv208.entities.report_formats import ReportFormatType
from gvm.protocols.gmp.requests import ReportFormatType


class GmpTriggerAlertTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections import OrderedDict

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import HostsOrdering
from gvm.protocols.gmp.requests import HostsOrdering


class GmpCreateAuditTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections import OrderedDict

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import HostsOrdering
from gvm.protocols.gmp.requests import HostsOrdering


class GmpModifyAuditTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import (
from gvm.protocols.gmp.requests import (
CredentialType,
SnmpAuthAlgorithm,
SnmpPrivacyAlgorithm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import CredentialFormat
from gvm.protocols.gmp.requests import CredentialFormat


class GmpGetCredentialTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import SnmpAuthAlgorithm, SnmpPrivacyAlgorithm
from gvm.protocols.gmp.requests import SnmpAuthAlgorithm, SnmpPrivacyAlgorithm


class GmpModifyCredentialTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import FilterType
from gvm.protocols.gmp.requests import FilterType


class GmpCreateFilterTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import FilterType
from gvm.protocols.gmp.requests import FilterType


class GmpModifyFilterTestMixin:
Expand Down
19 changes: 0 additions & 19 deletions tests/protocols/gmpv208/entities/notes/test_create_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from decimal import Decimal

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import SeverityLevel


class GmpCreateNoteTestMixin:
Expand Down Expand Up @@ -118,24 +117,6 @@ def test_create_note_with_severity(self):
b"</create_note>"
)

def test_create_note_with_threat(self):
self.gmp.create_note("foo", nvt_oid="oid1", threat=SeverityLevel.HIGH)

self.connection.send.has_been_called_with(
b"<create_note>"
b"<text>foo</text>"
b'<nvt oid="oid1"/>'
b"<threat>High</threat>"
b"</create_note>"
)

def test_create_note_invalid_threat(self):
with self.assertRaises(InvalidArgument):
self.gmp.create_note("foo", nvt_oid="oid1", threat="")

with self.assertRaises(InvalidArgument):
self.gmp.create_note("foo", nvt_oid="oid1", threat="foo")

def test_create_note_with_days_active(self):
self.gmp.create_note("foo", nvt_oid="oid1", days_active=0)

Expand Down
20 changes: 0 additions & 20 deletions tests/protocols/gmpv208/entities/notes/test_modify_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from decimal import Decimal

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import SeverityLevel


class GmpModifyNoteTestMixin:
Expand Down Expand Up @@ -142,25 +141,6 @@ def test_modify_note_with_severity(self):
b"</modify_note>"
)

def test_modify_note_with_threat(self):
self.gmp.modify_note(
note_id="n1", text="foo", threat=SeverityLevel.HIGH
)

self.connection.send.has_been_called_with(
b'<modify_note note_id="n1">'
b"<text>foo</text>"
b"<threat>High</threat>"
b"</modify_note>"
)

def test_modify_note_invalid_threat(self):
with self.assertRaises(InvalidArgument):
self.gmp.modify_note(note_id="n1", text="foo", threat="")

with self.assertRaises(InvalidArgument):
self.gmp.modify_note(note_id="n1", text="foo", threat="foo")

def test_modify_note_with_invalid_port(self):
with self.assertRaises(InvalidArgument):
self.gmp.modify_note(note_id="o1", text="foo", port="123")
Expand Down
41 changes: 0 additions & 41 deletions tests/protocols/gmpv208/entities/overrides/test_create_override.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from decimal import Decimal

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import SeverityLevel


class GmpCreateOverrideTestMixin:
Expand Down Expand Up @@ -151,46 +150,6 @@ def test_create_override_with_new_severity(self):
b"</create_override>"
)

def test_create_override_with_threat(self):
self.gmp.create_override(
"foo", nvt_oid="oid1", threat=SeverityLevel.HIGH
)

self.connection.send.has_been_called_with(
b"<create_override>"
b"<text>foo</text>"
b'<nvt oid="oid1"/>'
b"<threat>High</threat>"
b"</create_override>"
)

def test_create_override_invalid_threat(self):
with self.assertRaises(InvalidArgument):
self.gmp.create_override("foo", nvt_oid="oid1", threat="")

with self.assertRaises(InvalidArgument):
self.gmp.create_override("foo", nvt_oid="oid1", threat="foo")

def test_create_override_with_new_threat(self):
self.gmp.create_override(
"foo", nvt_oid="oid1", new_threat=SeverityLevel.HIGH
)

self.connection.send.has_been_called_with(
b"<create_override>"
b"<text>foo</text>"
b'<nvt oid="oid1"/>'
b"<new_threat>High</new_threat>"
b"</create_override>"
)

def test_create_override_invalid_new_threat(self):
with self.assertRaises(InvalidArgument):
self.gmp.create_override("foo", nvt_oid="oid1", new_threat="")

with self.assertRaises(InvalidArgument):
self.gmp.create_override("foo", nvt_oid="oid1", new_threat="foo")

def test_create_override_with_days_active(self):
self.gmp.create_override("foo", nvt_oid="oid1", days_active=0)

Expand Down
43 changes: 0 additions & 43 deletions tests/protocols/gmpv208/entities/overrides/test_modify_override.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from decimal import Decimal

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import SeverityLevel


class GmpModifyOverrideTestMixin:
Expand Down Expand Up @@ -180,48 +179,6 @@ def test_modify_override_with_new_severity(self):
b"</modify_override>"
)

def test_modify_override_with_threat(self):
self.gmp.modify_override(
override_id="o1", text="foo", threat=SeverityLevel.HIGH
)

self.connection.send.has_been_called_with(
b'<modify_override override_id="o1">'
b"<text>foo</text>"
b"<threat>High</threat>"
b"</modify_override>"
)

def test_modify_override_invalid_threat(self):
with self.assertRaises(InvalidArgument):
self.gmp.modify_override(override_id="o1", text="foo", threat="")

with self.assertRaises(InvalidArgument):
self.gmp.modify_override(override_id="o1", text="foo", threat="foo")

def test_modify_override_with_new_threat(self):
self.gmp.modify_override(
override_id="o1", text="foo", new_threat=SeverityLevel.HIGH
)

self.connection.send.has_been_called_with(
b'<modify_override override_id="o1">'
b"<text>foo</text>"
b"<new_threat>High</new_threat>"
b"</modify_override>"
)

def test_modify_override_invalid_new_threat(self):
with self.assertRaises(InvalidArgument):
self.gmp.modify_override(
override_id="o1", text="foo", new_threat=""
)

with self.assertRaises(InvalidArgument):
self.gmp.modify_override(
override_id="o1", text="foo", new_threat="foo"
)

def test_modify_override_with_invalid_port(self):
with self.assertRaises(InvalidArgument):
self.gmp.modify_override(override_id="o1", text="foo", port="123")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import EntityType, PermissionSubjectType
from gvm.protocols.gmp.requests import EntityType, PermissionSubjectType


class GmpCreatePermissionTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import EntityType, PermissionSubjectType
from gvm.protocols.gmp.requests import EntityType, PermissionSubjectType


class GmpModifyPermissionTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208.entities.port_lists import PortRangeType
from gvm.protocols.gmp.requests import PortRangeType


class GmpCreatePortRangeTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import RequiredArgument
from gvm.protocols.gmpv208.entities.report_formats import ReportFormatType
from gvm.protocols.gmp.requests import ReportFormatType


class GmpCloneReportFormatTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import GvmError
from gvm.protocols.gmpv208.entities.report_formats import ReportFormatType
from gvm.protocols.gmp.requests import ReportFormatType


class GmpDeleteReportFormatTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import RequiredArgument
from gvm.protocols.gmpv208.entities.report_formats import ReportFormatType
from gvm.protocols.gmp.requests import ReportFormatType


class GmpGetReportFormatTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import RequiredArgument
from gvm.protocols.gmpv208.entities.report_formats import ReportFormatType
from gvm.protocols.gmp.requests import ReportFormatType


class GmpModifyReportFormatTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import GvmError
from gvm.protocols.gmpv208.entities.report_formats import ReportFormatType
from gvm.protocols.gmp.requests import ReportFormatType


class GmpVerifyReportFormatTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import RequiredArgument
from gvm.protocols.gmpv208.entities.report_formats import ReportFormatType
from gvm.protocols.gmp.requests import ReportFormatType


class GmpGetReportTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import ScannerType
from gvm.protocols.gmp.requests import ScannerType


class GmpCreateScannerTestMixin:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import ScannerType
from gvm.protocols.gmp.requests import ScannerType


class GmpModifyScannerTestMixin:
Expand Down
2 changes: 1 addition & 1 deletion tests/protocols/gmpv208/entities/secinfo/test_get_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.protocols.gmpv208 import InfoType
from gvm.protocols.gmp.requests import InfoType


class GmpGetInfoTestMixin:
Expand Down
Loading

0 comments on commit 5e67903

Please sign in to comment.