-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: Introduce a StrEnum class for Models
Allow to use a Enum class with str behavior for easier usage of models with enum values in APIs.
- Loading branch information
1 parent
b1d96b0
commit 3073728
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# SPDX-FileCopyrightText: 2023 Greenbone AG | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
import unittest | ||
|
||
from pontos.models import StrEnum | ||
|
||
|
||
class FooEnum(StrEnum): | ||
A = "a" | ||
B = "b" | ||
|
||
|
||
class StrEnumTestCase(unittest.TestCase): | ||
def test_str(self): | ||
self.assertEqual(str(FooEnum.A), "a") | ||
self.assertEqual(str(FooEnum.B), "b") | ||
|
||
def test_str_append(self): | ||
self.assertEqual("say " + FooEnum.A, "say a") | ||
self.assertEqual("say " + FooEnum.B, "say b") | ||
|
||
def test_f_string(self): | ||
self.assertEqual(f"say {FooEnum.A}", "say a") | ||
self.assertEqual(f"say {FooEnum.B}", "say b") |