Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
base repository: gsathya/pyonionoo
base: master
head repository: gsathya/pyonionoo
compare: tests
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 5 files changed
  • 0 comments
  • 1 contributor
Commits on Oct 05, 2012
The summary method is tested by test_summary.py,
the responses are stored in summary_response.py

To run the tests, start the server and run
'trial ./tests'
Showing with 188 additions and 1 deletion.
  1. +1 −1 pyonionoo.conf
  2. 0 tests/__init__.py
  3. +4 −0 tests/data/summary
  4. +26 −0 tests/summary_responses.py
  5. +157 −0 tests/test_summary.py
@@ -29,5 +29,5 @@ poolsize = 10
debug = no

[metrics]
out_dir = /tmp
out_dir = tests/data
summary_file = summary
Empty file.
@@ -0,0 +1,4 @@
r sumkledi 0013D22389CD50D0B784A3E4061CB31E8CE8CEB5 178.218.213.229;; 2012-07-03 07:00:00 80 0 Exit,Fast,Running,Valid 26 ru 178.218.213.229 1341285307613
r Unnamed 0036D8A9212508D2C963B4BA965FF33FEF9842EB 85.141.74.20;; 2012-06-30 01:00:00 10582 15228 Exit,Fast,V2Dir,Valid 56 ru ppp85-141-74-20.pppoe.mtu-net.ru 1341296110373
b Unnamed 000951A845A3B4772F16DEC805DD0144F2BF7E02 10.199.144.153;; 2012-07-01 12:07:04 443 0 Valid -1 ?? null -1
b Unnamed 0014A2055278DB3EB0E59EA701741416AF185558 10.210.57.40;; 2012-07-02 22:37:06 443 0 Valid -1 ?? null -1
@@ -0,0 +1,26 @@
# List of responses from Pyonionoo

BAD_REQUEST = """<html><title>400: Bad Request</title><body>400: Bad Request</body></html>"""

FULL_SUMMARY = """{"relays_published": "2012-07-03 07:00:00", "bridges_published": "2012-07-02 22:37:06", "relays": [{"n": "sumkledi", "r": true, "f": "0013D22389CD50D0B784A3E4061CB31E8CE8CEB5"}, {"n": "Unnamed", "r": false, "f": "0036D8A9212508D2C963B4BA965FF33FEF9842EB"}], "bridges": [{"n": "Unnamed", "r": false, "f": "000951A845A3B4772F16DEC805DD0144F2BF7E02"}, {"n": "Unnamed", "r": false, "f": "0014A2055278DB3EB0E59EA701741416AF185558"}]}"""


RELAY_SUMMARY = """{"relays_published": "2012-07-03 07:00:00", "bridges_published": "2012-07-02 22:37:06", "relays": [{"n": "sumkledi", "r": true, "f": "0013D22389CD50D0B784A3E4061CB31E8CE8CEB5"}, {"n": "Unnamed", "r": false, "f": "0036D8A9212508D2C963B4BA965FF33FEF9842EB"}], "bridges": []}"""

BRIDGE_SUMMARY = """{"relays_published": "2012-07-03 07:00:00", "bridges_published": "2012-07-02 22:37:06", "relays": [], "bridges": [{"n": "Unnamed", "r": false, "f": "000951A845A3B4772F16DEC805DD0144F2BF7E02"}, {"n": "Unnamed", "r": false, "f": "0014A2055278DB3EB0E59EA701741416AF185558"}]}"""

RUNNING_TRUE = """{"relays_published": "2012-07-03 07:00:00", "bridges_published": "2012-07-02 22:37:06", "relays": [{"n": "sumkledi", "r": true, "f": "0013D22389CD50D0B784A3E4061CB31E8CE8CEB5"}], "bridges": []}"""

RUNNING_FALSE = """{"relays_published": "2012-07-03 07:00:00", "bridges_published": "2012-07-02 22:37:06", "relays": [{"n": "sumkledi", "r": true, "f": "0013D22389CD50D0B784A3E4061CB31E8CE8CEB5"}, {"n": "Unnamed", "r": false, "f": "0036D8A9212508D2C963B4BA965FF33FEF9842EB"}], "bridges": [{"n": "Unnamed", "r": false, "f": "000951A845A3B4772F16DEC805DD0144F2BF7E02"}, {"n": "Unnamed", "r": false, "f": "0014A2055278DB3EB0E59EA701741416AF185558"}]}"""

