Exemplo n.º 1
0
    def test_load_state(self):
        """
        Test that  data can be loaded to the application
        from an existing database
        """
        amity = self.load_data_into_amity(Amity())
        test_db = Database(amity)
        test_db.save_state({"--db": "test.db"})

        amity2 = Amity()
        test_db2 = Database(amity2)

        # Load data from previously created database
        test_db2.load_state({"<sqlite_database>": "test.db"})

        # Data is entered into the application
        print('in test_load_state', amity.people)
        print('in test_load_state', amity.rooms)
        print(len(amity.rooms))
        print(amity.livingspaces)
        self.assertEqual(2, len(amity.rooms))
        self.assertEqual(1, len(amity.livingspaces))
        self.assertEqual(1, len(amity.offices))
        self.assertEqual(2, len(amity.people))
        self.assertEqual(1, len(amity.fellows))
        self.assertEqual(1, len(amity.staff))

        os.remove("test.db")
Exemplo n.º 2
0
    def test_save_state(self):
        """Test that application data can be saved to user-defined database"""
        amity = self.load_data_into_amity(Amity())
        test_db = Database(amity)
        test_db.save_state({"--db": "test.db"})

        # File is created
        self.assertTrue(os.path.exists("test.db"))
        os.remove("test.db")
Exemplo n.º 3
0
    def setUp(self):
        self.amity = Amity()

        self.office_1 = Office('PERL')
        self.office_2 = Office('OCCULUS')
        self.living_space_1 = LivingSpace('DOJO')
        self.living_space_2 = LivingSpace('NODE')

        self.staff_1 = Staff("BOB", "WACHIRA")
        self.staff_2 = Staff("BOB", "ODHIAMBO")
        self.fellow_1 = Fellow("LAWRENCE", "WACHIRA", "N")
        self.fellow_2 = Fellow("LAWRENCE", "NYAMBURA", "Y")
        self.fellow_3 = Fellow("MARTIN", "MUNGAI", "Y")

        self.staff_1.employee_id, self.staff_1.office_allocated = 1, "PERL"
        self.staff_2.employee_id = 2
        self.fellow_1.employee_id = 3
        self.fellow_2.employee_id, self.fellow_2.office_allocated = 4, \
            "OCCULUS"
        self.fellow_2.living_space_allocated = "DOJO"
        self.fellow_3.employee_id = 5

        self.office_1.current_occupancy = 1
        self.office_2.current_occupancy = 1
        self.living_space_1.current_occupancy = 1

        self.amity.rooms = [self.office_1, self.office_2, self.living_space_1,
                            self.living_space_2]
        self.amity.offices = [self.office_1, self.office_2]
        self.amity.living_spaces = [self.living_space_2, self.living_space_1]
        self.amity.persons = [self.staff_1, self.staff_2, self.fellow_1,
                              self.fellow_2, self.fellow_3]
        self.amity.staff = [self.staff_2, self.staff_1]
        self.amity.fellows = [self.fellow_2, self.fellow_1, self.fellow_3]

        self.initial_room_count = len(self.amity.rooms)
        self.initial_office_count = len(self.amity.offices)
        self.initial_living_space_count = len(self.amity.living_spaces)
        self.initial_persons_count = len(self.amity.persons)
        self.initial_staff_count = len(self.amity.staff)
        self.initial_fellow_count = len(self.amity.fellows)

        self.amity.create_files_directory()
        self.amity.create_databases_directory()

        self.saved_id = None
        if Path('./models/.id.txt').is_file():
            with open('./models/.id.txt', "r") as current_id:
                self.saved_id = current_id.read()
        else:
            with open('./models/.id.txt', "w+") as person_id:
                person_id.write("5")
Exemplo n.º 4
0
    def setUp(self):
        self.amity = Amity()
        self.amity.room_types = {
            "office": {Office('MOMBASA'): ['Lavender Ayodi'],
                       Office('HOGWARTS'): [],
                       Office('LAGOS'): []},
            "livingspace": {LivingSpace('KENYA'): [],
                            LivingSpace('PLATFORM'): [],
                            LivingSpace('VALHALLA'): []}
        }

        self.amity.persons = {
            'fellow': [Fellow('Lavender Ayodi')],
            'staff': [Staff('John Doe')]
        }
