From 9545bc995eea9e6b75e784ff52931b4613440568 Mon Sep 17 00:00:00 2001 From: Steve Linabery Date: Thu, 20 Jul 2023 11:37:54 -0500 Subject: [PATCH] Rename ConfigDict class to avoid name clash with pydantic The workaround in the previous patch left some technical debt in the form of ambiguity in the class names. This patch corrects that by renaming our class BugjiraConfigDict. This patch also cleans up a pytest warning about how the pydantic ValidationError was moved to a different namespace in that library by adjusting the import statements we use. --- src/bugjira/config.py | 13 ++++++------- tests/unit/test_broker.py | 2 +- tests/unit/test_config.py | 2 +- tests/unit/test_issue.py | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/bugjira/config.py b/src/bugjira/config.py index f7b6a42..ba59485 100644 --- a/src/bugjira/config.py +++ b/src/bugjira/config.py @@ -1,25 +1,24 @@ import json -import pydantic -from pydantic import BaseModel, field_validator, constr +from pydantic import ConfigDict, BaseModel, field_validator, constr class BugzillaConfig(BaseModel): - model_config = pydantic.ConfigDict(extra='forbid') + model_config = ConfigDict(extra='forbid') URL: constr(strip_whitespace=True, min_length=1) api_key: constr(strip_whitespace=True, min_length=1) class JiraConfig(BaseModel): - model_config = pydantic.ConfigDict(extra='forbid') + model_config = ConfigDict(extra='forbid') URL: constr(strip_whitespace=True, min_length=1) token_auth: constr(strip_whitespace=True, min_length=1) -class ConfigDict(BaseModel): - model_config = pydantic.ConfigDict(extra='forbid') +class BugjiraConfigDict(BaseModel): + model_config = ConfigDict(extra='forbid') bugzilla: BugzillaConfig jira: JiraConfig @@ -32,7 +31,7 @@ class Config(BaseModel): @field_validator("config_dict") def validate_minimum_config(cls, v): - ConfigDict(**v) + BugjiraConfigDict(**v) return v @staticmethod diff --git a/tests/unit/test_broker.py b/tests/unit/test_broker.py index ff3a81d..9e05384 100644 --- a/tests/unit/test_broker.py +++ b/tests/unit/test_broker.py @@ -3,7 +3,7 @@ import pytest from bugzilla import Bugzilla from jira import JIRA -from pydantic.error_wrappers import ValidationError +from pydantic import ValidationError import bugjira.broker as broker from bugjira.broker import ( diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index 6d199e8..91fc609 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -1,7 +1,7 @@ from copy import deepcopy import pytest -from pydantic.error_wrappers import ValidationError +from pydantic import ValidationError from bugjira.config import Config diff --git a/tests/unit/test_issue.py b/tests/unit/test_issue.py index 00ef1ed..b345d2f 100644 --- a/tests/unit/test_issue.py +++ b/tests/unit/test_issue.py @@ -1,5 +1,5 @@ import pytest -from pydantic.error_wrappers import ValidationError +from pydantic import ValidationError from bugjira.issue import BugzillaIssue, JiraIssue