LOOKUP_RESULT_HASHED_FINGERPRINT = """{"relays_published": "2012-07-03 07:00:00", "bridges_published": "2012-07-02 22:37:06", "relays": [], "bridges": [{"n": "Unnamed", "r": false, "f": "0014A2055278DB3EB0E59EA701741416AF185558"}]}"""

LOOKUP_RESULT_FINGERPRINT = """{"relays_published": "2012-07-03 07:00:00", "bridges_published": "2012-07-02 22:37:06", "relays": [{"n": "sumkledi", "r": true, "f": "0013D22389CD50D0B784A3E4061CB31E8CE8CEB5"}], "bridges": []}"""

COUNTRY_RESULT = """{"relays_published": "2012-07-03 07:00:00", "bridges_published": "2012-07-02 22:37:06", "relays": [{"n": "sumkledi", "r": true, "f": "0013D22389CD50D0B784A3E4061CB31E8CE8CEB5"}, {"n": "Unnamed", "r": false, "f": "0036D8A9212508D2C963B4BA965FF33FEF9842EB"}], "bridges": []}"""

OFFSET_RESULT="""{"relays_published": "2012-07-03 07:00:00", "bridges_published": "2012-07-02 22:37:06", "relays": [], "bridges": [{"n": "Unnamed", "r": false, "f": "000951A845A3B4772F16DEC805DD0144F2BF7E02"}, {"n": "Unnamed", "r": false, "f": "0014A2055278DB3EB0E59EA701741416AF185558"}]}"""

LIMIT_RESULT="""{"relays_published": "2012-07-03 07:00:00", "bridges_published": "2012-07-02 22:37:06", "relays": [{"n": "sumkledi", "r": true, "f": "0013D22389CD50D0B784A3E4061CB31E8CE8CEB5"}, {"n": "Unnamed", "r": false, "f": "0036D8A9212508D2C963B4BA965FF33FEF9842EB"}], "bridges": []}"""

LIMIT_OFFSET_RESULT="""{"relays_published": "2012-07-03 07:00:00", "bridges_published": "2012-07-02 22:37:06", "relays": [{"n": "Unnamed", "r": false, "f": "0036D8A9212508D2C963B4BA965FF33FEF9842EB"}], "bridges": [{"n": "Unnamed", "r": false, "f": "000951A845A3B4772F16DEC805DD0144F2BF7E02"}]}"""
@@ -0,0 +1,157 @@
import cyclone.httpclient

from summary_responses import *
from cyclone.escape import json_decode
from cyclone.httputil import url_concat
from twisted.internet import defer
from twisted.trial import unittest

host = "localhost"
port = 8888
url = "http://%s:%s/%s" % (host, port, 'summary')

# fixme: passing self is a bad idea
def check_correct_response(self, response, expected):
self.assertEqual(response.code, 200)
self.assertEqual(response.headers['Content-Type'][0], 'application/json')
# check if valid json
json_decode(response.body)
self.assertEqual(response.body, expected)

# xxx: passing self is a bad idea
def check_incorrect_response(self, response, expected):
self.assertEqual(response.code, 400)
self.assertEqual(response.body, expected)

class TestSummaryDocuments(unittest.TestCase):
# check correct response of full summary
@defer.inlineCallbacks
def test_summary(self):
response = yield cyclone.httpclient.fetch(url)
check_correct_response(self, response, FULL_SUMMARY)

# check correct response of TYPE argument where TYPE=relay
@defer.inlineCallbacks
def test_relay_type(self):
params = {'type': 'relay'}
response = yield cyclone.httpclient.fetch(url_concat(url, params))
check_correct_response(self, response, RELAY_SUMMARY)

# check correct response of TYPE argument where TYPE=bridge
@defer.inlineCallbacks
def test_bridge_type(self):
params = {'type': 'bridge'}
response = yield cyclone.httpclient.fetch(url_concat(url, params))
check_correct_response(self, response, BRIDGE_SUMMARY)

# check correct response of RUNNING argument where RUNNING=true
@defer.inlineCallbacks
def test_running_true(self):
params = {'running': 'true'}
response = yield cyclone.httpclient.fetch(url_concat(url, params))
check_correct_response(self, response, RUNNING_TRUE)

