Skip to content

Commit

Permalink
Rename ConfigDict class to avoid name clash with pydantic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eggmaster authored and jguiditta committed Jul 25, 2023
1 parent 8ebfa07 commit 9545bc9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
13 changes: 6 additions & 7 deletions src/bugjira/config.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -32,7 +31,7 @@ class Config(BaseModel):

@field_validator("config_dict")
def validate_minimum_config(cls, v):
ConfigDict(**v)
BugjiraConfigDict(**v)
return v

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_config.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_issue.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from pydantic.error_wrappers import ValidationError
from pydantic import ValidationError

from bugjira.issue import BugzillaIssue, JiraIssue

Expand Down

0 comments on commit 9545bc9

Please sign in to comment.