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) #278

Closed

Conversation

sourcery-ai[bot]
Copy link
Contributor

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

Pull Request #277 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.

@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.10%.

Quality metrics Before After Change
Complexity 2.05 ⭐ 2.00 ⭐ -0.05 👍
Method Length 47.60 ⭐ 47.60 ⭐ 0.00
Working memory 5.02 ⭐ 5.00 ⭐ -0.02 👍
Quality 78.49% 78.59% 0.10% 👍
Other metrics Before After Change
Lines 3031 3020 -11
Changed files Quality Before Quality After Quality Change
nuxeo/client.py 64.45% 🙂 64.82% 🙂 0.37% 👍
nuxeo/documents.py 81.88% ⭐ 82.10% ⭐ 0.22% 👍
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.61% ⭐ 83.61% ⭐ 0.00%
tests/manual/many_small_files.py 82.28% ⭐ 82.25% ⭐ -0.03% 👎

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: 96.32% // Head: 96.31% // Decreases project coverage by -0.00% ⚠️

Coverage data is based on head (ef81bb9) compared to base (f3c6477).
Patch coverage: 84.61% of modified lines in pull request are covered.

Additional details and impacted files
@@                            Coverage Diff                             @@
##           wip-NXPY-239-Fix-tests-cases-on-Python     #278      +/-   ##
==========================================================================
- Coverage                                   96.32%   96.31%   -0.01%     
==========================================================================
  Files                                          26       26              
  Lines                                        1633     1630       -3     
==========================================================================
- Hits                                         1573     1570       -3     
  Misses                                         60       60              
Flag Coverage Δ
unit 96.31% <84.61%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
nuxeo/documents.py 93.65% <33.33%> (ø)
nuxeo/client.py 99.43% <100.00%> (-0.01%) ⬇️
nuxeo/exceptions.py 100.00% <100.00%> (ø)
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.

@gitofanindya gitofanindya force-pushed the wip-NXPY-239-Fix-tests-cases-on-Python branch from 20587f9 to e2d0e88 Compare October 14, 2022 12:25
@sourcery-ai sourcery-ai bot force-pushed the sourcery/wip-NXPY-239-Fix-tests-cases-on-Python branch from 975e343 to c7ea555 Compare October 14, 2022 12:25
@gitofanindya gitofanindya force-pushed the wip-NXPY-239-Fix-tests-cases-on-Python branch from e2d0e88 to ab92fe2 Compare October 14, 2022 12:35
@sourcery-ai sourcery-ai bot force-pushed the sourcery/wip-NXPY-239-Fix-tests-cases-on-Python branch from c7ea555 to dcb28f1 Compare October 14, 2022 12:36
@gitofanindya gitofanindya force-pushed the wip-NXPY-239-Fix-tests-cases-on-Python branch from ab92fe2 to f4d7a70 Compare October 14, 2022 12:46
@sourcery-ai sourcery-ai bot force-pushed the sourcery/wip-NXPY-239-Fix-tests-cases-on-Python branch from dcb28f1 to 870ff51 Compare October 14, 2022 12:46
@gitofanindya gitofanindya force-pushed the wip-NXPY-239-Fix-tests-cases-on-Python branch from f4d7a70 to 835dc3c Compare October 14, 2022 12:59
@sourcery-ai sourcery-ai bot force-pushed the sourcery/wip-NXPY-239-Fix-tests-cases-on-Python branch from 870ff51 to 18fb5a3 Compare October 14, 2022 13:00
@gitofanindya gitofanindya force-pushed the wip-NXPY-239-Fix-tests-cases-on-Python branch from 835dc3c to 787eb05 Compare October 14, 2022 13:03
@sourcery-ai sourcery-ai bot force-pushed the sourcery/wip-NXPY-239-Fix-tests-cases-on-Python branch from 18fb5a3 to 211dade Compare October 14, 2022 13:04
@gitofanindya gitofanindya force-pushed the wip-NXPY-239-Fix-tests-cases-on-Python branch from 787eb05 to 4e9ede2 Compare October 14, 2022 13:19
@sourcery-ai sourcery-ai bot force-pushed the sourcery/wip-NXPY-239-Fix-tests-cases-on-Python branch from 211dade to 569e1ab Compare October 14, 2022 13:20
@gitofanindya gitofanindya force-pushed the wip-NXPY-239-Fix-tests-cases-on-Python branch from 4e9ede2 to d67d130 Compare October 14, 2022 13:38
@sourcery-ai sourcery-ai bot force-pushed the sourcery/wip-NXPY-239-Fix-tests-cases-on-Python branch from 569e1ab to 4fc4dd0 Compare October 14, 2022 13:38
WORKSPACE_TEST = WORKSPACE_ROOT + "/" + WORKSPACE_NAME
WORKSPACE_TEST = f"{WORKSPACE_ROOT}/{WORKSPACE_NAME}"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lines 4-4 refactored with the following changes:

Comment on lines -163 to +168
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("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_digester refactored with the following changes:

Comment on lines -195 to +198
params={"document": WORKSPACE_ROOT + "/Document"},
params={"document": f"{WORKSPACE_ROOT}/Document"},
)
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_execute 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 + "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:

file_out = filename + ".dl"
file_out = f"{filename}.dl"
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 download_file refactored with the following changes:

@gitofanindya gitofanindya force-pushed the wip-NXPY-239-Fix-tests-cases-on-Python branch from d67d130 to f3c6477 Compare October 14, 2022 13:59
@sourcery-ai sourcery-ai bot force-pushed the sourcery/wip-NXPY-239-Fix-tests-cases-on-Python branch from 4fc4dd0 to ef81bb9 Compare October 14, 2022 14:07
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 + "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:

file_out = filename + ".dl"
file_out = f"{filename}.dl"
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 download_file refactored with the following changes:

Base automatically changed from wip-NXPY-239-Fix-tests-cases-on-Python to master October 17, 2022 06:24
@sourcery-ai sourcery-ai bot closed this Oct 17, 2022
@sourcery-ai sourcery-ai bot deleted the sourcery/wip-NXPY-239-Fix-tests-cases-on-Python branch October 17, 2022 06:25
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

2 participants