Skip to content
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

NXPY-239: Fix tests cases on Python (Sourcery refactored) #276

Conversation

sourcery-ai[bot]
Copy link
Contributor

@sourcery-ai sourcery-ai bot commented Oct 14, 2022

Pull Request #275 refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the wip-NXPY-239-Fix-tests-cases-on-Python branch, then run:

git fetch origin sourcery/wip-NXPY-239-Fix-tests-cases-on-Python
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Sourcery AI seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Comment on lines -110 to +118
"User-Agent": app_name + "/" + version,
"User-Agent": f"{app_name}/{version}",
"Accept": "application/json, */*",
}

self.schemas = kwargs.get("schemas", "*")
self.repository = kwargs.pop("repository", "default")
self._session = requests.sessions.Session()
self._session.hooks["response"] = [log_response]
cookies = kwargs.pop("cookies", None)
if cookies:
if cookies := kwargs.pop("cookies", None):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function NuxeoClient.__init__ refactored with the following changes:

Comment on lines -184 to +186
data.update(params)
data |= params

url = self.api_path + "/search/lang/NXQL/execute"
url = f"{self.api_path}/search/lang/NXQL/execute"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function NuxeoClient.query refactored with the following changes:

kwargs.update(self.client_kwargs)
kwargs |= self.client_kwargs
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function NuxeoClient.request refactored with the following changes:

Comment on lines -402 to +401
error_data.update(response.json())
error_data |= response.json()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function NuxeoClient._handle_error refactored with the following changes:

raise UnavailableBogusConvertor(
e.message, options["converter"] if options["converter"] else ""
)
raise UnavailableBogusConvertor(e.message, options["converter"] or "")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function API.convert refactored with the following changes:

Comment on lines -357 to +361
operation.params = {"document": WORKSPACE_ROOT + "/Document"}
operation.params = {"document": f"{WORKSPACE_ROOT}/Document"}
operation.input_obj = batch.get(0)
operation.execute()
doc = server.documents.get(path=WORKSPACE_ROOT + "/Document")
doc = server.documents.get(path=f"{WORKSPACE_ROOT}/Document")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_operation refactored with the following changes:

Comment on lines -430 to +441
operation.params = {"document": WORKSPACE_ROOT + "/Document"}
operation.params = {"document": f"{WORKSPACE_ROOT}/Document"}
operation.input_obj = batch.get(0)
operation.execute(void_op=True)

operation = server.operations.new("Document.Fetch")
operation.params = {"value": WORKSPACE_ROOT + "/Document"}
operation.params = {"value": f"{WORKSPACE_ROOT}/Document"}
info = operation.execute()
digest = info["properties"]["file:content"]["digest"]

operation = server.operations.new("Blob.Get")
operation.input_obj = WORKSPACE_ROOT + "/Document"
operation.input_obj = f"{WORKSPACE_ROOT}/Document"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_upload refactored with the following changes:

Comment on lines -484 to +495
operation.params = {"document": WORKSPACE_ROOT + "/Document"}
operation.params = {"document": f"{WORKSPACE_ROOT}/Document"}
operation.input_obj = batch.get(0)
operation.execute(void_op=True)

operation = server.operations.new("Document.Fetch")
operation.params = {"value": WORKSPACE_ROOT + "/Document"}
operation.params = {"value": f"{WORKSPACE_ROOT}/Document"}
info = operation.execute()
digest = info["properties"]["file:content"]["digest"]

operation = server.operations.new("Blob.Get")
operation.input_obj = WORKSPACE_ROOT + "/Document"
operation.input_obj = f"{WORKSPACE_ROOT}/Document"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_upload_several_callbacks refactored with the following changes:

self.url = nuxeo_url + "site/automation"
self.url = f"{nuxeo_url}site/automation"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ResponseAutomation.__init__ refactored with the following changes:

self.url = nuxeo_url + "small%20file.txt"
self.url = f"{nuxeo_url}small%20file.txt"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ResponseChunkedContents.__init__ refactored with the following changes:

self.url = nuxeo_url + "small%20file.txt"
self.url = f"{nuxeo_url}small%20file.txt"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ResponseChunkedJsonContents.__init__ refactored with the following changes:

self.url = nuxeo_url + "small%20file.txt"
self.url = f"{nuxeo_url}small%20file.txt"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ResponseChunkedJsonContentsTooLong.__init__ refactored with the following changes:

self.url = nuxeo_url + "json/cmis"
self.url = f"{nuxeo_url}json/cmis"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ResponseCmis.__init__ refactored with the following changes:

