def add(self, args): cursor = connection.cursor() if args is None: print('!! name is required !!') elif args[1] is None: print('!! class is required !!') else: dname = args[0] dclass = args[1][7] if args[2] is not None: DroneStore.add( Drone(dname, class_type=int(dclass), rescue=true)) query = 'select * from drone_info where drone_name = ' + dname + ' and class_type = ' + dclass + ' and rescue = "yes"' cursor.execute(query) records = cursor.fetchall() for row in records: id = str(row[0]) print('Added rescue drone with ID 000' + id) else: DroneStore.add( Drone(dname, class_type=int(dclass), rescue=false)) query = 'select * from drone_info where drone_name = ' + dname + ' and class_type = ' + dclass cursor.execute(query) records = cursor.fetchall() for row in records: id = str(row[0]) print('Added drone with ID 000' + id) raise Exception("Add method has not been implemented yet")
def test_add_exception(self): #arrange dr = Drone("Test drone", class_type=1) store = DroneStore() #act actual = store.add(dr) #assert with self.assertRaises(Exception): store.add(dr)
def test_add_success(self): # Arrange dr = Drone("drone123") store = DroneStore() # Act store.add(dr) # Assert self.assertEqual(dr, store.get(dr.id))
def test_add_success(self): # Arrange dr = Drone("Test drone") store = DroneStore() # Act store.add(dr) # Assert self.assertEqual(store.get(1), dr)
def test_droneAddException(self): #Arrange store = DroneStore() dr = Drone("Dupe") store.add(dr) #Act and Assert with self.assertRaises(Exception): store.add(dr)
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_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_add_error(self): #Arrange dr = Drone("Test Drone") store = DroneStore() #Act act = store.add(dr) #Assert with self.assertRaises(Exception): store.add(dr)
def test_add_already_exists(self): # Arrange dr = Drone("drone123") store = DroneStore() # Act store.add(dr) with self.assertRaises(Exception) as ctx: store.add(dr) # Assert self.assertEqual('Drone already exists in store', str(ctx.exception))
def test_add_fail(self): # Arrange dr = Drone("Test drone") store = DroneStore() errorText = 'Drone already exists in store' # Act try: store.add(dr) store.add(dr) # Assert except Exception as ex: self.assertEqual(str(ex), errorText)
def test_add_success(self): #arrange dr = Drone("Test drone", class_type=1) store = DroneStore() #act actual = store.add(dr) #assert self.assertIn(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_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_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)