client tests

git-svn-id: https://bucket.mit.edu/svn/nilm/nilmdb@10611 ddd99763-3ecb-0310-9145-efcb8ce7c51f
This commit is contained in:
Jim Paris 2012-03-20 14:26:29 +00:00
parent b766aef257
commit 56a1770f45

61
tests/test_client.py Normal file
View File

@ -0,0 +1,61 @@
import nilmdb
from nilmdb.printf import *
from nose.tools import *
from nose.tools import assert_raises
import json
import itertools
import os
import shutil
import sys
import threading
import urllib2
from urllib2 import urlopen, HTTPError
import Queue
import StringIO
import shlex
testdb = "tests/client-testdb"
def eq_(a, b):
if not a == b:
raise AssertionError("%r != %r" % (a, b))
def ne_(a, b):
if not a != b:
raise AssertionError("unexpected %r == %r" % (a, b))
class TestClient(object):
def setUp(self):
# Clear out DB
try:
shutil.rmtree(testdb)
except:
pass
try:
os.unlink(testdb)
except:
pass
# Start web app on a custom port
self.db = nilmdb.NilmDB(testdb)
self.server = nilmdb.Server(self.db, host = "127.0.0.1",
port = 12380, stoppable = False)
self.server.start(blocking = False)
def tearDown(self):
# Close web app
self.server.stop()
self.db.close()
def test_client_basic(self):
# Test a fake host
client = nilmdb.Client(url = "http://localhost:1/")
with assert_raises(NilmDBError) as e:
client.version()
# Now a real host
client = nilmdb.Client(url = "http://localhost:12380/")
eq_(distutils.version.StrictVersion(getjson("/version")),
distutils.version.StrictVersion(self.server.version))