more unit test progress
authorDavid Blacka <david@blacka.com>
Wed, 16 Jul 2008 02:34:53 +0000 (22:34 -0400)
committerDavid Blacka <david@blacka.com>
Wed, 16 Jul 2008 02:34:53 +0000 (22:34 -0400)
.cvsignore [deleted file]
rwhoisd/.cvsignore [deleted file]
rwhoisd/QueryProcessor.py
test/TestQueryProcessor.py [new file with mode: 0644]

diff --git a/.cvsignore b/.cvsignore
deleted file mode 100644 (file)
index 4fca027..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-MANIFEST
-build
-dist
diff --git a/rwhoisd/.cvsignore b/rwhoisd/.cvsignore
deleted file mode 100644 (file)
index 0d20b64..0000000
+++ /dev/null
@@ -1 +0,0 @@
-*.pyc
index d867ea0..d40b687 100644 (file)
@@ -407,11 +407,6 @@ def reduce_domain(domain):
     dlist.pop(0)
     return '.'.join(dlist)
 
-def is_heirarchical(value):
-    if cidr.valid_cidr(value): return True
-    if is_domainname(value): return True
-    return False
-
 if __name__ == '__main__':
 
     import MemDB, Session
diff --git a/test/TestQueryProcessor.py b/test/TestQueryProcessor.py
new file mode 100644 (file)
index 0000000..6121a9d
--- /dev/null
@@ -0,0 +1,96 @@
+# This file is part of python-rwhoisd
+#
+# Copyright (C) 2008 David E. Blacka
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
+
+
+import path
+import QueryProcessor, Session, MemDB, QueryParser
+import unittest, types, StringIO
+
+
+class TestHelperMethods(unittest.TestCase):
+
+    def testMatchCidr(self):
+        values = [ ("127.0.0.1/24", "127.0.0.0/24", True),
+                   ("127.0.0.0/24**", "127.0.0.8", True),
+                   ("127.0.0.0/24*", "127.0.0.0/23", True),
+                   ("127.0.0.0/24*", "127.0.0.1/24", True),
+                   ("127.0.0.10/24", "127.0.0.0/22", False) ]
+        for sv, tv, v in values:
+            self.assertEquals(QueryProcessor.match_cidr(sv, tv), v)
+
+    def testIsDomainName(self):
+        values = [ ("a.domain", True), ("not_a_domain", False),
+                   ("www.foo.com.", True), ("glor!.com", False),
+                   ("a_bad.domain", False) ]
+        for a, r in values:
+            assert(QueryProcessor.is_domainname(a) == r)
+
+    def testIsSubdomain(self):
+        values = [ ("sub.foo.domain", "domain", True),
+                   ("sub.bar.domain", "foo.domain", False),
+                   ("baz.domain", "a.baz.domain", False),
+                   ("a.com", "a.com", True) ]
+        for sub, domain, value in values:
+            self.assertEquals(QueryProcessor.is_subdomain(domain, sub), value)
+
+    def testReduceDomain(self):
+        values = [ ("a.com", "com"), ("b.com.", "com."),
+                   (".", ""), ("a.b.c.net", "b.c.net") ]
+        for d, v in values:
+            self.assertEquals(QueryProcessor.reduce_domain(d), v)
+
+
+class TestProcessing(unittest.TestCase):
+    def setUp(self):
+        db = MemDB.MemDB()
+        db.init_schema("test_schema")
+        db.load_data("test_data")
+        db.index_data()
+        QueryParser.db = db
+        self.processor = QueryProcessor.QueryProcessor(db)
+        self.session = Session.Context()
+        self.session.wfile = StringIO.StringIO()
+
+
+    def testParseKnown(self):
+        queries = [ ('domain a.com', """domain:ID:333.a.com\r
+domain:Auth-Area:a.com\r
+domain:Class-Name:domain\r
+domain:Guardian:444.a.com\r
+domain:Domain-Name:a.com\r
+domain:Primary-Server:5551.a.com\r
+domain:Secondary-Server:5552.a.com\r
+domain:Organization:777.a.com\r
+domain:Admin-Contact:222.a.com\r
+domain:Tech-Contact:222.a.com\r
+domain:Billing-Contact:222.a.com\r
+domain:Created:19961022\r
+domain:Updated:19961023\r
+domain:Updated-By:hostmaster@a.com\r
+\r
+%ok\r
+""") ]
+
+        for q, s in queries:
+            self.processor.process_query(self.session, q)
+            res = self.session.wfile.getvalue()
+            self.assertEquals(res, s.lower())
+
+if __name__ == "__main__":
+    unittest.main()