You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/usage/configuration.md
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,6 +84,23 @@ If `trust_env` is set to `True`, githubkit (httpx) will look for the environment
84
84
85
85
If you want to set a proxy for client programmatically, you can pass a proxy URL to the `proxy` option. See [httpx's proxies documentation](https://www.python-httpx.org/advanced/proxies/) for more information.
86
86
87
+
### `transport`, `async_transport`
88
+
89
+
These two options let you provide a custom [HTTPX transport](https://www.python-httpx.org/advanced/transports/) for the underlying HTTP client.
90
+
91
+
They accept instances of the following types:
92
+
93
+
-`httpx.BaseTransport` (sync transport) — pass via the `transport` option.
94
+
-`httpx.AsyncBaseTransport` (async transport) — pass via the `async_transport` option.
95
+
96
+
When provided, githubkit will forward the transport to create the client. This is useful for:
97
+
98
+
- providing a custom network implementation;
99
+
- injecting test-only transports (for example `httpx.MockTransport`) to stub responses in unit tests;
100
+
- using alternative transports provided by HTTPX or third parties.
101
+
102
+
Note that if you pass `None` to the option, the default transport will be created by HTTPX.
103
+
87
104
### `cache_strategy`
88
105
89
106
The `cache_strategy` option defines how to cache the tokens or http responses. You can provide a githubkit built-in cache strategy or a custom one that implements the `BaseCacheStrategy` interface. By default, githubkit uses the `MemCacheStrategy` to cache the data in memory.
Copy file name to clipboardExpand all lines: docs/usage/unit-test.md
+68-1Lines changed: 68 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,10 @@
1
1
# Unit Test
2
2
3
-
If you are using githubkit in your business logic, you may want to mock the github API in your unit tests. You can custom the response by mocking the `request`/`arequest` method of the `GitHub` class. Here is an example of how to mock githubkit's API calls:
3
+
If you are using githubkit in your business logic, you may want to mock the github API in your unit tests. There are two ways to reach this.
4
+
5
+
## Mocking the API Calls
6
+
7
+
If you can't provide a githubkit test client to your business logic, you can mock the `request`/`arequest` method of the `GitHub` class to custom the response. Here is an example of how to mock githubkit's API calls:
4
8
5
9
=== "Sync"
6
10
@@ -106,3 +110,66 @@ If you are using githubkit in your business logic, you may want to mock the gith
106
110
1. Example function you want to test, which calls the GitHub API.
107
111
2. other request parameters including headers, json, etc.
108
112
3. When the request is made, return a fake response
113
+
114
+
## Using a Test Transport
115
+
116
+
You can also create a test client with mock transport and provide it to your business logic. Here is an example:
117
+
118
+
=== "Sync"
119
+
120
+
```python
121
+
import json
122
+
from pathlib import Path
123
+
124
+
import httpx
125
+
import pytest
126
+
127
+
from githubkit import GitHub
128
+
from githubkit.versions.latest.models import FullRepository
0 commit comments