def test_list_other_user_guides(db): user1, token1 = generate_user() user2, token2 = generate_user() with session_scope() as session: c_id = create_community(session, 0, 2, "Root node", [user1], [], None).id with pages_session(token1) as api: guide1_id = api.CreateGuide( pages_pb2.CreateGuideReq( title="dummy title", content="dummy content", address="dummy address", location=pages_pb2.Coordinate( lat=1, lng=1, ), parent_community_id=c_id, )).page_id guide2_id = api.CreateGuide( pages_pb2.CreateGuideReq( title="dummy title 2", content="dummy content 2", address="dummy address 2", location=pages_pb2.Coordinate( lat=1, lng=1, ), parent_community_id=c_id, )).page_id with pages_session(token2) as api: res = api.ListUserGuides(pages_pb2.ListUserGuidesReq(user_id=user1.id)) assert [p.page_id for p in res.guides] == [guide1_id, guide2_id]
def test_create_guide_errors(db): user, token = generate_user() with session_scope() as session: c_id = create_community(session, 0, 2, "Root node", [user], [], None).id with pages_session(token) as api: with pytest.raises(grpc.RpcError) as e: api.CreateGuide( pages_pb2.CreateGuideReq( title=None, content="dummy content", parent_community_id=c_id, )) assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT assert e.value.details() == errors.MISSING_PAGE_TITLE with pages_session(token) as api: with pytest.raises(grpc.RpcError) as e: api.CreateGuide( pages_pb2.CreateGuideReq( title="dummy title", content=None, parent_community_id=c_id, )) assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT assert e.value.details() == errors.MISSING_PAGE_CONTENT with pages_session(token) as api: with pytest.raises(grpc.RpcError) as e: api.CreateGuide( pages_pb2.CreateGuideReq( title="dummy title", content="dummy content", )) assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT assert e.value.details() == errors.MISSING_PAGE_PARENT with pages_session(token) as api: with pytest.raises(grpc.RpcError) as e: api.CreateGuide( pages_pb2.CreateGuideReq( title="dummy title", content="dummy content", parent_community_id=9999, )) assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT assert e.value.details() == errors.COMMUNITY_NOT_FOUND with pages_session(token) as api: with pytest.raises(grpc.RpcError) as e: api.CreateGuide( pages_pb2.CreateGuideReq( title="dummy title", content="dummy content", address="dummy address", parent_community_id=c_id, )) assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT assert e.value.details() == errors.INVALID_GUIDE_LOCATION with pages_session(token) as api: with pytest.raises(grpc.RpcError) as e: api.CreateGuide( pages_pb2.CreateGuideReq( title="dummy title", content="dummy content", location=pages_pb2.Coordinate( lat=1, lng=1, ), parent_community_id=c_id, )) assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT assert e.value.details() == errors.INVALID_GUIDE_LOCATION
def test_create_page_guide(db): user, token = generate_user() with session_scope() as session: c_id = create_community(session, 0, 2, "Root node", [user], [], None).id with pages_session(token) as api: time_before = now() res = api.CreateGuide( pages_pb2.CreateGuideReq( title="dummy title", content="dummy content", address="dummy address", location=pages_pb2.Coordinate( lat=1, lng=1, ), parent_community_id=c_id, )) assert res.title == "dummy title" assert res.type == pages_pb2.PAGE_TYPE_GUIDE assert res.content == "dummy content" assert res.address == "dummy address" assert res.location.lat == 1 assert res.location.lng == 1 assert res.slug == "dummy-title" assert time_before < to_aware_datetime(res.created) < now() assert time_before < to_aware_datetime(res.last_edited) < now() assert res.last_editor_user_id == user.id assert res.creator_user_id == user.id assert res.owner_user_id == user.id assert not res.owner_community_id assert not res.owner_group_id assert res.editor_user_ids == [user.id] assert res.can_edit assert res.can_moderate with pages_session(token) as api: time_before = now() res = api.CreateGuide( pages_pb2.CreateGuideReq( title="dummy title", content="dummy content", parent_community_id=c_id, )) assert res.title == "dummy title" assert res.type == pages_pb2.PAGE_TYPE_GUIDE assert res.content == "dummy content" assert not res.address assert not res.HasField("location") assert res.slug == "dummy-title" assert time_before < to_aware_datetime(res.created) < now() assert time_before < to_aware_datetime(res.last_edited) < now() assert res.last_editor_user_id == user.id assert res.creator_user_id == user.id assert res.owner_user_id == user.id assert not res.owner_community_id assert not res.owner_group_id assert res.editor_user_ids == [user.id] assert res.can_edit assert res.can_moderate