-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements #233 (and kind-of tests it)
- Loading branch information
Showing
9 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ coverage | |
coveralls | ||
Jinja2 | ||
pip>=18.0 | ||
pproxy==2.2.0 | ||
pytest | ||
recommonmark | ||
Sphinx | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
geojson>=2.3.0,<3 | ||
PySocks==1.7.1,<2 | ||
requests>=2.20.0,<3 | ||
geojson>=2.3.0,<3 | ||
requests[socks] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"api_key": "b1b15e88fa797225412429c1c50c122a", | ||
"subscription_type": "free", | ||
"language": "en", | ||
"connection": { | ||
"use_ssl": true, | ||
"verify_ssl_certs": false, | ||
"use_proxy": true, | ||
"timeout_secs": 5 | ||
}, | ||
"proxies": { | ||
"http": "http://user:[email protected]:8899", | ||
"https": "https://user:[email protected]:8899" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"api_key": "b1b15e88fa797225412429c1c50c122a", | ||
"subscription_type": "free", | ||
"language": "en", | ||
"connection": { | ||
"use_ssl": true, | ||
"verify_ssl_certs": false, | ||
"use_proxy": true, | ||
"timeout_secs": 5 | ||
}, | ||
"proxies": { | ||
"http": "socks5://127.0.0.1:8899", | ||
"https": "socks5://127.0.0.1:8899" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIID5zCCAs+gAwIBAgIUWVG9t0QFZLIKXdt8PZl9dqsqdykwDQYJKoZIhvcNAQEL | ||
BQAwgYIxCzAJBgNVBAYTAklUMRIwEAYDVQQIDAlOZXZlcmxhbmQxFDASBgNVBAcM | ||
C0dvdGhhbSBDaXR5MQ0wCwYDVQQKDARBQ01FMQswCQYDVQQLDAJJVDELMAkGA1UE | ||
AwwCQ1MxIDAeBgkqhkiG9w0BCQEWEWNzcGFycGFAZ21haWwuY29tMB4XDTE5MTEx | ||
MzIxMDYzOVoXDTIwMTExMjIxMDYzOVowgYIxCzAJBgNVBAYTAklUMRIwEAYDVQQI | ||
DAlOZXZlcmxhbmQxFDASBgNVBAcMC0dvdGhhbSBDaXR5MQ0wCwYDVQQKDARBQ01F | ||
MQswCQYDVQQLDAJJVDELMAkGA1UEAwwCQ1MxIDAeBgkqhkiG9w0BCQEWEWNzcGFy | ||
cGFAZ21haWwuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAr+Fv | ||
FxgOqncbxHwTr8pcrEYwO/GXwRwvTD1vWgMjdX7kDSh3Mlgd6TdRvmaojtXaNAaf | ||
iTyrsPBS8LAPIZR+/8Fhxuc+tT5ClrJdK5XLM0Z3xhvAVyiwQOWxJwNapDD2cQ2W | ||
VbT6OorVAlLD9QjToGjCasx+eyL2hOVWAqK0funmHAytA1VzRVcv9ZzWZNWIvpp2 | ||
qkkznQyipIl/+Pub2GkeKXjSwzlfAYGFAWN9NcLxUn2NOw9+5FkPeg19YCGBmUJx | ||
KxLq2B8gjLLtd6TYgdreJSpAwsb1PPFTvF2J4EVfiY+NfQtwzDIhGva4FfLeCvHL | ||
qOEwYblx0pkRJ5swKwIDAQABo1MwUTAdBgNVHQ4EFgQUVvFAYKIXJLLje+RRC40A | ||
SCvlAPcwHwYDVR0jBBgwFoAUVvFAYKIXJLLje+RRC40ASCvlAPcwDwYDVR0TAQH/ | ||
BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAWXjbYM8G8E9M0LLu6a5HsHvOUCI6 | ||
SDA4XT09tWz5zgltHKj9WQzKTEi0ggO3LwUiTuJhhCMUL8S64lPPbNwUXpU8Mmmr | ||
dHn3F4hXPJfOClCfVK+VPf1wEgvjHx2ajxrac7N7NCGYhfblpWy4lVQWFoY3219J | ||
KKfeHKbIQjo2dmm2NyXzyBDWjcH3YPlNDUwr+fOhmMDAHS94Dlji/Cdpd25vPLj/ | ||
58/ZFkJ46PGEAcisvT9Rjylw1qo0LJ3xFzvWdS9vWThH3inBCUpeoyebdhlpljW8 | ||
da0N8MkhHMy3uZs70y/8xjtp5mO/pQjtzOijz9YV6uQs0zRoWHfGs3fT5Q== | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
import pathlib | ||
import unittest | ||
from pyowm import OWM | ||
from pyowm.weatherapi25.observation import Observation | ||
from pyowm.utils import config | ||
|
||
|
||
class TesIntegrationProxy(unittest.TestCase): | ||
|
||
_api_key = os.getenv('OWM_API_KEY', None) | ||
|
||
def test_call_api_behind_http_proxy(self): | ||
# fetch config and overwrite API Key as per env variable | ||
config_file_name = 'proxy_http.json' | ||
path = (pathlib.Path() / config_file_name).absolute() | ||
cfg = config.get_config_from(path) | ||
cfg['api_key'] = self._api_key | ||
|
||
# go | ||
owm = OWM(cfg['api_key'], cfg) | ||
wm = owm.weather_manager() | ||
result = wm.weather_at_place('London,GB') | ||
self.assertIsInstance(result, Observation) | ||
|
||
def test_call_api_behind_socks_proxy(self): | ||
# fetch config and overwrite API Key as per env variable | ||
config_file_name = 'proxy_socks.json' | ||
path = (pathlib.Path() / config_file_name).absolute() | ||
cfg = config.get_config_from(path) | ||
cfg['api_key'] = self._api_key | ||
|
||
# go | ||
owm = OWM(cfg['api_key'], cfg) | ||
wm = owm.weather_manager() | ||
result = wm.weather_at_place('London,GB') | ||
self.assertIsInstance(result, Observation) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[tox] | ||
envlist = | ||
py37, py38 | ||
skip_missing_interpreters = | ||
True | ||
skipsdist = True | ||
|
||
[testenv] | ||
passenv = OWM_API_KEY | ||
deps = -rproxyreqs.txt | ||
commands = pytest . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ -z "$OWM_API_KEY" ]; then | ||
echo "*** OWM_API_KEY env variable is not set: aborting" | ||
exit 1 | ||
fi | ||
|
||
export OWM_API_KEY | ||
|
||
cd proxy | ||
|
||
# Build one-off dependency file | ||
DEPS_FILE="$(readlink . -f)/proxyreqs.txt" | ||
echo 'pytest' | cat - ../../requirements.txt > $DEPS_FILE | ||
|
||
|
||
# Run proxy server | ||
PID_FILE="$(readlink . -f)/proxy.pid" | ||
export PID_FILE | ||
|
||
#proxy.py --num-workers 1 --hostname 127.0.0.1 --port 8899 --basic-auth user:pass --pid-file "$PID_FILE" > /dev/null 2>&1 & | ||
pproxy -l http+socks4+socks5://127.0.0.1:8899 --ssl selfsigned.crt > /dev/null 2>&1 & | ||
echo $$ >"$PID_FILE" | ||
|
||
# Run tests | ||
echo "*** Running tests... " | ||
tox | ||
|
||
|
||
# Shut down proxy | ||
echo "*** Killing proxy... " | ||
PID=$(cat $PID_FILE) | ||
rm "$PID_FILE" | ||
rm "$DEPS_FILE" | ||
|
||
kill -9 "$PID" | ||
|
||
echo "*** End of proxy tests" |