Skip to content

Commit

Permalink
Merge b53b3f6 into 3001b70
Browse files Browse the repository at this point in the history
  • Loading branch information
mldzs committed Apr 7, 2021
2 parents 3001b70 + b53b3f6 commit d85dd66
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
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;
}

0 comments on commit d85dd66

Please sign in to comment.