Exemplo n.º 5
0
    def setUp(self):
        self.test_amity = Amity()
        """Create living space"""
        self.test_amity.create_room({
            "<room_name>": ["LivingA"],
            "Living": True,
            "Office": False
        })
        """Create office"""
        self.test_amity.create_room({
            "<room_name>": ["OfficeA"],
            "Living": False,
            "Office": True
        })

        # Assign rooms to variables
        self.livinga = self.test_amity.livingspaces[0]
        self.officea = self.test_amity.offices[0]
        """Add fellow that wants space"""
        self.test_amity.add_person({
            "<first_name>": "Test",
            "<last_name>": "Fellow",
            "<wants_space>": "Y",
            "Fellow": True,
            "Staff": False
        })
        """Add staff member that wants space"""
        self.test_amity.add_person({
            "<first_name>": "Test",
            "<last_name>": "Staff",
            "<wants_space>": "Y",
            "Fellow": False,
            "Staff": True
        })
        # Assign people to variables
        self.testfellow = self.test_amity.people[0]
        self.teststaff = self.test_amity.people[1]
Exemplo n.º 6
0
class AmityApp(cmd.Cmd):
    intro = cprint(figlet_format("Amity Room App", font="cosmic"), "white")
    prompt = 'Amity>>> '
    # file = None

    amity = Amity()

    @docopt_cmd
    def do_create_room(self, arg):
        """
        Creates a new room in the system.
        Usage: create_room <room_name> <room_type>
        """
        room_name = arg["<room_name>"]
        room_type = arg["<room_type>"]
        print(self.amity.create_room(room_name, room_type))

    @docopt_cmd
    def do_add_person(self, arg):
        """
        Creates a new person and assigns them to a random room in Amity.
        Usage: add_person <first_name> <second_name> <person_type> [--Y]
        """
        person_name = arg["<first_name>"] + " " + arg["<second_name>"]
        person_type = arg["<person_type>"]
        wants_accomodation = arg["--Y"]

        if wants_accomodation is False:
            wants_accomodation = "N"

        print(
            self.amity.add_person(person_name, person_type,
                                  wants_accomodation))

    @docopt_cmd
    def do_reallocate_person(self, arg):
        """
        Reallocates a person to a new room of their choice.
        Usage: reallocate_person <first_name> <second_name> <new_room>
        """
        new_room_name = arg["<new_room>"]
        person_name = arg["<first_name>"] + " " + arg["<second_name>"]
        print(self.amity.reallocate_person(person_name, new_room_name))

    @docopt_cmd
    def do_load_people(self, arg):
        """
        Loads people into the Amity system from a text file.
        Usage: load_people <filename>
        """
        print(self.amity.load_people(arg["<filename>"]))

    @docopt_cmd
    def do_print_allocations(self, arg):
        """
        Prints and outputs the people who have been successfully allocated
        a space per room.
        Usage: print_allocations <filename>
        """
        filename = arg['<filename>']
        print(self.amity.print_allocations(filename))

    @docopt_cmd
    def do_print_unallocated(self, arg):
        """
        Prints and outputs the people who have been not yet been allocated
        a room.
        Usage: print_unallocated <filename>
        """
        filename = arg['<filename>']

        print(self.amity.print_unallocated(filename))

    @docopt_cmd
    def do_print_room(self, arg):
        """
        Prints the people who have been allocated the specified room.
        Usage: print_room <room_name>
        """
        room_name = arg['<room_name>']
        print(self.amity.print_room(room_name))

    @docopt_cmd
    def do_save_state(self, arg):
        """
        Saves the data to a SQLite database
        Usage: save_state <db_name>
        """
        db_name = arg["<db_name>"]

        print(self.amity.save_state(db_name))

    @docopt_cmd
    def do_load_state(self, arg):
        """
        Loads the data to a SQLite database
        Usage: load_state <db_name>
        """
        db_name = arg["<db_name>"]

        print(self.amity.load_state(db_name))

    def do_quit(self, arg):
        """Quits out of Interactive Mode."""

        print('Till next time, Good Bye!')
        exit()
Exemplo n.º 7
0
        else:
            pretty_print_data(rooms)

    @docopt_cmd
    def do_allocate_unallocated(self, args):
        """
        Randomly allocate rooms to unallocated people
        Usage: allocate_unallocated [-f|-s]
        """
        result = amity.randomly_allocate_unallocated()
        if result:
            allocated_staff = amity.translate_staff_data_to_dict(
                result['staff'])
            allocated_fellows = amity.translate_fellow_data_to_dict(
                result['fellows'])
            print_subtitle("Newly Allocated")
            if args['-s']:
                pretty_print_data(allocated_staff)
            elif args['-f']:
                pretty_print_data(allocated_fellows)
            else:
                pretty_print_data(allocated_staff + allocated_fellows)


opt = docopt(__doc__, sys.argv[1:], True, 2.0)

if opt['--interactive']:
    print_header()
    amity = Amity()
    AmityInteractive().cmdloop()
Exemplo n.º 8
0
 def setUp(self):
     self.amityville = Amity()
