def test_amity_load_person(self):
     self.create_room()
     amity = Amity('load_people')
     amity.people = []
     args = {
         '<file_location>': 'data/people_test.txt',
     }
     amity.run_command(args)
     self.assertEqual(len(amity.people), 2)
 def create_room(self):
     amity = Amity('create_room')
     args = {
         '<room_name>':
         ['testRoom 1', 'testRoom 2', 'testRoom 3', 'testRoom 1'],
         '<room_type>': ['living', 'office', 'living'],
     }
     amity.rooms = []  # make sure the rooms list is empty
     amity.run_command(args)
     return amity
 def add_person(self, living_space=True, reset=True):
     amity = Amity('add_person')
     args = {
         '<firstname>': 'test',
         '<lastname>': 'user',
         '<person_type>': 'fellow',
         '-w': living_space,
     }
     if reset:
         amity.people = []  # make sure the people list is empty
     amity.run_command(args)
     return amity
 def test_amity_allocate_person(self):
     self.create_room()
     self.add_person(False)
     amity = Amity('allocate_person')
     person = amity.people[-1]  # Select the last added
     args = {
         '<person_id>': person.uid,
         '<new_room_name>': 'testRoom 1',
         '-w': True,
     }
     amity.run_command(args)
     self.assertEqual(amity.people[-1].assigned_room['LIVINGSPACE'],
                      'TESTROOM 1')
     self.assertEqual(amity.people[-1].is_allocated, True)
 def test_amity_reallocate_person(self):
     self.create_room()
     self.add_person()
     amity = Amity('reallocate_person')
     person = amity.people[0]
     new_room = "TESTROOM 3" if person.assigned_room[
         'LIVINGSPACE'] == 'TESTROOM 1' else "TESTROOM 1"
     args = {
         '<person_id>': person.uid,
         '<new_room_name>': new_room,
         '-l': True,
     }
     amity.run_command(args)
     self.assertEqual(amity.people[0].assigned_room['LIVINGSPACE'],
                      new_room)
 def test_amity_remove_person(self):
     self.create_room()
     self.add_person()
     amity = Amity('remove_person')
     person = amity.people[-1]  # Select the last added
     args = {
         '<person_id>': person.uid,
         '<current_room_name>': person.assigned_room['LIVINGSPACE'],
     }
     amity.run_command(args)
     room = [room for room in amity.rooms if room.name == 'TESTROOM 1']
     if room:
         old_person = [
             p for p in room[0].people if p.name() == person.name()
         ]
     self.assertEqual(old_person, [])
Exemple #7
0
"""
from docopt import docopt
from src.amity import Amity

#function mapping to avoid long if else chain
func_map = [
    'create_room',
    'add_person',
    'reallocate_person',
    'load_people',
    'print_allocations',
    'print_unallocated',
    'print_room',
    'save_state',
    'load_state',
    'list_people',
    'list_rooms',
    'allocate_person',
    'remove_person',
    'clear',
]

if __name__ == '__main__':
    arguments = docopt(__doc__)

    for command in func_map:
        if arguments[command]:
            amity = Amity(command)
            amity.run_command(arguments)
            break