from kab_ingestion.github import GitHubConnector from kab_ingestion.sharepoint import SharePointConnector from kab_ingestion.models import ConnectorConfig, SyncCursor class Secrets: def get(self,r): return "token" class HTTP: def __init__(self, responses): self.responses=responses def request(self,*a,**k): return self.responses.pop(0) def gh(): c=ConnectorConfig("gh","t1","s",{"owner":"o","repo":"r","ref":"main"}) h=HTTP([{"tree":[{"type":"blob","path":"a.md","sha":"1"}]},{"content":"hello"}]) return GitHubConnector(h,Secrets()).full(c) def test_github_full(): docs,c=gh(); assert docs[0].mime_type=="text/markdown" and docs[0].acl.tenant_id=="t1" def test_github_scope_required(): try: GitHubConnector(HTTP([]),Secrets()).full(ConnectorConfig("x","t","s",{})); assert False except ValueError: assert True def test_sharepoint_full(): c=ConnectorConfig("sp","t1","s",{"site_id":"s","library_id":"l"}) item={"id":"i","name":"a.pdf","eTag":"e","webUrl":"u","@microsoft.graph.downloadUrl":"raw","file":{}} docs,_=SharePointConnector(HTTP([{"value":[item]},{"content":"pdf"}]),Secrets()).full(c); assert docs[0].mime_type=="application/pdf"