Exemple #1
0
 def test_relocate_person(self):
     person = Person.add_person("New", "Per", 'staff')
     office = Office.create("R Office")
     print(office.id, office.name)
     self.assertNotEqual(person.office.id, office.id)
     person.relocate("R Office")
     self.assertEqual(person.office.id, office.id)
Exemple #2
0
 def test_add_staff_with_location_request(self):
     current_count = Person.all().count()
     person = Person.add_person("New",
                                "Staff",
                                "Staff",
                                wants_accommodation=True)
     self.assertEqual(current_count + 1, Person.all().count())
     self.assertIsNotNone(person.office_id)
     self.assertIsNone(person.living_space_id)
Exemple #3
0
 def test_add_fellow_without_location_request(self):
     current_count = Person.all().count()
     person = Person.add_person("New",
                                "Fellow",
                                "Fellow",
                                wants_accommodation=False)
     self.assertEqual(current_count + 1, Person.all().count())
     self.assertIsNotNone(person.office_id)
     self.assertIsNone(person.living_space_id)
Exemple #4
0
 def test_print_room(self):
     person = Person.add_person("New", "Person", "staff")
     self.arguments = {
         '<first_name>': None,
         '<last_name>': None,
         '<role>': None,
         '<room_name>': [person.office.name],
         '<room_type>': None,
         '<wants_accommodation>': None,
         'add_person': False,
         'create_room': False,
         'print_room': True
     }
     self.assertIn('%s, %s' % (person.name, person.role),
                   handle(self.arguments))
Exemple #5
0
def handle(_arguments):
    """Handle commands and argument"""

    try:
        if _arguments.get('create_room'):
            room_name = _arguments.get('<room_name>')
            room_type = _arguments.get('<room_type>').replace(' ', '_').lower()
            new_rooms = Room.create_multiple(room_type, room_name)
            return [
                "A(n) %s called %s has been successfully created" %
                (room.room_type.capitalize(), room.name) for room in new_rooms
            ]

        elif _arguments.get('add_person'):
            first_name = _arguments.get('<first_name>')
            last_name = _arguments.get('<last_name>')
            role = _arguments.get('<role>')
            wants_accommodation = True if _arguments.get(
                '<wants_accommodation>') == 'Y' else False
            person = Person.add_person(first_name,
                                       last_name,
                                       role,
                                       wants_accommodation=wants_accommodation)
            result = [
                "%s %s has been successfully added" %
                (person.role.capitalize(), person.name),
                "%s has been allocated the Office %s" %
                (person.name, person.office.name)
            ]
            if role.lower() == Person.FELLOW and wants_accommodation:
                result.append("%s has been allocated the Living Space %s" %
                              (person.name, person.living_space.name))
            return result

        elif _arguments.get('print_room'):
            room = Room.get_by_name(_arguments.get('<room_name>')[0])
            if room:
                return [
                    ", ".join([person.name, person.role])
                    for person in room.get_people()
                ] or ['No one here yet']
            return ['Ooops.. Room Does not exist']

        elif _arguments.get('print_allocations'):
            allocations = [
                "%s in %s Office and %s Living Space" % allocation
                for allocation in Person.get_allocations()
            ]
            if '--o' in _arguments:
                file = open(_arguments.get('--o'), 'w')
                file.write("\n".join(allocations))
                file.close()
                return [
                    "Allocations written to %s file" % _arguments.get('--o')
                ]
            return allocations

        elif _arguments.get('relocate_person'):
            person = Person.all().get(
                int(_arguments.get("<person_identifier>")))
            room_name = _arguments.get("<new_room_name>")
            person.relocate(room_name)
            return ['%s has been relocated to %s' % (person.name, room_name)]

        elif _arguments.get('load_people'):
            file = open(_arguments.get("<file_name>"))
            people_list = file.readlines()
            people = Person.load_people(people_list)
            p = []
            for key in people:
                text = "%s\n------------------------------------\n %s" % (
                    key, ", ".join(people[key]))
                p.append(text)
            return p
        elif _arguments.get('save_state'):
            db_file = _arguments.get('--db')
            copyfile('dojo.db', db_file)
            return ["Data successfully saved to %s" % db_file]
        elif _arguments.get('load_state'):
            db_file = _arguments.get('<sqlite_database>')
            copyfile(db_file, 'dojo.db')
            return ["Data successfully loaded from %s" % db_file]
    except KeyboardInterrupt:
        return
    except Exception as e:
        return ["Ooops Something unexpected happened: %s" % str(e)]