-
-
Notifications
You must be signed in to change notification settings - Fork 893
Feature: Display name field mapping #2372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zampierilucas
wants to merge
3
commits into
pycontribs:main
Choose a base branch
from
zampierilucas:feature/display-name-field-mapping
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,161 @@ | ||
from __future__ import annotations | ||
|
||
from jira.resources import convert_display_name_to_python_name | ||
from tests.conftest import JiraTestCase | ||
|
||
|
||
class IssueDisplayNameFieldsTest(JiraTestCase): | ||
def setUp(self) -> None: | ||
super().setUp() | ||
self.issue_1 = self.test_manager.project_b_issue1 | ||
self.issue_1_obj = self.test_manager.project_b_issue1_obj | ||
|
||
def test_issue_has_display_name_fields(self): | ||
issue = self.issue_1_obj | ||
all_attrs = [attr for attr in dir(issue.fields) if not attr.startswith('__')] | ||
custom_field_ids = [attr for attr in all_attrs if attr.startswith('customfield_')] | ||
|
||
self.assertGreater(len(custom_field_ids), 0) | ||
|
||
standard_fields = ['summary', 'status', 'priority', 'created'] | ||
for field in standard_fields: | ||
self.assertIn(field, all_attrs) | ||
|
||
expected_minimum = len(custom_field_ids) + len(standard_fields) | ||
self.assertGreater(len(all_attrs), expected_minimum) | ||
|
||
def test_issue_field_access_patterns(self): | ||
issue = self.issue_1_obj | ||
|
||
self.assertIsNotNone(issue.fields.summary) | ||
self.assertIsNotNone(issue.fields.status) | ||
|
||
custom_fields = [attr for attr in dir(issue.fields) if attr.startswith('customfield_')] | ||
if custom_fields: | ||
getattr(issue.fields, custom_fields[0]) | ||
|
||
all_fields = dir(issue.fields) | ||
self.assertIsInstance(all_fields, list) | ||
self.assertGreater(len(all_fields), 10) | ||
|
||
def test_issue_field_equivalence_real_data(self): | ||
issue = self.issue_1_obj | ||
|
||
if not hasattr(self.jira, '_fields_cache') or not self.jira._fields_cache: | ||
self.skipTest("JIRA instance doesn't have fields cache populated") | ||
|
||
fields_cache = self.jira._fields_cache | ||
tested_pairs = 0 | ||
|
||
for display_name, field_id in fields_cache.items(): | ||
if tested_pairs >= 3: | ||
break | ||
|
||
if hasattr(issue.fields, field_id): | ||
python_name = convert_display_name_to_python_name(display_name) | ||
|
||
if hasattr(issue.fields, python_name): | ||
original_value = getattr(issue.fields, field_id) | ||
display_value = getattr(issue.fields, python_name) | ||
self.assertEqual(original_value, display_value) | ||
tested_pairs += 1 | ||
|
||
if tested_pairs == 0: | ||
self.skipTest("No suitable field pairs found for equivalence testing") | ||
|
||
def test_issue_custom_field_values_preserved(self): | ||
issue = self.issue_1_obj | ||
|
||
custom_fields_with_values = [] | ||
for attr in dir(issue.fields): | ||
if attr.startswith('customfield_'): | ||
value = getattr(issue.fields, attr, None) | ||
if value is not None: | ||
custom_fields_with_values.append((attr, value)) | ||
|
||
self.assertGreater(len(custom_fields_with_values), 0) | ||
|
||
fields_cache = getattr(self.jira, '_fields_cache', {}) | ||
|
||
for field_id, original_value in custom_fields_with_values[:3]: | ||
display_name = None | ||
for name, fid in fields_cache.items(): | ||
if fid == field_id: | ||
display_name = name | ||
break | ||
|
||
if display_name: | ||
python_name = convert_display_name_to_python_name(display_name) | ||
|
||
if hasattr(issue.fields, python_name): | ||
display_value = getattr(issue.fields, python_name) | ||
self.assertIs( | ||
original_value, display_value, | ||
f"Values should be the same object: {field_id} vs {python_name}" | ||
) | ||
|
||
def test_issue_fields_dir_includes_display_names(self): | ||
issue = self.issue_1_obj | ||
all_attrs = dir(issue.fields) | ||
|
||
standard_fields = ['summary', 'status', 'priority', 'issuetype'] | ||
for field in standard_fields: | ||
self.assertIn(field, all_attrs) | ||
|
||
custom_field_ids = [attr for attr in all_attrs if attr.startswith('customfield_')] | ||
self.assertGreater(len(custom_field_ids), 0) | ||
|
||
standard_and_custom = set(standard_fields + custom_field_ids + | ||
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', | ||
'__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', | ||
'__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', | ||
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', | ||
'__str__', '__subclasshook__', '__weakref__', '_issue_session', | ||
'aggregateprogress', 'aggregatetimeestimate', 'aggregatetimeoriginalestimate', | ||
'aggregatetimespent', 'archivedby', 'archiveddate', 'assignee', 'attachment', | ||
'comment', 'components', 'created', 'creator', 'description', 'duedate', | ||
'environment', 'fixVersions', 'issuelinks', 'labels', 'lastViewed', | ||
'progress', 'project', 'reporter', 'resolution', 'resolutiondate', | ||
'security', 'subtasks', 'timeestimate', 'timeoriginalestimate', | ||
'timespent', 'timetracking', 'updated', 'versions', 'votes', | ||
'watches', 'worklog', 'workratio']) | ||
|
||
display_name_fields = [attr for attr in all_attrs if attr not in standard_and_custom] | ||
self.assertGreater(len(display_name_fields), 0) | ||
|
||
def test_issue_creation_with_display_names(self): | ||
fresh_issue = self.jira.issue(self.issue_1) | ||
|
||
all_attrs = dir(fresh_issue.fields) | ||
custom_fields = [attr for attr in all_attrs if attr.startswith('customfield_')] | ||
|
||
expected_display_names = len(custom_fields) > 0 | ||
|
||
if expected_display_names: | ||
standard_and_meta_fields = { | ||
'__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', | ||
'__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', | ||
'__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', | ||
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', | ||
'__str__', '__subclasshook__', '__weakref__', '_issue_session', | ||
'aggregateprogress', 'aggregatetimeestimate', 'aggregatetimeoriginalestimate', | ||
'aggregatetimespent', 'archivedby', 'archiveddate', 'assignee', 'attachment', | ||
'comment', 'components', 'created', 'creator', 'description', 'duedate', | ||
'environment', 'fixVersions', 'issuelinks', 'issuetype', 'labels', 'lastViewed', | ||
'priority', 'progress', 'project', 'reporter', 'resolution', 'resolutiondate', | ||
'security', 'status', 'subtasks', 'summary', 'timeestimate', | ||
'timeoriginalestimate', 'timespent', 'timetracking', 'updated', | ||
'versions', 'votes', 'watches', 'worklog', 'workratio' | ||
} | ||
|
||
potential_display_names = [ | ||
attr for attr in all_attrs | ||
if attr not in standard_and_meta_fields and not attr.startswith('customfield_') | ||
] | ||
|
||
self.assertGreater(len(potential_display_names), 0) | ||
|
||
|
||
if __name__ == '__main__': | ||
import unittest | ||
unittest.main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a hack to me, but I could not find a way to access _fields_cache from resources directly, but I would love to be pointed in the 'right' way to do it.