def test_remove_success(self): # Arrange dr = Drone("drone123") store = DroneStore() # Act store.add(dr) store.remove(dr) # Assert self.assertNotIn(dr.id, store.list_all())
def test_DroneStore_add(self): #Arrange dr = Drone("Test Drone") store = DroneStore() #Act act = store.add(dr) #print(dr.id in store.list_all()) used to test output #Assert self.assertEqual(dr.id in store.list_all(), True, "Drone has not been added successfully")
def test_droneRemove(self): #Arrange store = DroneStore() dr = Drone("Test") dr2 = Drone("Test2") dr3 = Drone("Test3") store.add(dr) store.add(dr2) #Act store.remove(dr2) #Assert listy = [] for i in store.list_all(): listy.append(store.get(i)) self.assertIn(dr, listy) self.assertNotIn(dr2, listy)
def test_droneAdd(self): # Arrange dr = Drone("Tester") dr2 = Drone("Tester2") dr3 = Drone("Tester3") dr4 = Drone("Tester3") store = DroneStore() #Act store.add(dr) store.add(dr2) store.add(dr3) listy = [] #Assert for i in store.list_all(): listy.append(store.get(i)) self.assertIn(dr, listy) self.assertIn(dr2, listy) self.assertIn(dr3, listy) self.assertNotIn(dr4, listy)
class Application(object): """ Main application wrapper for processing input. """ def __init__(self, conn): self._drones = DroneStore(conn) self._commands = { 'list': self.list, 'add': self.add, 'update': self.update, 'remove': self.remove, 'allocate': self.allocate, 'help': self.help, } def main_loop(self): print 'Welcome to DALSys' cont = True while cont: val = raw_input('> ').strip().lower() cmd = None args = {} if len(val) == 0: continue try: parts = val.split(' ') if parts[0] == 'quit': cont = False print 'Exiting DALSys' else: cmd = self._commands[parts[0]] except KeyError: print '!! Unknown command "%s" !!' % (val) if cmd is not None: args = parts[1:] try: cmd(args) except Exception as ex: print '!! %s !!' % (str(ex)) def add(self, args): """ Adds a new drone. """ print args self._drones.add(args) def allocate(self, args): """ Allocates a drone to an operator. """ self._drones.allocate(args) def help(self, args): """ Displays help information. """ print "Valid commands are:" print "* list [- class =(1|2)] [- rescue ]" print "* add 'name ' -class =(1|2) [- rescue ]" print "* update id [- name ='name '] [- class =(1|2)] [- rescue ]" print "* remove id" print "* allocate id 'operator'" def list(self, args): """ Lists all the drones in the system. """ self._drones.list_all(args) def remove(self, args): """ Removes a drone. """ self._drones.remove(args) def update(self, args): """ Updates the details for a drone. """ self._drones.update(args)