Skip to content

Commit

Permalink
use enum for deprecation reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
amy-gb committed Jul 4, 2024
1 parent 42dceb0 commit 139fb8e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
16 changes: 8 additions & 8 deletions tests/standalone_plugins/test_deprecate_vts.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ParseArgsTestCase(unittest.TestCase):
def test_parse_args(self):
testfile = "testfile.nasl"
output_path = "attic/"
reason = "notus"
reason = "NOTUS"

args = parse_args(
[
Expand All @@ -38,11 +38,11 @@ def test_parse_args(self):
self.assertEqual(args.output_path, Path(output_path))
self.assertEqual(args.deprecation_reason, reason)

def test_parse_args_invalid_reason(self):
def test_mandatory_arg_group_both(self):
testfile = "testfile.nasl"
output_path = "attic/"
input_path = "nasl/common"
reason = "notus"
reason = "NOTUS"

with self.assertRaises(SystemExit):
parse_args(
Expand All @@ -58,7 +58,7 @@ def test_parse_args_invalid_reason(self):
]
)

def test_mandatory_arg_group_both(self):
def test_invalid_reason(self):
output_path = "attic/"
input_path = "nasl/common"
reason = "foo"
Expand All @@ -76,7 +76,7 @@ def test_mandatory_arg_group_both(self):

def test_mandatory_arg_group_neither(self):
output_path = "attic/"
reason = "notus"
reason = "NOTUS"
with self.assertRaises(SystemExit):
parse_args(
[
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_deprecate(self):
content=NASL_CONTENT,
)
]
deprecate(out_dir, to_deprecate, "notus")
deprecate(out_dir, to_deprecate, "NOTUS")

result = testfile2.read_text(encoding="utf8")
self.assertNotIn(result, "script_mandatory_keys")
Expand All @@ -147,7 +147,7 @@ def test_deprecate_kb_item(self):
content=NASL_CONTENT_KB,
)
]
deprecate(out_dir, to_deprecate, "notus")
deprecate(out_dir, to_deprecate, "NOTUS")
self.assertLogs(
"Unable to deprecate testfile1.nasl. There are still KB keys "
"remaining."
Expand Down Expand Up @@ -177,7 +177,7 @@ def test_update_summary_no_oid_match(self):
full_path=Path("dir/testfile.nasl"),
content=NASL_CONTENT,
)
result = update_summary(file, "notus")
result = update_summary(file, "NOTUS")
self.assertIn("This VT has been deprecated", result)

def test_get_files_from_path(self):
Expand Down
18 changes: 10 additions & 8 deletions troubadix/standalone_plugins/deprecate_vts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
from argparse import ArgumentParser, Namespace
from dataclasses import dataclass
from enum import Enum
from pathlib import Path
from typing import Iterable, Optional

Expand All @@ -15,12 +16,12 @@
SpecialScriptTag,
)

DEPRECATIONS = {
"notus": "and replaced by a Notus scanner based one.",
"merged": "because it has been merged into a different VT.",
"defunct": "and is therefore no longer functional.",
"duplicate": "as a duplicate.",
}

class Deprecations(Enum):
NOTUS = "and replaced by a Notus scanner based one."
MERGED = "because it has been merged into a different VT."
DEFUNCT = "and is therefore no longer functional."
DUPLICATE = "as a duplicate."


@dataclass
Expand Down Expand Up @@ -52,7 +53,8 @@ def update_summary(file: DeprecatedFile, deprecation_reason: str) -> str:
return file.content

Check warning on line 53 in troubadix/standalone_plugins/deprecate_vts.py

View check run for this annotation

Codecov / codecov/patch

troubadix/standalone_plugins/deprecate_vts.py#L52-L53

Added lines #L52 - L53 were not covered by tests

deprecate_text = (
f"Note: This VT has been deprecated {DEPRECATIONS[deprecation_reason]}"
f"Note: This VT has been deprecated "
f"{Deprecations[deprecation_reason].value}"
)

new_summary = old_summary + "\n" + deprecate_text
Expand Down Expand Up @@ -205,7 +207,7 @@ def parse_args(args: Iterable[str] = None) -> Namespace:
"-r",
"--deprecation-reason",
metavar="<deprecation_reason>",
choices=DEPRECATIONS.keys(),
choices=[reason.name for reason in Deprecations],
type=str,
help="The reason the VT is being deprecated. Options are 'notus':"
"The VT has been replaced by a new Notus VT. 'Merged': the VT has"
Expand Down

0 comments on commit 139fb8e

Please sign in to comment.