From a001991372757840f622007cadf52f964eb8895b Mon Sep 17 00:00:00 2001 From: Jonathan Mieldazis Date: Wed, 7 Apr 2021 11:54:29 -0300 Subject: [PATCH 1/3] update repository proto. Add filter by name to repository --- bothub/api/grpc/repository/services.py | 3 +++ bothub/api/grpc/repository/tests.py | 20 ++++++++++++++++---- bothub/protos/repository.proto | 5 ++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/bothub/api/grpc/repository/services.py b/bothub/api/grpc/repository/services.py index b83700dbf..d5f5ff539 100644 --- a/bothub/api/grpc/repository/services.py +++ b/bothub/api/grpc/repository/services.py @@ -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) diff --git a/bothub/api/grpc/repository/tests.py b/bothub/api/grpc/repository/tests.py index 0b89e771d..22cadf49a 100644 --- a/bothub/api/grpc/repository/tests.py +++ b/bothub/api/grpc/repository/tests.py @@ -2,7 +2,7 @@ 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 @@ -25,8 +25,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) @@ -35,7 +43,8 @@ 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] @@ -44,7 +53,10 @@ 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] diff --git a/bothub/protos/repository.proto b/bothub/protos/repository.proto index 82eabf6ac..9a39bb467 100644 --- a/bothub/protos/repository.proto +++ b/bothub/protos/repository.proto @@ -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) {} @@ -43,4 +41,5 @@ message Category { message RepositoryListRequest { optional int32 org_id = 1; + string name = 2; } From 6570ed7f8dc30ffc4664388e02b0fdf99dd76da7 Mon Sep 17 00:00:00 2001 From: Jonathan Mieldazis Date: Wed, 7 Apr 2021 11:56:04 -0300 Subject: [PATCH 2/3] run black --- bothub/api/grpc/repository/tests.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/bothub/api/grpc/repository/tests.py b/bothub/api/grpc/repository/tests.py index 22cadf49a..5ef7fae11 100644 --- a/bothub/api/grpc/repository/tests.py +++ b/bothub/api/grpc/repository/tests.py @@ -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, RepositoryAuthorization +from bothub.common.models import ( + Repository, + Organization, + OrganizationAuthorization, + RepositoryAuthorization, +) from bothub.protos import repository_pb2_grpc, repository_pb2 @@ -28,13 +33,13 @@ def setUp(self): self.repository_authorization = RepositoryAuthorization.objects.create( user=self.organization.repository_owner, repository=self.repository, - role=RepositoryAuthorization.LEVEL_ADMIN + role=RepositoryAuthorization.LEVEL_ADMIN, ) def test_list(self): - response_grpc = self.stub.List(repository_pb2.RepositoryListRequest( - name=self.repository.name - )) + 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) @@ -43,8 +48,7 @@ def test_list(self): def test_list_with_filter_by_owner_id(self): response_grpc = self.stub.List( repository_pb2.RepositoryListRequest( - name=self.repository.name, - org_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] @@ -54,8 +58,7 @@ def test_list_with_filter_by_owner_id(self): response_grpc = self.stub.List( repository_pb2.RepositoryListRequest( - name=self.repository.name, - org_id=100 + name=self.repository.name, org_id=100 ) # random id ) repositories_from_response_grpc = [repository_ for repository_ in response_grpc] From b53b3f68f768c6611ad443aeac1d0393591281f1 Mon Sep 17 00:00:00 2001 From: Jonathan Mieldazis Date: Wed, 7 Apr 2021 13:40:36 -0300 Subject: [PATCH 3/3] update travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 692cdb5b6..b3fb7dc08 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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