def test_remove_exception(self): #arrange dr = Drone("Test drone", class_type=1) store = DroneStore() #assert with self.assertRaises(Exception): store.remove(dr)
def test_remove_doesnt_exist(self): # Arrange dr = Drone("drone123") store = DroneStore() # Act with self.assertRaises(Exception) as ctx: store.remove(dr) # Assert self.assertEqual('Drone does not exist in store', str(ctx.exception))
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_remove_success(self): # Arrange dr = Drone("Test drone") store = DroneStore() store.add(dr) # Act store.remove(dr) # Assert self.assertEqual(store.get(1), None)
def test_droneRemoveException(self): #Arrange store = DroneStore() dr = Drone("Test") store.add(dr) store.remove(dr) #Act and Assert with self.assertRaises(Exception): store.remove(dr)
def test_DroneStore_remove_error(self): dr = Drone("Test Drone") store = DroneStore() #Act #act = store.remove(dr) #Assert with self.assertRaises(Exception) as context: store.remove(dr) self.assertEqual("Drone does not exist in store", str(context.exception))
def test_remove_fail(self): # Arrange dr = Drone("Test drone") store = DroneStore() errorText = 'Drone does not exist in store' # Act try: store.remove(dr) # Assert except Exception as ex: self.assertEqual(str(ex), errorText)
def test_remove_success(self): #arrange dr = Drone("Test drone", class_type=1) store = DroneStore() #act actual = store.add(dr) actual = store.remove(dr) #assert self.assertNotIn(dr.id, store._drones)
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_DroneStore_remove(self): #Arrange dr = Drone("Test Drone") store = DroneStore() #Act act = store.add(dr) act2 = store.remove(dr) #print(dr.id in store.list_all()) used to test output #Assert self.assertEqual(dr.id in store.list_all(), False, "Drone has not been removed successfully")
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)