Exemplo n.º 1
0
    def test_allocate_success(self):
        # Arrange
        dr = Drone("Test drone", class_type=1)
        op = Operator()
        op.first_name = "John"
        op.drone_license = 1
        store = DroneStore()

        # Act
        act = store.allocate(dr, op)

        # Assert
        self.assertTrue(act.is_valid())
    def test_has_rescue_endorsement(self):
        # Arrange
        dr = Drone("Test drone", rescue=True)
        op = Operator()
        op.first_name = "John"
        op.drone_license = 1
        store = DroneStore()

        # Act
        act = store.allocate(dr, op)

        # Assert
        self.assertFalse(act.is_valid())
        self.assertIn("Operator does not have rescue endorsement", act.messages)
    def test_holds_correct_license(self):
        # Arrange
        dr = Drone("Test drone", class_type=2)
        op = Operator()
        op.first_name = "John"
        op.drone_license = 1
        store = DroneStore()

        # Act
        act = store.allocate(dr, op)

        # Assert
        self.assertFalse(act.is_valid())
        self.assertIn("Operator does not have correct drone license", act.messages)
Exemplo n.º 4
0
    def test_only_one_drone(self):
        # Arrange
        dr = Drone("Test drone", class_type=1)
        op = Operator()
        op.first_name = "John"
        op.drone_license = 1
        op.drone = Drone("Yet another")
        store = DroneStore()

        # Act
        act = store.allocate(dr, op)
        # Assert
        self.assertFalse(act.is_valid())
        self.assertIn("Operator can only control one drone", act.messages)
Exemplo n.º 5
0
    def test_has_rescue_endorsement_success(self):
        # Arrange
        dr = Drone("Test drone", rescue=True)
        op = Operator()
        op.first_name = "John"
        op.drone_license = 1
        op.rescue_endorsement = True
        store = DroneStore()

        # Act
        act = store.allocate(dr, op)

        # Assert
        self.assertTrue(act.is_valid())
Exemplo n.º 6
0
    def test_commit(self):
        # Arrange
        dr = Drone("Test drone", class_type=1)
        op = Operator()
        op.first_name = "John"
        op.drone_license = 1
        store = DroneStore()

        # Act
        act = store.allocate(dr, op)
        act.commit()

        # Assert
        self.assertEquals(dr.operator, op)
        self.assertEquals(op.drone, dr)
Exemplo n.º 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)