diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/runtests.py | 17 | ||||
| -rwxr-xr-x | test/test_freebase.py | 22 | ||||
| -rw-r--r-- | test/test_schema_manipulation.py | 33 |
3 files changed, 24 insertions, 48 deletions
diff --git a/test/runtests.py b/test/runtests.py index 65f02c9..c90afb7 100644 --- a/test/runtests.py +++ b/test/runtests.py @@ -5,6 +5,8 @@ import os.path import freebase +import getlogindetails + def main(): created = False passwordfile = "test/.password.txt" @@ -12,17 +14,8 @@ def main(): # setup password stuff if not os.path.isfile(passwordfile): created = True - USERNAME, PASSWORD = "", "" - print "RUNTESTSIn order to run the tests, we need to use a valid freebase username and password" - USERNAME = raw_input("Please enter your username: ") - PASSWORD = raw_input("Please enter your password (it'll appear in cleartext): ") - - freebase.login(USERNAME, PASSWORD) - - print "Thanks!" - fh = open(passwordfile, "w") - fh.write(USERNAME + "\n" + PASSWORD) - fh.close() + USERNAME, PASSWORD = getlogindetails.main(create_password_file=True) + USERNAME, PASSWORD = getlogindetails.main() # run tests import test_freebase @@ -34,7 +27,7 @@ def main(): # This is very strange. If you try to do [s1, s2], thereby running freebase tests first, # two tests in the testschemamanipulation file fail! They fail because of caching issues; if # I check on freebase, the changes are actually there. I have racked my mind for explanations. - anotherrun = unittest.TestSuite([s2, s1]) + anotherrun = unittest.TestSuite([s1, s2]) #run = unittest.TestSuite(suites) diff --git a/test/test_freebase.py b/test/test_freebase.py index 32517fc..d448b39 100755 --- a/test/test_freebase.py +++ b/test/test_freebase.py @@ -32,34 +32,22 @@ import sys, logging import freebase import random +import getlogindetails + from freebase.api import HTTPMetawebSession, MetawebError USERNAME = 'username' PASSWORD = 'password' -API_HOST = 'sandbox.freebase.com' +API_HOST = 'http://sandbox-freebase.com' TEST_QUERY = {'id': 'null', 'name': 'Sting'} s = HTTPMetawebSession(API_HOST) if USERNAME == "username" and PASSWORD == "password": - try: - passwordfile = open("test/.password.txt", "r") - fh = passwordfile.read().split("\n") - USERNAME = fh[0] - PASSWORD = fh[1] - passwordfile.close() - s.login(USERNAME, PASSWORD) - - except Exception, e: - print "FREEBASEIn order to run the tests, we need to use a valid freebase username and password" - USERNAME = raw_input("Please enter your username: ") - PASSWORD = raw_input("Please enter your password (it'll appear in cleartext): ") - s.login(USERNAME, PASSWORD) - print "Thanks!" + USERNAME, PASSWORD = getlogindetails.main() -else: - s.login(USERNAME, PASSWORD) +s.login(USERNAME, PASSWORD) class TestFreebase(unittest.TestCase): def test_freebase_dot_login_logout(self): diff --git a/test/test_schema_manipulation.py b/test/test_schema_manipulation.py index 968e429..53ce542 100644 --- a/test/test_schema_manipulation.py +++ b/test/test_schema_manipulation.py @@ -4,35 +4,23 @@ import freebase import random import time +import getlogindetails + from freebase.api import HTTPMetawebSession, MetawebError from freebase.schema import create_type, reciprocate_property, delegate_property from freebase.schema import create_property, type_object, copy_property, move_property USERNAME = 'username' PASSWORD = 'password' -API_HOST = 'sandbox.freebase.com' +API_HOST = 'http://sandbox-freebase.com' s = freebase.api.HTTPMetawebSession(API_HOST) domain_id = None if USERNAME == "username" and PASSWORD == "password": - try: - passwordfile = open("test/.password.txt", "r") - fh = passwordfile.read().split("\n") - USERNAME = fh[0] - PASSWORD = fh[1] - passwordfile.close() - s.login(USERNAME, PASSWORD) - - except Exception, e: - print "SCHEMAIn order to run the tests, we need to use a valid freebase username and password" - USERNAME = raw_input("Please enter your username: ") - PASSWORD = raw_input("Please enter your password (it'll appear in cleartext): ") - s.login(USERNAME, PASSWORD) - print "Thanks!" + USERNAME, PASSWORD = getlogindetails.main() -else: - s.login(USERNAME, PASSWORD) +s.login(USERNAME, PASSWORD) r = s.create_private_domain("test" + str(int(random.random() * 1e10)), "test")["domain_id"] domain_id = s.mqlread({"id" : r, "a:id" : None})["a:id"] @@ -48,16 +36,23 @@ class TestSchemaManipulation(unittest.TestCase): self.assertEqual(a.create, "created") b = s.create_object("B", path=domain_id + "/b", included_types=["/people/person"]) + print s.cookiejar._cookies["sandbox-freebase.com"] + q = { "id" : b.id, "type" : [{"id" : None}] } types = map(f, s.mqlread(q)["type"]) self.assertEqual("/common/topic" in types, True) self.assertEqual("/people/person" in types, True) self.assertEqual("/film/actor" in types, False) - s.touch(), time.sleep(2), s.touch(); + s.touch(), time.sleep(2), s.touch(); + print s.cookiejar._cookies["sandbox-freebase.com"] type_object(s, b.id, "/film/film_genre") + print s.cookiejar._cookies["sandbox-freebase.com"] + s.touch(), time.sleep(2), s.touch(); - s.mqlwrite({"id" : b.id, "/film/film_genre/films_in_this_genre" : {"id" : "/en/the_taking_of_pelham_1_2_3", "connect" : "insert"}}) + #s.mqlwrite({"id" : b.id, "/film/film_genre/films_in_this_genre" : {"id" : "/en/the_taking_of_pelham_1_2_3", "connect" : "insert"}}) types = map(f, s.mqlread(q)["type"]) + print s.cookiejar._cookies["sandbox-freebase.com"] + s.touch(), time.sleep(2), s.touch(); print types |