# check correct response of RUNNING argument where RUNNING=false
@defer.inlineCallbacks
def test_running_false(self):
params = {'running': 'false'}
response = yield cyclone.httpclient.fetch(url_concat(url, params))
check_correct_response(self, response, RUNNING_FALSE)

# check correct response of LOOKUP argument where LOOKUP is hashed fingerprint
@defer.inlineCallbacks
def test_lookup_hashed_fp(self):
hashed_fp = "0014A2055278DB3EB0E59EA701741416AF185558"
params = {'lookup': hashed_fp}
response = yield cyclone.httpclient.fetch(url_concat(url, params))
check_correct_response(self, response, LOOKUP_RESULT_HASHED_FINGERPRINT)

# check incorrect response of LOOKUP argument where LOOKUP is fingerprint
@defer.inlineCallbacks
def test_lookup_fp(self):
fp = "0013D22389CD50D0B784A3E4061CB31E8CE8CEB5"
params = {'lookup': fp}
response = yield cyclone.httpclient.fetch(url_concat(url, params))
check_correct_response(self, response, LOOKUP_RESULT_FINGERPRINT)

# check correct response of LOOKUP argument where LOOKUP is lower case fingerprint
@defer.inlineCallbacks
def test_lookup_case_insensitive_fp(self):
fp = "0013D22389CD50D0B784A3E4061CB31E8CE8CEB5"
params = {'lookup': fp.lower()}
response = yield cyclone.httpclient.fetch(url_concat(url, params))
check_correct_response(self, response, LOOKUP_RESULT_FINGERPRINT)

# check incorrect response of LOOKUP argument where LOOKUP is <40 chars
@defer.inlineCallbacks
def test_lookup_incorrect(self):
fp = "0014A20552"
params = {'lookup': fp}
response = yield cyclone.httpclient.fetch(url_concat(url, params))
check_incorrect_response(self, response, BAD_REQUEST)

# check correct response of COUNTRY argument
@defer.inlineCallbacks
def test_country(self):
country = "ru"
params = {'country': country}
response = yield cyclone.httpclient.fetch(url_concat(url, params))
check_correct_response(self, response, COUNTRY_RESULT)

# check correct response of COUNTRY argument where COUNTRY is upper case
@defer.inlineCallbacks
def test_country_case_insensitive(self):
country = "ru"
params = {'country': country.upper()}
response = yield cyclone.httpclient.fetch(url_concat(url, params))
check_correct_response(self, response, COUNTRY_RESULT)

# check incorrect response of COUNTRY argument
@defer.inlineCallbacks
def test_country_incorrect(self):
country = "russia"
params = {'country': country}
response = yield cyclone.httpclient.fetch(url_concat(url, params))
check_incorrect_response(self, response, BAD_REQUEST)

# check correct response of COUNTRY argument where COUNTRY is upper case
@defer.inlineCallbacks
def test_offset(self):
offset = 2
params = {'offset': offset}
response = yield cyclone.httpclient.fetch(url_concat(url, params))
check_correct_response(self, response, OFFSET_RESULT)

# check incorrect response of OFFSET argument where offset is an alphabet
@defer.inlineCallbacks
def test_offset_incorrect(self):
offset = 'a'
params = {'offset': offset}
response = yield cyclone.httpclient.fetch(url_concat(url, params))
check_incorrect_response(self, response, BAD_REQUEST)

# check correct response of LIMIT
@defer.inlineCallbacks
def test_limit(self):
limit = 2
params = {'limit': limit}
response = yield cyclone.httpclient.fetch(url_concat(url, params))
check_correct_response(self, response, LIMIT_RESULT)

# check correct response of LIMIT when used with OFFSET
@defer.inlineCallbacks
def test_limit_offset(self):
limit = 2
offset = 1
params = {'limit': limit, 'offset':offset}
response = yield cyclone.httpclient.fetch(url_concat(url, params))
check_correct_response(self, response, LIMIT_OFFSET_RESULT)

# check incorrect response of LIMIT
@defer.inlineCallbacks
def test_limit_incorrect(self):
limit = 'a'
params = {'limit': limit}
response = yield cyclone.httpclient.fetch(url_concat(url, params))
check_incorrect_response(self, response, BAD_REQUEST)

No commit comments for this range