Exemplo n.º 9
0
class AmityApp(cmd.Cmd):
    intro = colored(
        '\n\t\t\t\tWelcome to Amity!\n\t    -Type help for a '
        'list of instructions on how to use the app-', 'green')
    prompt = colored('\n\nAmity >> ', 'magenta')
    amity = Amity()

    @docopt_cmd
    def do_create_room(self, args):
        """Usage: create_room <room_type> <room_name>..."""
        room_type = args['<room_type>']
        room_list = args['<room_name>']

        for name in room_list:
            self.amity.create_room(name, room_type)
            sleep(0.2)

    @docopt_cmd
    def do_add_person(self, args):
        """
        Usage: add_person <designation> <first_name> <second_name> \
[-a <wants_accommodation>]

Options:
    -a <wants_accommodation>  Whether person wants accommodation [default: N]
        """
        designation = args['<designation>']
        first_name = args['<first_name>']
        second_name = args['<second_name>']
        wants_accommodation = args['-a']

        if wants_accommodation.upper() not in ["Y", "N"]:
            print("\n<wants_accommodation> should either be 'Y' or 'N' and is "
                  "not an option for STAFF persons")

        elif designation.upper() in ["FELLOW", "F"]:
            if wants_accommodation.upper() == 'Y':
                self.amity.add_fellow(first_name, second_name, "Y")
            else:
                self.amity.add_fellow(first_name, second_name)

        elif designation.upper() in ["STAFF", "S"]:
            if wants_accommodation != 'N':
                print("\n  STAFF persons cannot be allocated living spaces")

            else:
                self.amity.add_staff(first_name, second_name)

        else:
            print("\n  Invalid Employee designation. Designation should be "
                  "either 'Staff' or 'Fellow'")

    @docopt_cmd
    def do_reallocate_person(self, args):
        """Usage: reallocate_person <employee_id> <new_room_name>"""

        employee_id = args['<employee_id>']
        new_room_name = args['<new_room_name>']

        self.amity.reallocate_person(employee_id, new_room_name)

    @docopt_cmd
    def do_load_people(self, arg):
        """Usage: load_people <file_name>"""

        self.amity.load_people(arg["<file_name>"])

    @docopt_cmd
    def do_print_allocations(self, arg):
        """
    Usage: print_allocations [-f <file_name>]

Options:
    -f <file_name>  Output to file
        """
        if arg['-f']:
            self.amity.print_allocations(arg['-f'])

        else:
            self.amity.print_allocations()

    @docopt_cmd
    def do_print_unallocated(self, arg):
        """
        Usage: print_unallocated [-f <file_name>]

Options:
    -f <unallocated.txt>  Output to file
        """
        if arg['-f']:
            self.amity.print_unallocated(arg['-f'])

        else:
            self.amity.print_unallocated()

    @docopt_cmd
    def do_print_room(self, arg):
        """Usage: print_room <room_name>"""

        room_name = arg['<room_name>']

        if room_name.isalpha():
            self.amity.print_room(room_name)

        else:
            print("\n  Invalid room name. Room name should consist of "
                  "alphabetical characters only")

    @docopt_cmd
    def do_save_state(self, arg):
        """Usage: save_state [--db <database_name>]

Options:
    --db <database_name>  Save to specified database(default is set to 'Amity')
        """
        if arg['--db']:
            self.amity.save_state(arg['--db'])

        else:
            self.amity.save_state()

    @docopt_cmd
    def do_load_state(self, arg):
        """Usage: load_state [--db <sqlite_database>]

Options:
    --db <database_name>  Load from specified database(default is set to
    'Amity')
        """
        if arg['--db']:
            self.amity.load_state(arg['--db'])

        else:
            self.amity.load_state()

    @docopt_cmd
    def do_help(self, arg):
        """Usage: help"""

        print('''
\t\t\t\t   Commands:
   create room <room_type> <room_name> ...
   add person <first_name> <second_name> <designation> [wants_accommodation]
   reallocate person <employee_id> <new_room_name>
   print_allocations [-o=allocations.txt]
   print_unallocated [-o=unallocated.txt]
   print room <room_name>
   load_people <file_name>
   save_state [--db=sqlite_database]
   load_state <sqlite_database>
   help
-Words enclosed in angle brackets '< >' should guide you on the required
 number of arguments, except when they appear like this: '< >...' when any
 number of arguments is allowed.
-Square brackets '[]' denote optional arguments.
-Separate different arguments with a space.
\n\t\t\t  ||Type exit to close the app||
                   ''')

    @docopt_cmd
    def do_exit(self, arg):
        """Usage: exit"""
        print('\n\n' + '*' * 60 + '\n')
        cprint('\t\tThank you for using Amity!\n', 'green')
        print('*' * 60)
        style = Figlet(font='pebbles')
        cprint(style.renderText('Good Bye!'), 'magenta')
        exit()