vinissimus / async-asgi-testclient

A framework-agnostic library for testing ASGI web applications
MIT License
159 stars 20 forks source link

Add client (remote peer) to scope #21

Closed aviramha closed 4 years ago

aviramha commented 4 years ago

FastAPI provides the key client in the scope for accessing ip,port tuple of the request origin. I lacked it for my tests, so added and think it might be usable for someone else.

P.S: Great repo, exactly what I lacked :)

codecov-io commented 4 years ago

Codecov Report

Merging #21 into master will increase coverage by 0.09%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #21      +/-   ##
==========================================
+ Coverage   83.77%   83.87%   +0.09%     
==========================================
  Files           5        5              
  Lines         339      341       +2     
==========================================
+ Hits          284      286       +2     
  Misses         55       55
Impacted Files Coverage Δ
async_asgi_testclient/testing.py 86.75% <100%> (+0.17%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 5f9df31...09cfb39. Read the comment docs.

masipcat commented 4 years ago

Hi, thank you for your PR!

I'd prefer to make this optional ("client": None by default, to avoid confusion), and make it customizable in the TestClient constructor. Something like:

class TestClient:
    def __init__(self, ..., scope_client: Optional[List] = None):
        self.scope_client = scope_client

and then use the self.scope_client in the scope.

aviramha commented 4 years ago

FastAPI/Starlette always has this value (so I assume it's more comfortable), but I don't mind making this optional :)

aviramha commented 4 years ago

I noticed that there are more scope stuff missing, so I made this more robust. Please tell me what you think

masipcat commented 4 years ago

Released 1.2.1