예제 #1
0
 def testNoMatchingUser(self):
     TEST_LOG_FILE = 'room_testnouser.log'
     testLogger = logging.getLogger('nouser')
     testHandler = logging.FileHandler(TEST_LOG_FILE, mode='w')
     testHandler.setFormatter(logging.Formatter('%(message)'))
     testLogger.addHandler(logging.FileHandler(TEST_LOG_FILE, mode='w'))
     dmaking = decisionMaking(testLogger, ['localhost', 8080],
                              'http://localhost:8082')
     self.assertRaises(KeyError, dmaking.findMatchingRoom, 'nouser',
                       37.229854, -80.417724, 2085)
예제 #2
0
 def testNoMatchingRoom(self):
     TEST_LOG_FILE = 'room_testnoroom.log'
     testLogger = logging.getLogger('noroom')
     testHandler = logging.FileHandler(TEST_LOG_FILE, mode='w')
     testHandler.setFormatter(logging.Formatter('%(message)'))
     testLogger.addHandler(logging.FileHandler(TEST_LOG_FILE, mode='w'))
     dmaking = decisionMaking(testLogger, ['localhost', 8080],
                              'http://localhost:8082')
     self.assertEquals(
         dmaking.findMatchingRoom('bsaget', 38.229854, -81.417724, 2085),
         None)
 def testNoMatchingHouse(self):
     try:
         TEST_LOG_FILE = 'testnohouse.log'
         testLogger = logging.getLogger('nohouse')
         testHandler = logging.FileHandler(TEST_LOG_FILE, mode='w')
         testHandler.setFormatter(logging.Formatter('%(message)'))
         testLogger.addHandler(logging.FileHandler(TEST_LOG_FILE, mode='w'))
         print 'Testing command decision when there will be no matching house'
         dmaking = decisionMaking(testLogger, ['localhost', 8080], 'http://localhost:8082')
         dmaking.command(good_request_no_house)
         testoutfile = open(TEST_LOG_FILE)
         log = testoutfile.read().strip('\n')
         expected = ['Command Decision 1:',
                     'no matching room']
         self.assertTrue(validateLog(expected, log))
     except:
         raise
 def testGoodRequest(self):
     try:
         TEST_LOG_FILE = 'testallok.log'
         testLogger = logging.getLogger('allok')
         testHandler = logging.FileHandler(TEST_LOG_FILE, mode='w')
         testHandler.setFormatter(logging.Formatter('%(message)'))
         testLogger.addHandler(logging.FileHandler(TEST_LOG_FILE, mode='w'))
         testLogger.setLevel(logging.INFO)
         print 'Testing command decision when there will be no matching user'
         dmaking = decisionMaking(testLogger, ['localhost', 8080], 'http://localhost:8082')
         dmaking.command(good_request_should_work)
         testoutfile = open(TEST_LOG_FILE)
         log = testoutfile.read().strip('\n')
         expected = ['Command Decision 1:',
             'matched room (101, 3)',
             'requesting devices']
         self.assertTrue(validateLog(expected, log))
     except:
         raise
예제 #5
0
 def __init__(self, server_address, persistentStorageAddress, deviceBase, RequestHandlerClass, declogname, resetlog):
     BaseHTTPServer.HTTPServer.__init__(self, server_address, RequestHandlerClass)
     self.shouldStop = False
     self.timeout = 1
     self.storageAddress = persistentStorageAddress
     self.timeconfig = {}
     self.threads=[]
     self.deviceBase = deviceBase
     decisionlogger = logging.getLogger('DecisionMakingServer')
     if resetlog:
         decisionlogger.addHandler(logging.FileHandler(declogname, mode = 'w'))
     else:
         decisionlogger.addHandler(logging.FileHandler(declogname, mode = 'a'))
     decisionlogger.setLevel(logging.DEBUG)
     self.decision = decisionMaking(decisionlogger, persistentStorageAddress, deviceBase)
     self.serverrequestlogger = logging.getLogger('ServerRequestLogger')
     serverrequestloggerhandler = logging.FileHandler('ServerRequestLogFile', mode = 'a')
     serverformatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
     serverrequestloggerhandler.setFormatter(serverformatter)
     self.serverrequestlogger.addHandler(serverrequestloggerhandler)
     self.serverrequestlogger.setLevel(logging.INFO)
예제 #6
0
        testHandler = logging.FileHandler(TEST_LOG_FILE, mode='w')
        testHandler.setFormatter(logging.Formatter('%(message)'))
        testLogger.addHandler(logging.FileHandler(TEST_LOG_FILE, mode='w'))
        dmaking = decisionMaking(testLogger, ['localhost', 8080],
                                 'http://localhost:8082')
        self.assertEquals(
            dmaking.findMatchingRoom('bsaget', 38.229854, -81.417724, 2085),
            None)


TEST_LOG_FILE = 'testLocationUpdate.log'
testLogger = logging.getLogger('locations')
testHandler = logging.FileHandler(TEST_LOG_FILE, mode='w')
testHandler.setFormatter(logging.Formatter('%(message)'))
testLogger.addHandler(logging.FileHandler(TEST_LOG_FILE, mode='w'))
mydmaking = decisionMaking(testLogger, ['localhost', 8080],
                           'http://localhost:8082')


class testLocationUpdates(unittest.TestCase):
    def testNoPreviousRoom(self):
        mydmaking.locationDecision(good_location_message)
        print('1')

    def testPrevEntryNoChange(self):
        mydmaking.locationDecision(good_location_message)
        print('2')

    def testPrevEntryRoomChange(self):
        mydmaking.locationDecision(change_location_message)
        print('3')
 def testDemoRestoreSnapshot(self):
     print 'Running restore snapshot demo'
     dmaking = decisionMaking(None, ['localhost', 8080], 'http://localhost:8082')
     dmaking.restoreRoomState(None, None, None, None)