Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
Fix test url, cleanup hooks (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrews authored Nov 5, 2023
1 parent ebf6099 commit c4bb9fb
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 49 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
uses: actions/setup-python@v4
- name: Install dependencies
run: python -m pip install .[lint]
- name: black
run: black --check .
- name: ruff
run: ruff check .
test:
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![This is Gemini Control. We're at T-1 minute, T-60 seconds and counting. T-45 seconds and counting. The range holding a final status check. T-30 seconds. Recorders have gone to fast speed. Twenty seconds. Fifteen seconds. Ten, nine, eight, seven, six, five, four, three, two, one zero. Ignition.](docs/img/transcript-1.png)

Ignition is a simple but powerful transport library for Python3 clients using the recently designed [Gemini protocol](https://gemini.circumlunar.space/). This project intends to implement all of the [transport specifications](https://gemini.circumlunar.space/docs/specification.html) (sections 1-4) of the Gemini protocol and provide an easy-to-use interface, so as to act as a building block in a larger application.
Ignition is a simple but powerful transport library for Python3 clients using the recently designed [Gemini protocol](https://geminiprotocol.net/). This project intends to implement all of the [transport specifications](https://geminiprotocol.net/docs/specification.gmi) (sections 1-4) of the Gemini protocol and provide an easy-to-use interface, so as to act as a building block in a larger application.

If you're building a Python3 application that uses Gemini, Ignition is your gateway to the stars, in very much the same way that [requests](https://requests.readthedocs.io/en/master/) is for HTTP and **gopherlib** is for Gopher.

Expand Down Expand Up @@ -45,7 +45,7 @@ The most basic usage of Ignition allows the user to create a request and get a r
import ignition

# Fetch capsule content
response = ignition.request('//gemini.circumlunar.space')
response = ignition.request('//geminiprotocol.net')

# Get status from remote capsule
print(response.status)
Expand Down Expand Up @@ -90,10 +90,10 @@ More advanced request usage:
```python
import ignition

response = ignition.request('/software', referer='//gemini.circumlunar.space:1965')
response = ignition.request('/software', referer='//geminiprotocol.net:1965')

print("Got back response %s from %s" % (response.status, response.url))
# Got back a response 20 from gemini://gemini.circumlunar.space/software
# Got back a response 20 from gemini://geminiprotocol.net/software

if not response.success():
print("There was an error on the response.")
Expand All @@ -105,7 +105,7 @@ Passing a referer:
```python
import ignition

response1 = ignition.request('//gemini.circumlunar.space')
response1 = ignition.request('//geminiprotocol.net')
response2 = ignition.request('software', referer=response1.url)

print(response2)
Expand All @@ -116,7 +116,7 @@ More advanced response validation:
```python
import ignition

url = '//gemini.circumlunar.space'
url = '//geminiprotocol.net'
response = ignition.request(url)

if response.is_a(ignition.SuccessResponse):
Expand Down Expand Up @@ -167,7 +167,7 @@ Ignition is licensed under [Mozilla Public License 2.0](https://www.mozilla.org/
Copyright 2020-2022 by [Chris Brousseau](https://github.com/cbrews).

## Thank you
* *solderpunk* for leading the design of the [Gemini protocol](https://gemini.circumlunar.space/docs/specification.html), without which this project would not have been possible.
* *solderpunk* for leading the design of the [Gemini protocol](https://geminiprotocol.net/docs/specification.html), without which this project would not have been possible.
* *Sean Conman* for writing the [Gemini torture tests](gemini://gemini.conman.org/test/torture), which were instrumental in initial client testing.
* *Michael Lazar* for his work on [Jetforce](https://github.com/michael-lazar/jetforce), which helped testing along the way.

Expand Down
8 changes: 4 additions & 4 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@ This allows for the bulk of URL generation logic to be handled without ignition

*Use Case 1: Automatically populate URL protocol*
```python
ignition.url('//gemini.circumlunar.space') # => gemini://gemini.circumlunar.space
ignition.url('//geminiprotocol.net') # => gemini://geminiprotocol.net
```

*Use Case 2: Navigate to an absolute path*
```python
ignition.url('/home', 'gemini://gemini.circumlunar.space') # => gemini://gemini.circumlunar.space/home
ignition.url('/home', 'gemini://geminiprotocol.net') # => gemini://geminiprotocol.net/home
```

*Use Case 3: Navigate to a relative path*
```python
ignition.url('2', 'gemini://gemini.circumlunar.space/home') # => gemini://gemini.circumlunar.space/home/2
ignition.url('2', 'gemini://geminiprotocol.net/home') # => gemini://geminiprotocol.net/home/2
```

*Use Case 4: Resolve paths with navigation*
```python
ignition.url('../fun/', 'gemini://gemini.circumlunar.space/home/work/') # => gemini://gemini.circumlunar.space/home/fun/
ignition.url('../fun/', 'gemini://geminiprotocol.net/home/work/') # => gemini://geminiprotocol.net/home/fun/
```

*Note:* if the user's intent is to generate a url to a Gemini capsule and then make a request, ignition recommends that you just provide the *url* and *referer* to `ignition.request()`, as that function encapsulates all of the logic within this method when making a request. If you want to retrieve a URL from an already processed request, it is recommended to use `ignition.BaseResponse.url`, as that will store the URL that was actually used. This method is only intended for use in constructing a URL but not generating a request.
Expand Down
2 changes: 1 addition & 1 deletion docs/developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This section is for software developers who are interested in contributing to th

### Local Environment Setup

I recommend using `pyenv` and `virtualenv` locally to manage your python environment. When you `cd` into the `ignition` directory you should be able to run:
I recommend using `pyenv` and `virtualenv` locally to manage your python environment. Once you have [pyenv](https://github.com/pyenv/pyenv) installed (with [shell extensions](https://github.com/pyenv/pyenv#set-up-your-shell-environment-for-pyenv)), you can `cd` into the `ignition` directory you should be able to run:
```bash
$ python --version
Python 3.10.4
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import ignition

url = "//gemini.circumlunar.space"
url = "//geminiprotocol.net/"
response = ignition.request(url)

if response.is_a(ignition.SuccessResponse):
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import ignition

# Fetch capsule content
response = ignition.request("//gemini.circumlunar.space")
response = ignition.request("//geminiprotocol.net/")

# Get status from remote capsule
print(response.status)
Expand Down
4 changes: 2 additions & 2 deletions examples/using_referer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import ignition

response1 = ignition.request("//gemini.circumlunar.space")
response2 = ignition.request("software", referer=response1.url)
response1 = ignition.request("//geminiprotocol.net/")
response2 = ignition.request("software/", referer=response1.url)

print(response2)
8 changes: 4 additions & 4 deletions ignition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,22 @@ def url(request_url, referer=None):
*Use Case 1: Automatically populate URL protocol*
```python
ignition.url('//gemini.circumlunar.space') # => gemini://gemini.circumlunar.space
ignition.url('//geminiprotocol.net') # => gemini://geminiprotocol.net
```
*Use Case 2: Navigate to an absolute path*
```python
ignition.url('/home', 'gemini://gemini.circumlunar.space') # => gemini://gemini.circumlunar.space/home
ignition.url('/home', 'gemini://geminiprotocol.net') # => gemini://geminiprotocol.net/home
```
*Use Case 3: Navigate to a relative path*
```python
ignition.url('2', 'gemini://gemini.circumlunar.space/home') # => gemini://gemini.circumlunar.space/home/2
ignition.url('2', 'gemini://geminiprotocol.net/home') # => gemini://geminiprotocol.net/home/2
```
*Use Case 4: Resolve paths with navigation*
```python
ignition.url('../fun/', 'gemini://gemini.circumlunar.space/home/work/') # => gemini://gemini.circumlunar.space/home/fun/
ignition.url('../fun/', 'gemini://geminiprotocol.net/home/work/') # => gemini://geminiprotocol.net/home/fun/
```
*Note:* if the user's intent is to generate a url to a Gemini capsule and then make a request,
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ include = [
'/ignition',
]

[tool.black]
exclude = "ignition/python"

[tool.ruff]
select = [
"I", # isort
Expand Down
4 changes: 0 additions & 4 deletions tests/test_ignition.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def test_request(mock_request):


def test_request_with_values(mock_request):

ignition.request(
"path", referer="//test", timeout=10, raise_errors=True, ca_cert="string"
)
Expand All @@ -81,7 +80,6 @@ def test_request_with_values(mock_request):


def test_request_with_default_timeout(mock_request):

ignition.set_default_timeout(9)
ignition.request("//test")

Expand All @@ -102,7 +100,6 @@ def test_request_with_default_timeout(mock_request):


def test_request_with_overloaded_timeout(mock_request):

ignition.set_default_timeout(8)
ignition.request("//test", timeout=12)

Expand All @@ -123,7 +120,6 @@ def test_request_with_overloaded_timeout(mock_request):


def test_request_with_hosts_file(mock_request):

ignition.set_default_hosts_file(".my_hosts_file")
ignition.request("//test")

Expand Down
4 changes: 2 additions & 2 deletions tests/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from ignition.request import Request

request = Request(
"software/", referer="gemini://gemini.circumlunar.space/", request_timeout=30
"software/", referer="gemini://geminiprotocol.net/", request_timeout=30
)


def test_get_url():
assert request.get_url() == "gemini://gemini.circumlunar.space/software/"
assert request.get_url() == "gemini://geminiprotocol.net/software/"


def test_send():
Expand Down
44 changes: 21 additions & 23 deletions tests/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,39 @@
@pytest.mark.parametrize(
"test_url",
[
"gemini://gemini.circumlunar.space/",
"//gemini.circumlunar.space/",
"gemini://gemini.circumlunar.space:1965/",
"//gemini.circumlunar.space:1965/",
" gemini://gemini.circumlunar.space:1965/",
" //gemini.circumlunar.space:1965/",
"gemini://geminiprotocol.net/",
"//geminiprotocol.net/",
"gemini://geminiprotocol.net:1965/",
"//geminiprotocol.net:1965/",
" gemini://geminiprotocol.net:1965/",
" //geminiprotocol.net:1965/",
],
)
def test_standard_gemini_url(test_url):
final_url = URL(test_url)
assert str(final_url) == "gemini://gemini.circumlunar.space/"
assert str(final_url) == "gemini://geminiprotocol.net/"
assert final_url.protocol() == "gemini://"
assert final_url.host() == "gemini.circumlunar.space"
assert final_url.host() == "geminiprotocol.net"
assert final_url.port() == 1965
assert final_url.path() == "/"
assert final_url.query() == ""


def test_url_with_different_scheme():
final_url = URL("https://gemini.circumlunar.space/")
assert str(final_url) == "https://gemini.circumlunar.space/"
final_url = URL("https://geminiprotocol.net/")
assert str(final_url) == "https://geminiprotocol.net/"
assert final_url.protocol() == "https://"
assert final_url.host() == "gemini.circumlunar.space"
assert final_url.host() == "geminiprotocol.net"
assert final_url.port() == 1965
assert final_url.path() == "/"
assert final_url.query() == ""


def test_url_with_nonstandard_port():
final_url = URL("gemini://gemini.circumlunar.space:80/")
assert str(final_url) == "gemini://gemini.circumlunar.space:80/"
final_url = URL("gemini://geminiprotocol.net:80/")
assert str(final_url) == "gemini://geminiprotocol.net:80/"
assert final_url.protocol() == "gemini://"
assert final_url.host() == "gemini.circumlunar.space"
assert final_url.host() == "geminiprotocol.net"
assert final_url.port() == 80
assert final_url.path() == "/"
assert final_url.query() == ""
Expand All @@ -55,34 +55,32 @@ def test_url_with_nonstandard_port():
@pytest.mark.parametrize("test_path", ["", "/", "/test/path.gmi"])
@pytest.mark.parametrize("test_query", ["", "abc", "user=name"])
def test_url_with_basic_paths_and_queries(test_path, test_query):
test_url = "gemini://gemini.circumlunar.space" + test_path
test_url = "gemini://geminiprotocol.net" + test_path
if test_query:
test_url += "?" + test_query

final_url = URL(test_url)

assert str(final_url) == test_url
assert final_url.protocol() == "gemini://"
assert final_url.host() == "gemini.circumlunar.space"
assert final_url.host() == "geminiprotocol.net"
assert final_url.port() == 1965
assert final_url.path() == test_path
assert final_url.query() == test_query


def test_url_with_convoluted_path():
final_url = URL("gemini://gemini.circumlunar.space/test/./test2/../path.gmi")
assert str(final_url) == "gemini://gemini.circumlunar.space/test/path.gmi"
final_url = URL("gemini://geminiprotocol.net/test/./test2/../path.gmi")
assert str(final_url) == "gemini://geminiprotocol.net/test/path.gmi"
assert final_url.protocol() == "gemini://"
assert final_url.host() == "gemini.circumlunar.space"
assert final_url.host() == "geminiprotocol.net"
assert final_url.port() == 1965
assert final_url.path() == "/test/path.gmi"
assert final_url.query() == ""


def test_standard_gemini_url_with_referer():
final_url = URL(
"gemini://gus.guru/", referer_url="gemini://gemini.circumlunar.space/"
)
final_url = URL("gemini://gus.guru/", referer_url="gemini://geminiprotocol.net/")
assert str(final_url) == "gemini://gus.guru/"
assert final_url.protocol() == "gemini://"
assert final_url.host() == "gus.guru"
Expand All @@ -92,7 +90,7 @@ def test_standard_gemini_url_with_referer():


def test_url_without_scheme_with_referer():
final_url = URL("//gus.guru/", referer_url="gemini://gemini.circumlunar.space/")
final_url = URL("//gus.guru/", referer_url="gemini://geminiprotocol.net/")
assert str(final_url) == "gemini://gus.guru/"
assert final_url.protocol() == "gemini://"
assert final_url.host() == "gus.guru"
Expand Down

0 comments on commit c4bb9fb

Please sign in to comment.