Example #1
0
    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())
Example #2
0
    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)
Example #3
0
    def __init__(self, conn):
        # Initialise the stores
        self.drones = DroneStore(conn)
        self.operators = OperatorStore(conn)
        self.maps = MapStore(conn)
        self.track = TrackingSystem()

        # Initialise the GUI window
        self.root = tk.Tk()
        self.root.title('Drone Allocation and Localisation')
        frame = tk.Frame(self.root)
        frame.pack(padx=10, pady=10)

        # Add in the buttons
        drone_button = tk.Button(frame,
                                 text="View Drones",
                                 command=self.view_drones,
                                 width=40,
                                 padx=5,
                                 pady=5)
        drone_button.pack(side=tk.TOP)
        operator_button = tk.Button(frame,
                                    text="View Operators",
                                    command=self.view_operators,
                                    width=40,
                                    padx=5,
                                    pady=5)
        operator_button.pack(side=tk.TOP)
        view_map_button = tk.Button(frame,
                                    text="View Maps",
                                    command=self.view_maps,
                                    width=40,
                                    padx=5,
                                    pady=5)
        view_map_button.pack(side=tk.TOP)
        allocate_drone_button = tk.Button(frame,
                                          text="Allocate Drone",
                                          command=self.view_allocation,
                                          width=40,
                                          padx=5,
                                          pady=5)
        allocate_drone_button.pack(side=tk.TOP)
        exit_button = tk.Button(frame,
                                text="Exit System",
                                command=quit,
                                width=40,
                                padx=5,
                                pady=5)
        exit_button.pack(side=tk.TOP)
Example #4
0
    def test_droneAddException(self):
        #Arrange
        store = DroneStore()
        dr = Drone("Dupe")

        store.add(dr)
        
        #Act and Assert
        with self.assertRaises(Exception):
            store.add(dr)
Example #5
0
    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))
Example #6
0
    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)
Example #7
0
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)
Example #8
0
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()
            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. """
        # Initialise variables
        name = ''
        dclass = ''
        res = False  # Rescue is False by default

        argsStart = 0

        # Strips for name of drone
        for i in range(len(args)):
            if args[0][0] == "'" or args[0][0] == '"':
                name = name + ' ' + args[i]
                if not (len(args[i]) == 0) and (args[i][-1] == "'"
                                                or args[i][-1] == '"'):
                    argsStart = i + 1
                    break

        # Tries to get name from user input
        try:
            name = name[1:]
        except:
            pass

        # Checks for -rescue argument
        if len(args) == 3:
            if args[2] == '-rescue':
                res = 1
            else:
                res = 0

        # Recombines to form proper argument list in format [name, class, rescue]
        args = [name] + args[argsStart:]

        # Checks for name and class inputs, if they do not exist returns error
        if len(name) == 0:
            raise Exception("name is required")
        else:
            try:
                dclass = args[1]
                if dclass[-1] == '1':
                    dclass = 1
                elif dclass[-1] == '2':
                    dclass = 2
            except:
                raise Exception("class is required")

        # Reformatted arguments list for query
        args = [name, dclass, res]
        self._drones.addDrones(args)

    def allocate(self, args):
        """ Allocates a drone to an operator. """
        if len(args) == 0:
            print("!! ID is required !!")
            raise Exception("Operator is required")
        elif len(args) == 1:
            try:
                args[0] = int(args[0])
                print("!! Operator is required !!")
            except:
                raise Exception("ID is required")
        elif len(args) > 2:
            raise Exception("Too many arguments")
        elif len(args) == 2:
            args[0] = int(args[0])
            self._drones.allocateDrones(args)
        else:
            raise Exception("Input Error")

    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. """
        try:
            print 'ID\tName\t\t\tClass\tRescue\tOperator'
            for drone in self._drones.listDrones(args):
                print '%.4d\t%-20s\t%s\t%s\t%s' % (
                    drone.id, drone.name, drone.class_type, drone.rescue,
                    drone.operator)
            if len(list(self._drones.listDrones(args))) != 0:
                print '%d drones listed' % len(
                    list(self._drones.listDrones(args)))
            else:
                raise Exception("There are no drones for this criteria")
        except Exception as error:
            raise Exception(error)

    def remove(self, args):
        """ Removes a drone. """
        if len(args) == 1:
            self._drones.removeDrones(int(args[0]))
        elif len(args) == 0:
            raise Exception("ID is required")

    def update(self, args):
        """ Updates the details for a drone. """
        try:
            Did = int(args[0])
        except:
            raise Exception("ID is required")
        name = None
        dclass = None
        res = 0

        for i in args:
            arg = i[0:2]
            if arg == '-n':
                name = i[7:-1]
            elif arg == '-c':
                dclass = int(i[-1])
            elif arg == '-r':
                res = 1

        args = [Did, name, dclass, res]
        self._drones.updateDrones(args)