Coverage for src/couchers/servicers/reporting.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-12-20 18:03 +0000

1import grpc 

2from google.protobuf import empty_pb2 

3 

4from couchers import errors 

5from couchers.models import ContentReport, User 

6from couchers.sql import couchers_select as select 

7from couchers.tasks import send_content_report_email 

8from proto import reporting_pb2_grpc 

9 

10 

11class Reporting(reporting_pb2_grpc.ReportingServicer): 

12 def Report(self, request, context, session): 

13 # note no filtering on visibility 

14 author_user = session.execute(select(User).where_username_or_id(request.author_user)).scalar_one_or_none() 

15 

16 if not author_user: 

17 context.abort(grpc.StatusCode.NOT_FOUND, errors.USER_NOT_FOUND) 

18 

19 content_report = ContentReport( 

20 reporting_user_id=context.user_id, 

21 reason=request.reason, 

22 description=request.description, 

23 content_ref=request.content_ref, 

24 author_user=author_user, 

25 user_agent=request.user_agent, 

26 page=request.page, 

27 ) 

28 

29 session.add(content_report) 

30 session.flush() 

31 

32 send_content_report_email(session, content_report) 

33 

34 return empty_pb2.Empty()