-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32ac5c9
commit 266e3cd
Showing
11 changed files
with
369 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -14,3 +14,4 @@ parts: | |
charm: | ||
charm-binary-python-packages: | ||
- psycopg[binary] | ||
- PyYAML |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
199 changes: 199 additions & 0 deletions
199
vm_operator/lib/ratings_api/ratings_features_user_pb2_grpc.py
This file contains 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,199 @@ | ||
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! | ||
"""Client and server classes corresponding to protobuf-defined services.""" | ||
import grpc | ||
|
||
from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2 | ||
import ratings_features_user_pb2 as ratings__features__user__pb2 | ||
|
||
|
||
class UserStub(object): | ||
"""Missing associated documentation comment in .proto file.""" | ||
|
||
def __init__(self, channel): | ||
"""Constructor. | ||
Args: | ||
channel: A grpc.Channel. | ||
""" | ||
self.Authenticate = channel.unary_unary( | ||
'/ratings.features.user.User/Authenticate', | ||
request_serializer=ratings__features__user__pb2.AuthenticateRequest.SerializeToString, | ||
response_deserializer=ratings__features__user__pb2.AuthenticateResponse.FromString, | ||
) | ||
self.Delete = channel.unary_unary( | ||
'/ratings.features.user.User/Delete', | ||
request_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString, | ||
response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString, | ||
) | ||
self.Vote = channel.unary_unary( | ||
'/ratings.features.user.User/Vote', | ||
request_serializer=ratings__features__user__pb2.VoteRequest.SerializeToString, | ||
response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString, | ||
) | ||
self.ListMyVotes = channel.unary_unary( | ||
'/ratings.features.user.User/ListMyVotes', | ||
request_serializer=ratings__features__user__pb2.ListMyVotesRequest.SerializeToString, | ||
response_deserializer=ratings__features__user__pb2.ListMyVotesResponse.FromString, | ||
) | ||
self.GetSnapVotes = channel.unary_unary( | ||
'/ratings.features.user.User/GetSnapVotes', | ||
request_serializer=ratings__features__user__pb2.GetSnapVotesRequest.SerializeToString, | ||
response_deserializer=ratings__features__user__pb2.GetSnapVotesResponse.FromString, | ||
) | ||
|
||
|
||
class UserServicer(object): | ||
"""Missing associated documentation comment in .proto file.""" | ||
|
||
def Authenticate(self, request, context): | ||
"""Missing associated documentation comment in .proto file.""" | ||
context.set_code(grpc.StatusCode.UNIMPLEMENTED) | ||
context.set_details('Method not implemented!') | ||
raise NotImplementedError('Method not implemented!') | ||
|
||
def Delete(self, request, context): | ||
"""Missing associated documentation comment in .proto file.""" | ||
context.set_code(grpc.StatusCode.UNIMPLEMENTED) | ||
context.set_details('Method not implemented!') | ||
raise NotImplementedError('Method not implemented!') | ||
|
||
def Vote(self, request, context): | ||
"""Missing associated documentation comment in .proto file.""" | ||
context.set_code(grpc.StatusCode.UNIMPLEMENTED) | ||
context.set_details('Method not implemented!') | ||
raise NotImplementedError('Method not implemented!') | ||
|
||
def ListMyVotes(self, request, context): | ||
"""Missing associated documentation comment in .proto file.""" | ||
context.set_code(grpc.StatusCode.UNIMPLEMENTED) | ||
context.set_details('Method not implemented!') | ||
raise NotImplementedError('Method not implemented!') | ||
|
||
def GetSnapVotes(self, request, context): | ||
"""Missing associated documentation comment in .proto file.""" | ||
context.set_code(grpc.StatusCode.UNIMPLEMENTED) | ||
context.set_details('Method not implemented!') | ||
raise NotImplementedError('Method not implemented!') | ||
|
||
|
||
def add_UserServicer_to_server(servicer, server): | ||
rpc_method_handlers = { | ||
'Authenticate': grpc.unary_unary_rpc_method_handler( | ||
servicer.Authenticate, | ||
request_deserializer=ratings__features__user__pb2.AuthenticateRequest.FromString, | ||
response_serializer=ratings__features__user__pb2.AuthenticateResponse.SerializeToString, | ||
), | ||
'Delete': grpc.unary_unary_rpc_method_handler( | ||
servicer.Delete, | ||
request_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString, | ||
response_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString, | ||
), | ||
'Vote': grpc.unary_unary_rpc_method_handler( | ||
servicer.Vote, | ||
request_deserializer=ratings__features__user__pb2.VoteRequest.FromString, | ||
response_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString, | ||
), | ||
'ListMyVotes': grpc.unary_unary_rpc_method_handler( | ||
servicer.ListMyVotes, | ||
request_deserializer=ratings__features__user__pb2.ListMyVotesRequest.FromString, | ||
response_serializer=ratings__features__user__pb2.ListMyVotesResponse.SerializeToString, | ||
), | ||
'GetSnapVotes': grpc.unary_unary_rpc_method_handler( | ||
servicer.GetSnapVotes, | ||
request_deserializer=ratings__features__user__pb2.GetSnapVotesRequest.FromString, | ||
response_serializer=ratings__features__user__pb2.GetSnapVotesResponse.SerializeToString, | ||
), | ||
} | ||
generic_handler = grpc.method_handlers_generic_handler( | ||
'ratings.features.user.User', rpc_method_handlers) | ||
server.add_generic_rpc_handlers((generic_handler,)) | ||
|
||
|
||
# This class is part of an EXPERIMENTAL API. | ||
class User(object): | ||
"""Missing associated documentation comment in .proto file.""" | ||
|
||
@staticmethod | ||
def Authenticate(request, | ||
target, | ||
options=(), | ||
channel_credentials=None, | ||
call_credentials=None, | ||
insecure=False, | ||
compression=None, | ||
wait_for_ready=None, | ||
timeout=None, | ||
metadata=None): | ||
return grpc.experimental.unary_unary(request, target, '/ratings.features.user.User/Authenticate', | ||
ratings__features__user__pb2.AuthenticateRequest.SerializeToString, | ||
ratings__features__user__pb2.AuthenticateResponse.FromString, | ||
options, channel_credentials, | ||
insecure, call_credentials, compression, wait_for_ready, timeout, metadata) | ||
|
||
@staticmethod | ||
def Delete(request, | ||
target, | ||
options=(), | ||
channel_credentials=None, | ||
call_credentials=None, | ||
insecure=False, | ||
compression=None, | ||
wait_for_ready=None, | ||
timeout=None, | ||
metadata=None): | ||
return grpc.experimental.unary_unary(request, target, '/ratings.features.user.User/Delete', | ||
google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString, | ||
google_dot_protobuf_dot_empty__pb2.Empty.FromString, | ||
options, channel_credentials, | ||
insecure, call_credentials, compression, wait_for_ready, timeout, metadata) | ||
|
||
@staticmethod | ||
def Vote(request, | ||
target, | ||
options=(), | ||
channel_credentials=None, | ||
call_credentials=None, | ||
insecure=False, | ||
compression=None, | ||
wait_for_ready=None, | ||
timeout=None, | ||
metadata=None): | ||
return grpc.experimental.unary_unary(request, target, '/ratings.features.user.User/Vote', | ||
ratings__features__user__pb2.VoteRequest.SerializeToString, | ||
google_dot_protobuf_dot_empty__pb2.Empty.FromString, | ||
options, channel_credentials, | ||
insecure, call_credentials, compression, wait_for_ready, timeout, metadata) | ||
|
||
@staticmethod | ||
def ListMyVotes(request, | ||
target, | ||
options=(), | ||
channel_credentials=None, | ||
call_credentials=None, | ||
insecure=False, | ||
compression=None, | ||
wait_for_ready=None, | ||
timeout=None, | ||
metadata=None): | ||
return grpc.experimental.unary_unary(request, target, '/ratings.features.user.User/ListMyVotes', | ||
ratings__features__user__pb2.ListMyVotesRequest.SerializeToString, | ||
ratings__features__user__pb2.ListMyVotesResponse.FromString, | ||
options, channel_credentials, | ||
insecure, call_credentials, compression, wait_for_ready, timeout, metadata) | ||
|
||
@staticmethod | ||
def GetSnapVotes(request, | ||
target, | ||
options=(), | ||
channel_credentials=None, | ||
call_credentials=None, | ||
insecure=False, | ||
compression=None, | ||
wait_for_ready=None, | ||
timeout=None, | ||
metadata=None): | ||
return grpc.experimental.unary_unary(request, target, '/ratings.features.user.User/GetSnapVotes', | ||
ratings__features__user__pb2.GetSnapVotesRequest.SerializeToString, | ||
ratings__features__user__pb2.GetSnapVotesResponse.FromString, | ||
options, channel_credentials, | ||
insecure, call_credentials, compression, wait_for_ready, timeout, metadata) |
This file contains 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 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 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,12 @@ | ||
# Copyright 2021 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
from pytest import fixture | ||
from pytest_operator.plugin import OpsTest | ||
|
||
|
||
@fixture(scope="module") | ||
async def ratings_charm(ops_test: OpsTest): | ||
"""Ratings charm used for integration testing.""" | ||
charm = await ops_test.build_charm(".") | ||
return charm |
This file contains 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,63 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2022 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
import asyncio | ||
import secrets | ||
|
||
import grpc | ||
import ratings_api.ratings_features_user_pb2 as pb2 | ||
import ratings_api.ratings_features_user_pb2_grpc as pb2_grpc | ||
from pytest import mark | ||
from pytest_operator.plugin import OpsTest | ||
|
||
RATINGS = "ratings" | ||
UNIT_0 = f"{RATINGS}/0" | ||
DB = "db" | ||
|
||
|
||
@mark.abort_on_fail | ||
@mark.skip_if_deployed | ||
async def test_deploy(ops_test: OpsTest, ratings_charm): | ||
await ops_test.model.deploy(await ratings_charm, application_name=RATINGS) | ||
# issuing dummy update_status just to trigger an event | ||
async with ops_test.fast_forward(): | ||
await ops_test.model.wait_for_idle(apps=[RATINGS], status="active", timeout=1000) | ||
assert ops_test.model.applications[RATINGS].units[0].workload_status == "active" | ||
|
||
|
||
@mark.abort_on_fail | ||
async def test_database_relation(ops_test: OpsTest): | ||
"""Test that the charm can be successfully related to PostgreSQL.""" | ||
await asyncio.gather( | ||
ops_test.model.deploy("postgresql", channel="edge", application_name=DB, trust=True), | ||
ops_test.model.wait_for_idle( | ||
apps=[DB], status="active", raise_on_blocked=True, timeout=1000 | ||
), | ||
) | ||
|
||
await asyncio.gather( | ||
ops_test.model.integrate(RATINGS, DB), | ||
ops_test.model.wait_for_idle( | ||
apps=[RATINGS], status="active", raise_on_blocked=True, timeout=1000 | ||
), | ||
) | ||
|
||
|
||
@mark.abort_on_fail | ||
async def test_ratings_register_user(ops_test: OpsTest): | ||
"""End-to-end test to ensure the app can interact with the database.""" | ||
# Introduce a wait (e.g., 300 seconds or 5 minutes) | ||
status = await ops_test.model.get_status() # noqa: F821 | ||
unit = list(status.applications[RATINGS].units)[0] | ||
print(f"Connecting to address: {status}") | ||
address = status["applications"][RATINGS]["units"][unit]["public-address"] | ||
print(f"Connecting to address: {address}") | ||
connection_string = f"{address}:443" | ||
|
||
channel = grpc.insecure_channel(connection_string) | ||
stub = pb2_grpc.UserStub(channel) | ||
message = pb2.AuthenticateRequest(id=secrets.token_hex(32)) | ||
print(f"Message sent: {message}") | ||
response = stub.Authenticate(message) | ||
assert response.token |
Oops, something went wrong.