Check in Cloud Job Discovery client code samples for python - #1546
Conversation
|
Still working on the samples. But I would like to know how to run local tests for my samples. |
|
I am working on the tests to those samples, however, I don't know how to run those '_test' files. Is there any guide? |
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
| from googleapiclient.discovery import build | ||
|
|
||
| client_service = build('jobs', 'v2') | ||
|
|
There was a problem hiding this comment.
You can remove these empty lines between code and region tag.
There was a problem hiding this comment.
I use pyformat -i -s 4 --recursive . to format my code. And it seems this is recommended.
Should I manually modify those files? Or it should be fine?
|
|
||
| import time | ||
|
|
||
| # [START instantiate] |
There was a problem hiding this comment.
For the region tag it might be better if you add the product name (job, maybe) as a prefix, i.e. use job_setup instead of setup.
There was a problem hiding this comment.
This is for tag consistence among different languages since TW prefer them in the same name. Do you think it is necessary to modify the tag?
| # [END instantiate] | ||
|
|
||
|
|
||
| # [START basic_company] |
There was a problem hiding this comment.
Maybe it's not necessary to declare a function here with a specific region tag. How about just specifying a company variable?
company = {
'display_name': 'Google',
'distributor_company_id': distributor_company_id,
'hq_location': '1600 Amphitheatre Parkway Mountain View, CA 94043'
}
You can use a fixed ID here as well I think.
There was a problem hiding this comment.
I could not use a fixed ID since creating an entity with same ID would lead to the failure of tests
There was a problem hiding this comment.
No. This function is required from doc site and I couldn't use the fixed ID due to our system.
| complete.companyName = company_name | ||
|
|
||
| results = complete.execute() | ||
| print('==========\n%s\n==========' % results) |
There was a problem hiding this comment.
The padding part ========== may not be necessary.
There was a problem hiding this comment.
Just want to make the output clear for customer. I could remove it if you think it is the better.
| body=company_to_be_created).execute() | ||
| print('==========\nCompany created: %s\n==========' % company_created) | ||
| return company_created | ||
| except HttpError as e: |
There was a problem hiding this comment.
Use the base error class (googleapiclient.errors.Error) would be better I think. Or you could just drop the try/except block and the let the error raise.
|
|
||
|
|
||
| # [START basic_job] | ||
| def generate_job_with_required_fields(company_name): |
There was a problem hiding this comment.
I feel that this can be a simple job variable as well.
There was a problem hiding this comment.
Just to distinguish this function from other generate job function such as generate_job_with_custom_attribute
|
|
||
| # [START batch_job_create] | ||
| def batch_job_create(client_service, company_name): | ||
| import base_job_sample |
There was a problem hiding this comment.
I understand your concern here; but for clarity I do feel that this part can be replaced with two simple job variables so that developers do not need to read another file to understand what's going on behind the scenes.
There was a problem hiding this comment.
It could be changed later since it request modifying the samples in all languages.
| job_to_be_updated = jobs_to_be_updated[index] | ||
| job_to_be_updated.update({'job_title': 'Engineer in Mountain View'}) | ||
| request = {'job': job_to_be_updated} | ||
| if index % 2 == 0: |
There was a problem hiding this comment.
This part might be a little bit confusing I think. If we are showing the batch updating method do we really need to showcase updating only half of the jobs and leaving the other half alone? We can just update all of them.
There was a problem hiding this comment.
They want to have the updateRequest one with the field mask feature, one is not.
| pass | ||
|
|
||
| batch = client_service.new_batch_http_request() | ||
| for index in range(0, len(jobs_to_be_updated)): |
There was a problem hiding this comment.
Side note: if you switch to updating all jobs instead, this part can become for job in jobs, which is easier to understand and more idiomatic for Python devs.
There was a problem hiding this comment.
I know. However, as mentioned above, they want half jobs updated using field mask feature, and half not.
| pass | ||
|
|
||
| batch = client_service.new_batch_http_request() | ||
| for index in range(0, len(jobs_to_be_deleted)): |
There was a problem hiding this comment.
The index is not necessary though; how about for job in jobs?
| @@ -0,0 +1,36 @@ | |||
| # This file must be used with "source bin/activate.csh" *from csh*. | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1,11 @@ | |||
| #!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1,11 @@ | |||
| #!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1,11 @@ | |||
| #!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1,11 @@ | |||
| #!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1 @@ | |||
| {"last_check":"2018-07-16T22:25:20Z","pypi_version":"10.0.1"} No newline at end of file | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1 @@ | |||
| /usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/include No newline at end of file | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1 @@ | |||
| /usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin No newline at end of file | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1 @@ | |||
| /usr/include/python2.7 No newline at end of file | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1,11 @@ | |||
| #!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1 @@ | |||
| python No newline at end of file | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1 @@ | |||
| python No newline at end of file | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1,78 @@ | |||
| #!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1,11 @@ | |||
| #!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1,11 @@ | |||
| #!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1,11 @@ | |||
| #!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1,11 @@ | |||
| #!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1,11 @@ | |||
| #!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1,11 @@ | |||
| #!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python | |||
There was a problem hiding this comment.
Please remove this file from the commit.
| @@ -0,0 +1,11 @@ | |||
| #!/usr/local/google/home/xinyunh/githubCode/pythonPersonalFork/python-docs-samples/jobs/env/bin/python | |||
There was a problem hiding this comment.
Please remove this file from the commit.
michaelawyu
left a comment
There was a problem hiding this comment.
PTAL at the comments.
|
How could I add cla:yes back? |
|
|
||
| # [START instantiate] | ||
| from googleapiclient.discovery import build | ||
|
|
There was a problem hiding this comment.
Please remove extra empty line(s) throughout the code.
CJD got Public beta launch so we would like to have our samples checked in as other projects.