self.url = nuxeo_url + "nothing"
self.url = f"{nuxeo_url}nothing"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ResponseEmpty.__init__ refactored with the following changes:

self.url = nuxeo_url + "nothing"
self.url = f"{nuxeo_url}nothing"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ResponseError409.__init__ refactored with the following changes:

self.url = nuxeo_url + "8.3%20GiB.mxf"
self.url = f"{nuxeo_url}8.3%20GiB.mxf"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ResponseMxf.__init__ refactored with the following changes:

self.url = nuxeo_url + "big%20file.txt"
self.url = f"{nuxeo_url}big%20file.txt"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ResponseTextError.__init__ refactored with the following changes:

self.url = nuxeo_url + "small%20file.txt"
self.url = f"{nuxeo_url}small%20file.txt"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ResponseTextOk.__init__ refactored with the following changes:

self.url = nuxeo_url + "big%20file.txt"
self.url = f"{nuxeo_url}big%20file.txt"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ResponseTextTooLong.__init__ refactored with the following changes:

assert len(aces) in (2, 3)
assert len(aces) in {2, 3}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_fetch_acls refactored with the following changes:

@sourcery-ai
Copy link
Contributor Author

sourcery-ai bot commented Oct 14, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.09%.

Quality metrics Before After Change
Complexity 2.11 ⭐ 2.06 ⭐ -0.05 👍
Method Length 48.28 ⭐ 48.28 ⭐ 0.00
Working memory 5.05 ⭐ 5.03 ⭐ -0.02 👍
Quality 78.23% 78.32% 0.09% 👍
Other metrics Before After Change
Lines 3008 2997 -11
Changed files Quality Before Quality After Quality Change
nuxeo/client.py 64.45% 🙂 64.82% 🙂 0.37% 👍
nuxeo/documents.py 79.58% ⭐ 79.78% ⭐ 0.20% 👍
nuxeo/exceptions.py 93.15% ⭐ 93.25% ⭐ 0.10% 👍
nuxeo/models.py 92.31% ⭐ 92.44% ⭐ 0.13% 👍
nuxeo/utils.py 66.44% 🙂 66.24% 🙂 -0.20% 👎
tests/constants.py 96.17% ⭐ 96.01% ⭐ -0.16% 👎
tests/test_batchupload.py 66.70% 🙂 66.65% 🙂 -0.05% 👎
tests/test_log_response.py 93.50% ⭐ 93.41% ⭐ -0.09% 👎
tests/test_repository.py 83.59% ⭐ 83.59% ⭐ 0.00%

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
nuxeo/client.py NuxeoClient.request 14 🙂 307 ⛔ 16 ⛔ 30.76% 😞 Try splitting into smaller methods. Extract out complex expressions
nuxeo/utils.py version_compare 16 🙂 226 ⛔ 10 😞 41.75% 😞 Try splitting into smaller methods. Extract out complex expressions
tests/test_batchupload.py test_upload_several_callbacks 5 ⭐ 317 ⛔ 46.99% 😞 Try splitting into smaller methods
tests/test_batchupload.py test_idempotent_requests 5 ⭐ 300 ⛔ 47.77% 😞 Try splitting into smaller methods
nuxeo/utils.py log_response 10 🙂 163 😞 12 😞 48.26% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@codecov
Copy link

codecov bot commented Oct 14, 2022

Codecov Report

Base: 95.27% // Head: 95.33% // Increases project coverage by +0.05% 🎉

Coverage data is based on head (2def784) compared to base (2315933).
Patch coverage: 69.23% of modified lines in pull request are covered.

Additional details and impacted files
@@                            Coverage Diff                             @@
##           wip-NXPY-239-Fix-tests-cases-on-Python     #276      +/-   ##
==========================================================================
+ Coverage                                   95.27%   95.33%   +0.05%     
==========================================================================
  Files                                          26       26              
  Lines                                        1652     1649       -3     
==========================================================================
- Hits                                         1574     1572       -2     
+ Misses                                         78       77       -1     
Flag Coverage Δ
unit 95.33% <69.23%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
nuxeo/documents.py 86.89% <0.00%> (ø)
nuxeo/exceptions.py 94.89% <0.00%> (+0.95%) ⬆️
nuxeo/client.py 98.86% <100.00%> (-0.02%) ⬇️
nuxeo/models.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@sourcery-ai sourcery-ai bot closed this Oct 14, 2022
@sourcery-ai sourcery-ai bot deleted the sourcery/wip-NXPY-239-Fix-tests-cases-on-Python branch October 14, 2022 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant