예제 #1
0
class App(cmd.Cmd):

    intro = 'A Room Allocation system for Andela Kenya facility Known As the dojo'
    prompt = '(dojo_space)'
    dojo = Dojo()

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

        if room_type == "office" or room_type == "living":
            self.dojo.create_room(room_type, room_name)
        else:
            print(
                "You've entered an invalid room type. Please choose either office or living"
            )

    @docopt_cmd
    def do_add_person(self, arg):
        """
        Usage: add_person <first_name> <last_name> <role> [<wants_accommodation>]
        """

        first_name = arg["<first_name>"]
        last_name = arg["<last_name>"]
        role = arg["<role>"]
        accommodation = arg["<wants_accommodation>"]

        self.dojo.add_person(first_name, last_name, role, accommodation)

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

    @docopt_cmd
    def do_print_allocation(self, arg):
        """
        Usage: print_allocation [<filename>]
        """
        self.dojo.print_allocations(arg["<filename>"])

    @docopt_cmd
    def do_print_unallocated(self, arg):
        """
        Usage: print_unallocated [<filename>]
        """
        self.dojo.print_unallocated(arg["<filename>"])

    def do_quit(self, arg):
        """ Quits out of program"""

        print('See you next time!')
        exit()
예제 #2
0
	def test_create_room_complete(self):
		dojo = Dojo()
		initial_room_count = len(dojo.list_of_rooms)
		black_office = dojo.create_room("Black", "office")
		self.assertTrue(black_office, "An office called black has been created")
		new_room_count = len(dojo.list_of_rooms)
		self.assertEqual(new_room_count - initial_room_count, >1)
예제 #3
0
 def test_load_state(self):
     """test for retrieving the current state from the database"""
     my_instance = Dojo()
     people_initial_list = len(my_instance.people)
     my_instance.load_state("alloc")
     people_new_list = len(my_instance.people)
     self.assertTrue(people_new_list > people_initial_list)
예제 #4
0
 def test_successful_print_list_of_unallocated_on_screen(self):
     """ test successful printing of names of people not allocated a room on screen"""
     self.dojo = Dojo()
     self.dojo.add_person('Diego', 'Pamio', 'FELLOW')
     self.dojo.print_unallocated()
     saved = sys.stdout
     output = saved.getvalue()
     self.assertIn('Diego Pamio', output)
예제 #5
0
 def test_create_office_successfully(self):
     dojo = Dojo()
     number_of_offices = len(dojo.offices_created)
     new_office = dojo.create_room("office", "Fox")
     new_number_of_offices = len(dojo.offices_created)
     self.assertEqual(number_of_offices + 1,
                      new_number_of_offices,
                      msg='New office Not Added')
예제 #6
0
 def test_create_livingspace_successfully(self):
     dojo = Dojo()
     number_of_livingspaces = len(dojo.livingspaces_created)
     new_livingspace = dojo.create_room("livingspace", "Uganda")
     new_number_of_livingspaces = len(dojo.livingspaces_created)
     self.assertEqual(number_of_livingspaces + 1,
                      new_number_of_livingspaces,
                      msg='New livingspace Not Added')
예제 #7
0
 def test_successful_print_list_of_allocation_on_screen(self):
     """ test successful printing of names of people allocated a room on screen"""
     self.dojo = Dojo()
     self.dojo.create_room("office", ["kenya"])
     self.dojo.add_person('Kevin', 'Oriels', 'FELLOW')
     self.dojo.print_allocations()
     saved = sys.stdout
     output = saved.getvalue()
     self.assertIn('Kevin Oriels', output)
예제 #8
0
 def test_create_room_already_taken(self):
     dojo = Dojo()
     dojo.create_room("office", "MergeConflict")
     self.assertEqual(dojo.create_room("office", "MergeConflict"),
                      "MergeConflict already exists",
                      msg='Room already exists')
     self.assertEqual(dojo.create_room("livingspace", "MergeConflict"),
                      "MergeConflict already exists",
                      msg='Room already exists')
예제 #9
0
    def test_can_print_empty_room(self):
        """ test  printing of names of people in room_name that does not exist """

        self.dojo = Dojo()
        self.dojo.create_room("office", ["kenya"])
        self.dojo.print_room("kenya")
        saved = sys.stdout
        output = saved.getvalue()
        self.assertIn("office space kenya contains no occupants", output)
예제 #10
0
    def test_cannot_print_list_for_room_not_existing(self):
        """ test unsuccessful printing of names of people in room_name that does not exist """

        self.dojo = Dojo()
        self.dojo.create_room("office", ["kenya"])
        self.dojo.print_room("Britain")
        saved = sys.stdout
        output = saved.getvalue()
        self.assertIn("Sorry.That rooms does not exist.", output)
예제 #11
0
 def test_add_staff_successfully(self):
     dojo = Dojo()
     dojo.create_room("office", "Office1")
     dojo.create_room("office", "Office2")
     number_of_staff = len(dojo.staff_added)
     new_staff = dojo.add_person("Maria", "staff")
     new_number_of_staff = len(dojo.staff_added)
     self.assertEqual(number_of_staff + 1,
                      new_number_of_staff,
                      msg='New staff Not Added')
예제 #12
0
    def test_can_add_staff(self):
        """ Test successful addition of staff """

        self.dojo = Dojo()
        self.dojo.create_room("office", ["kenya", "uganda"])
        self.dojo.create_room("living", ["Nairobi", "Kampala"])
        self.assertEqual(len(self.dojo.total_people), 0)
        self.dojo.add_person('Fred', 'Flint', 'STAFF')
        self.assertEqual(len(self.dojo.total_people), 1,
                         ' staff member(s) has been added to the system!')
예제 #13
0
    def test_can_print_names_of_people_in_room_on_screen(self):
        """ test successful printing of names of people in room_name on screen"""

        self.dojo = Dojo()
        self.dojo.create_room("office", ["kenya"])
        self.dojo.add_person('Kevin', 'Oriels', 'FELLOW')
        self.dojo.print_room("kenya")
        saved = sys.stdout
        output = saved.getvalue()
        self.assertIn("office space kenya contains Kevin Oriels", output)
예제 #14
0
 def test_successful_print_list_of_unallocated_to_txt_file(self):
     """ test successful printing of names of people not allocated a room to a txt file """
     self.dojo = Dojo()
     self.dojo.add_person('Diego', 'Pamio', 'FELLOW')
     self.dojo.add_person('Trent', 'Renzor', 'FELLOW', 'Y')
     self.dojo.print_unallocated("unallocated_persons")
     self.assertTrue(os.path.isfile("unallocated_persons.txt"))
     unallocated_file = open("unallocated_persons.txt").readlines()
     first_line = unallocated_file[4]
     self.assertEquals(first_line, "Diego Pamio, Trent Renzor\n")
     os.remove("unallocated_persons.txt")
예제 #15
0
 def test_add_fellow_with_accommodation_successfully(self):
     dojo = Dojo()
     dojo.create_room("office", "Office1")
     dojo.create_room("office", "Office2")
     dojo.create_room("livingspace", "livingspace1")
     dojo.create_room("livingspace", "livingspace2")
     number_of_fellows = len(dojo.fellows_added)
     new_fellow = dojo.add_person("Martina", "fellow", "Y")
     new_number_of_fellows = len(dojo.fellows_added)
     self.assertEqual(number_of_fellows + 1,
                      new_number_of_fellows,
                      msg='New fellow Not Added')
예제 #16
0
 def test_add_staff_with_accommodation_unsuccessfully(self):
     dojo = Dojo()
     dojo.create_room("office", "Office1")
     dojo.create_room("office", "Office2")
     dojo.create_room("livingspace", "livingspace1")
     dojo.create_room("livingspace", "livingspace2")
     number_of_staff = len(dojo.staff_added)
     new_staff = dojo.add_person("Maria", "staff", "Y")
     new_number_of_staff = len(dojo.staff_added)
     self.assertEqual(number_of_staff,
                      new_number_of_staff,
                      msg='Staff cannot be allocated livingspace')
예제 #17
0
    def test_can_add_person(self):
        """ Test successful addition of person """

        self.dojo = Dojo()
        self.dojo.create_room("office", ["kenya", "uganda"])
        self.dojo.create_room("living", ["Nairobi", "Kampala"])
        self.dojo.add_person('Kevin', 'Oriels', 'FELLOW')
        self.dojo.add_person('John', 'john', 'STAFF', '')
        self.dojo.add_person('Anne', 'Ndinda', 'FELLOW', 'Y')
        self.dojo.add_person('Steve', 'Mcmon', 'FELLOW', 'N')
        self.assertEqual(len(self.dojo.total_people), 4,
                         'Person(s) were added to the system!')
예제 #18
0
    def test_can_add_fellow(self):
        """ Test successful addition of fellows"""

        self.dojo = Dojo()
        self.dojo.create_room("office", ["kenya", "uganda"])
        self.dojo.create_room("living", ["Nairobi", "Kampala"])
        self.assertEqual(len(self.dojo.total_people), 0)
        self.dojo.add_person('Joe', 'jameson', 'FELLOW', 'Y')
        self.dojo.add_person('James', 'konia', 'FELLOW')
        self.dojo.add_person('Larry', 'smith', 'FELLOW', 'N')
        self.assertEqual(len(self.dojo.total_people), 3,
                         'staff member(s) were added to the system!')
예제 #19
0
    def test_cannot_add_person_with_missing_arguments(self):
        """ Test failure in addition of persons with Missing arguments """

        self.dojo = Dojo()
        self.dojo.create_room("office", ["kenya", "uganda"])
        self.dojo.create_room("living", ["Nairobi", "Kampala"])
        self.num_of_people = len(self.dojo.total_people)
        self.dojo.add_person('Kevin', '', '')
        self.dojo.add_person('', '', '', 'Y')
        self.dojo.add_person('', '', '', '')
        self.assertEqual(
            len(self.dojo.total_people), self.num_of_people,
            'Person(s) cannot be created without necessary credentials')
예제 #20
0
def main():
    
    dojo = Dojo(StockAgent, StockAgent, 'n7/5k2/8/8/8/8/8/3R3K w - - 0 1')
    (history, result) = dojo.play()
    
    mydir = 'results/svg/'
    filelist = [ f for f in os.listdir(mydir) if f.endswith(".svg") ]
    for f in filelist:
        os.remove(os.path.join(mydir, f))

    for i in range(len(history)-1):
        with open('{}move_{}.svg'.format(mydir, i), 'w') as f:
            f.write(history[i])
    print(result)
예제 #21
0
 def test_successful_print_list_of_allocation_to_txt_file(self):
     """ test successful printing of names of people allocated a room to a txt file """
     self.dojo = Dojo()
     self.dojo.create_room("office", ["kenya"])
     self.dojo.create_room("living", ["Nairobi"])
     self.dojo.add_person('Kevin', 'Oriels', 'FELLOW')
     self.dojo.print_allocations("allocated_persons")
     self.assertTrue(os.path.isfile("allocated_persons.txt"))
     allocated_file = open("allocated_persons.txt").readlines()
     first_line = allocated_file[1]
     third_line = allocated_file[5]
     self.assertEquals(first_line, "kenya \n")
     self.assertEquals(third_line, "Kevin Oriels\n")
     os.remove("allocated_persons.txt")
예제 #22
0
class DojoRoomAllocation(cmd.Cmd):
    os.system("clear")

    prompt = '\n ==== > DojoRoomAllocation: '
    dojo = Dojo()

    @docopt_cmd
    def do_create_room(self, arg):
        """Usage: create_room <room_type> <room_names>...
        """
        try:
            for room_name in arg['<room_names>']:
                print(dojo.create_room(arg['<room_type>'], room_name))
        except Exception:
            msg = term.red + 'An error when running create_room command' + term.off

    @docopt_cmd
    def do_add_person(self, arg):
        """Usage:
        add_person <first_name> <last_name> <person_type> [--wants_accomodation=None]
        """
        try:
            first_name = arg["<first_name>"]
            last_name = arg["<last_name>"]
            person_type = arg["<person_type>"]
            wants_accomodation = arg["--wants_accomodation"]
            print(
                person.add_person(first_name, last_name, person_type,
                                  wants_accomodation))

        except Exception:
            msg = term.red + 'An error when running add_person command' + term.off

    def do_quit(self, arg):
        """Usage: quit

        """

        os.system('clear')
        print('Thank you for using our app. Hope to see you back soon')
        exit()
예제 #23
0
 def test_create_room_without_passing_arguments_unsuccessfully(self):
     dojo = Dojo()
     self.assertRaises(TypeError, dojo.create_room)
예제 #24
0
	def test_room_already_exists(self):
		dojo = Dojo()
		black_office = dojo.create_room("Black", "office")
		black_exists = dojo.room_exists("Black")
예제 #25
0
class App(cmd.Cmd):
    print("WELCOME TO DOJO ROOM ALLOCATION")
    print("")
    print("ROOM ALLOCATION COMMANDS")
    print("")
    print("1.  create_room <room_type> <room_name> ...")
    print("2.  add_persons <name> <role> [<wants_accommodation>]")
    print("3.  print_room <room_name>")
    print("4.  print_allocations [<file_name>]")
    print("5. quit")
    print("")

    prompt = '(Dojo)'
    dojo = Dojo()

    @docopt_cmd
    def do_create_room(self, arg):

        """
        Usage: create_room <room_type> <room_name>...
        """
        room_name = arg["<room_name>"]
        room_type = arg["<room_type>"]
        if room_name and room_type:
            self.dojo.create_room(room_type,room_name)

    @docopt_cmd
    def do_add_persons(self, arg):

        """
        Usage: add_persons <first_name> <role> [<wants_accommodation>]
        """

        first_name = arg["<first_name>"]
        role = arg["<role>"].upper()
        accommodation = arg["<wants_accommodation>"]
        if accommodation is None:
            accommodation = "N"

        accommodation.upper()
        self.dojo.add_persons(first_name, role, accommodation)

    @staticmethod
    def do_quit(self):

        """ Quits out of program"""

        print('Thank you for using Dojo!')
        print('See you next time!')
        print('THIS IS ANDELA')
        exit()

    @docopt_cmd
    def do_print_room(self, arg):
        """
        Usage: print_room <room_name>
        """
        room_name = arg["<room_name>"]
        if room_name is not None:
            self.dojo.print_room(room_name)

    @docopt_cmd
    def do_print_allocations(self, arg):

        """
        Usage: print_allocations [<filename>]
        """
        self.dojo.print_allocations(arg["<filename>"])
예제 #26
0
class MyInteractive(cmd.Cmd):
    def introduction():

        print("dojo space allocation!".center(70))
        print("1. create_room <room_type> <room_name>...".center(70))

        print(
            "2. add_person <first_name> <last_name> <person_type> <wants_space>"
            .center(70))

        print("3. print_allocated".center(70))

        print("4. print_unallocated".center(70))

        print("other commands:".center(70))

        print("1. help".center(70))

        print("2. Exit".center(70))

    intro = introduction()
    prompt = '(dojo)'
    file = None

    dojo = Dojo()

    @docopt_cmd
    def do_create_room(self, args):
        """Usage: create_room <room_type> <room_name>..."""
        room_name = args["<room_name>"]
        room_type = args["<room_type>"]
        if room_type == "living":
            self.dojo.create_room(room_type, room_name)
        if room_type == "office":
            self.dojo.create_room(room_type, room_name)

    @docopt_cmd
    def do_add_person(self, args):
        """Usage: add_person <first_name> <last_name> <person_type> <wants_space>"""
        first_name = args["<first_name>"]
        last_name = args["<last_name>"]

        person_type = args["<person_type>"]
        wants_space = args["<wants_space>"]
        person_name = (first_name + " " + last_name)
        if person_type == "fellow":
            self.dojo.add_person(person_name, "fellow", wants_space)
        if person_type == "staff":
            self.dojo.add_person(person_name, "staff", wants_space)

    @docopt_cmd
    def do_print_room(self, args):
        """Usage: print_room <room_name>"""
        room_name = args["<room_name>"]
        self.dojo.print_room(room_name)

    @docopt_cmd
    def do_print_allocated(self, args):
        """Usage: print_allocated"""
        self.dojo.print_allocated()

    @docopt_cmd
    def do_print_unallocated(self, args):
        """Usage: print_allocated"""
        self.dojo.print_unallocated()

    @docopt_cmd
    def do_exit(self, args):
        """Exit"""

        exit()
예제 #27
0
 def setUp(self):
     self.class_instance = Dojo()
예제 #28
0
 def setUp(self):
     """setup defaults"""
     self.held, sys.stdout = sys.stdout, StringIO()
     self.my_instance = Dojo()
예제 #29
0
 def setUp(self):
     self.dojo = Dojo()
예제 #30
0
    app.py load_state <sqlite_database>
    app.py (-i | --interactive)
    app.py (-h | --help | --version)

Options:
    -i, --interactive  Interactive Mode
    -h, --help  Show this screen and exit.
"""

import sys
import cmd
from docopt import docopt, DocoptExit
from pyfiglet import Figlet
from termcolor import colored, cprint
from dojo import Dojo
dojo = Dojo()


def docopt_cmd(func):
    """
    This decorator is used to simplify the try/except block and pass the result
    of the docopt parsing to the called action.
    """

    def fn(self, args):
        try:
            opt = docopt(fn.__doc__, args)

        except DocoptExit as e:
            # This is thrown if a false command is given.
            print('Invalid Command!')