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

update repository proto. Add filter by name to repository #566

Merged
merged 3 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ before_script:
- psql -U bothub postgres -c "CREATE DATABASE bothub;"
- python -m grpc_tools.protoc --experimental_allow_proto3_optional --proto_path=./ --python_out=./ --grpc_python_out=./ ./bothub/protos/authentication.proto
- python -m grpc_tools.protoc --experimental_allow_proto3_optional --proto_path=./ --python_out=./ --grpc_python_out=./ ./bothub/protos/organization.proto
- python -m grpc_tools.protoc --experimental_allow_proto3_optional --proto_path=./ --python_out=./ --grpc_python_out=./ ./bothub/protos/repository.proto

install:
- pip install pipenv
Expand Down
3 changes: 3 additions & 0 deletions bothub/api/grpc/repository/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class RepositoryService(mixins.ListModelMixin, generics.GenericService):

def filter_queryset(self, queryset):
org_id = self.request.org_id

queryset = queryset.filter(name=self.request.name)

if org_id:
queryset = queryset.filter(authorizations__user__pk=org_id)

Expand Down
23 changes: 19 additions & 4 deletions bothub/api/grpc/repository/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

from bothub.api.v2.tests.utils import create_user_and_token
from bothub.common import languages
from bothub.common.models import Repository, Organization, OrganizationAuthorization
from bothub.common.models import (
Repository,
Organization,
OrganizationAuthorization,
RepositoryAuthorization,
)
from bothub.protos import repository_pb2_grpc, repository_pb2


Expand All @@ -25,8 +30,16 @@ def setUp(self):
owner=self.organization.repository_owner,
)

self.repository_authorization = RepositoryAuthorization.objects.create(
user=self.organization.repository_owner,
repository=self.repository,
role=RepositoryAuthorization.LEVEL_ADMIN,
)

def test_list(self):
response_grpc = self.stub.List(repository_pb2.RepositoryListRequest())
response_grpc = self.stub.List(
repository_pb2.RepositoryListRequest(name=self.repository.name)
)
repositories_from_response_grpc = [repository_ for repository_ in response_grpc]

self.assertEqual(len(repositories_from_response_grpc), 1)
Expand All @@ -35,7 +48,7 @@ def test_list(self):
def test_list_with_filter_by_owner_id(self):
response_grpc = self.stub.List(
repository_pb2.RepositoryListRequest(
owner_id=self.organization.repository_owner.pk
name=self.repository.name, org_id=self.organization.repository_owner.pk
)
)
repositories_from_response_grpc = [repository_ for repository_ in response_grpc]
Expand All @@ -44,7 +57,9 @@ def test_list_with_filter_by_owner_id(self):
self.assertTrue(repositories_from_response_grpc[0].name, self.repository.name)

response_grpc = self.stub.List(
repository_pb2.RepositoryListRequest(owner_id=100) # random id
repository_pb2.RepositoryListRequest(
name=self.repository.name, org_id=100
) # random id
)
repositories_from_response_grpc = [repository_ for repository_ in response_grpc]

Expand Down
5 changes: 2 additions & 3 deletions bothub/protos/repository.proto
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
syntax = "proto3";

package repository;

import "google/protobuf/empty.proto";
package weni.bothub.repository;

service RepositoryController {
rpc List(RepositoryListRequest) returns (stream Repository) {}
Expand Down Expand Up @@ -43,4 +41,5 @@ message Category {

message RepositoryListRequest {
optional int32 org_id = 1;
string name = 2;
}