Example #1
0
def main():
    created = False
    passwordfile = "test/.password.txt"
    
    # setup password stuff
    if not os.path.isfile(passwordfile):
        created = True
        USERNAME, PASSWORD = getlogindetails.main(create_password_file=True)
    USERNAME, PASSWORD = getlogindetails.main()        
 
    
    # run tests
    import test_freebase
    import test_schema_manipulation
    import test_hardcore_schema_manipulation

    s1 = unittest.TestLoader().loadTestsFromTestCase(test_freebase.TestFreebase)
    s2 = unittest.TestLoader().loadTestsFromTestCase(test_schema_manipulation.TestSchemaManipulation)
    s3 = unittest.TestLoader().loadTestsFromTestCase(test_hardcore_schema_manipulation.TestHardcoreSchemaManipulation)
    
    # 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.
    
    # this is such a hack, and I'm sorry. The tests run 100% correct individually.
    anotherrun = unittest.TestSuite([s1, s3, s2])
    
    #run = unittest.TestSuite(suites)
    
    # delete password stuff
    if created: os.remove(passwordfile)  
    
    return anotherrun
import random

import getlogindetails

from freebase.api import HTTPMetawebSession, MetawebError


USERNAME = "******"
PASSWORD = "******"
API_HOST = "http://sandbox-freebase.com"
TEST_QUERY = {"id": "null", "name": "Sting"}

s = HTTPMetawebSession(API_HOST)

if USERNAME == "username" and PASSWORD == "password":
    USERNAME, PASSWORD = getlogindetails.main()

s.login(USERNAME, PASSWORD)


class TestFreebase(unittest.TestCase):
    def test_freebase_dot_login_logout(self):
        freebase.login(username=USERNAME, password=PASSWORD)
        self.assertNotEqual(freebase.user_info(), None)
        self.assertEqual(freebase.loggedin(), True)
        freebase.logout()
        self.assertRaises(MetawebError, freebase.user_info)
        self.assertEqual(freebase.loggedin(), False)

    def test_login_logout(self):
        mss = HTTPMetawebSession(API_HOST, username=USERNAME, password=PASSWORD)
Example #3
0
import random
import time

import getlogindetails

from freebase.api import HTTPMetawebSession, MetawebError
from freebase.schema import dump_type, dump_base, restore

USERNAME = '******'
PASSWORD = '******'
API_HOST = 'sandbox-freebase.com'

s = freebase.api.HTTPMetawebSession(API_HOST)

if USERNAME == "username" and PASSWORD == "password":
    USERNAME, PASSWORD = getlogindetails.main()

s.login(USERNAME, PASSWORD)

# Sorry, this is just so annoying to type.
f = lambda x: x["id"]


class TestHardcoreSchemaManipulation(unittest.TestCase):
    def test_copy_an_entire_domain(self):
        domain_id = _create_domain()
        ex_domain_id = "/base/contractbridge"  # example domain id
        ex_domain_type = "bridge_player"
        ex_domain_type_id = ex_domain_id + "/" + ex_domain_type

        graph = dump_base(s, ex_domain_id)