Skip to content

Commit

Permalink
add from API test
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkhala committed Jan 21, 2025
1 parent 7714c7d commit 25981a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions py/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "davidkhala.gcp"
version = "0.0.5"
version = "0.1.0"
description = "@davidkhala/gcp: core gcp components"
authors = ["David Liu <[email protected]>"]
readme = "README.md"
Expand All @@ -15,7 +15,7 @@ auth = ["google-auth"]

[tool.poetry.group.dev.dependencies]
pytest = "*"
google-cloud-compute = "*"
google-cloud-language = "*"

[build-system]
requires = ["poetry-core"]
Expand Down
17 changes: 13 additions & 4 deletions py/tests/auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@ def test_from_service_account(self):
self.assertEqual(str(type(o.credentials)), "<class 'google.oauth2.service_account.Credentials'>")

def test_from_api_key(self):
from google.cloud.compute import RegionsClient
from google.cloud.language import LanguageServiceClient, Document
api_key = os.environ.get('API_KEY')
client = RegionsClient(
client = LanguageServiceClient(
client_options=AuthOptions.from_api_key(api_key)
)
for region in client.list(project='gcp-data-davidkhala'):
print(region.name)
text = "Hello, world!"
document = Document(
content=text, type_=Document.Type.PLAIN_TEXT
)

# Make a request to analyze the sentiment of the text.
sentiment = client.analyze_sentiment(
request={"document": document}
).document_sentiment

self.assertEqual(sentiment.score, sentiment.magnitude)


if __name__ == '__main__':
Expand Down

1 comment on commit 25981a8

@davidkhala
Copy link
Owner Author

Choose a reason for hiding this comment

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

close #12

Please sign in to comment.