Skip to content

Commit

Permalink
test: remove now-unused custom field stuff from fake_jira
Browse files Browse the repository at this point in the history
  • Loading branch information
Ned Batchelder authored and nedbat committed Oct 25, 2023
1 parent 4c566d0 commit bb40e4d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 35 deletions.
33 changes: 0 additions & 33 deletions tests/fake_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ class Issue:
key: str
status: str
issuetype: Optional[str] = None
contributor_name: Optional[str] = None
customer: Optional[str] = None
pr_number: Optional[int] = None
repo: Optional[str] = None
url: Optional[str] = None
description: Optional[str] = None
summary: Optional[str] = None
labels: Set[str] = field(default_factory=set)
Expand All @@ -41,25 +36,13 @@ def as_json(self) -> Dict:
"summary": self.summary or None,
"description": self.description or None,
"labels": sorted(self.labels),
FakeJira.CONTRIBUTOR_NAME: self.contributor_name or None,
FakeJira.CUSTOMER: self.customer or None,
FakeJira.PR_NUMBER: self.pr_number,
FakeJira.REPO: self.repo or None,
FakeJira.URL: self.url or None,
},
}


class FakeJira(faker.Faker):
"""A fake implementation of the Jira API, specialized to the OSPR project."""

# Custom fields for OSPR. The values are arbitrary.
CONTRIBUTOR_NAME = "custom_101"
CUSTOMER = "custom_102"
PR_NUMBER = "custom_103"
REPO = "custom_104"
URL = "customfield_10904" # This one is hard-coded

# Issue states and transitions for OSPR.
INITIAL_STATE = "Needs Triage"

Expand Down Expand Up @@ -92,17 +75,6 @@ def __init__(self, host) -> None:
# Map from old keys to new keys for moved issues.
self.moves: Dict[str, str] = {}

@faker.route(r"/rest/api/2/field")
def _get_field(self, _match, _request, _context) -> List[Dict]:
# Custom fields particular to the OSPR project.
return [{"id": i, "name": n, "custom": True} for i, n in [
(self.CONTRIBUTOR_NAME, "Contributor Name"),
(self.CUSTOMER, "Customer"),
(self.PR_NUMBER, "PR Number"),
(self.REPO, "Repo"),
(self.URL, "URL"),
]]

def make_issue(self, key: Optional[str] = None, project: str = "OSPR", **kwargs) -> Issue:
"""Make fake issue data."""
if key is None:
Expand Down Expand Up @@ -153,11 +125,6 @@ def _post_issue(self, _match, request, context):
summary=fields.get("summary"),
description=fields.get("description"),
labels=set(fields.get("labels")),
contributor_name=fields.get(FakeJira.CONTRIBUTOR_NAME),
customer=fields.get(FakeJira.CUSTOMER),
pr_number=fields.get(FakeJira.PR_NUMBER),
repo=fields.get(FakeJira.REPO),
url=fields.get(FakeJira.URL),
)
self.make_issue(key, **kwargs)
# Response is only some information:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def test_get_github_session(fake_github):

def test_get_jira_session(fake_jira):
session = get_jira_session("test1")
response = session.get("/rest/api/2/field")
response = session.get("/rest/api/2/issue/FOO-99")
headers = response.request.headers
user_token = "[email protected]:asdasdasdasdasd"
basic_auth = base64.b64encode(user_token.encode()).decode()
assert headers["Authorization"] == f"Basic {basic_auth}"
assert response.url == "https://test.atlassian.net/rest/api/2/field"
assert response.url == "https://test.atlassian.net/rest/api/2/issue/FOO-99"

0 comments on commit bb40e4d

Please sign in to comment.