def test_view_available(self):

        '''
        Test whether user can view a slot that has been made available
        '''
        orig_stdout = sys.stdout
        new_string = StringIO()
        sys.stdout = new_string
        service = startup()
        username, email = 'ikalonji', '*****@*****.**'
        create.create(service, username, email)
        days_to_display = 7
        events = view_available.view_open_bookings(service, days_to_display)
        self.assertTrue(events==True, 'Not true')
        sys.stdout = orig_stdout
示例#2
0
    def test_create_n(self):
        """
        Test Create function for confirming the creation of an event for n
        """
        service = code_clinic.startup()
        home = os.path.expanduser("~")
        username, email, name = code_clinic.get_credentials(home)

        summary = 'Test_create'
        descript = 'Test function create'
        startdate = datetime.datetime.now().date() + datetime.timedelta(days=5)
        starttime = '12:30'


        testdate=str(startdate.day)+"/"+str(startdate.month)+"/"+\
            str(startdate.year)
        with patch(
                'sys.stdin',
                StringIO(f'{testdate}\n{starttime}\n{summary}\
            \n{descript}\nn\n')):
            orig_stdout = sys.stdout
            new_string = StringIO()
            sys.stdout = new_string
            event_id = create.create(service, username, email)
            output = sys.stdout.getvalue().strip()
            self.assertTrue("Event not created", output)
            delete.do_delete(service, email, event_id)
            sys.stdout = orig_stdout
示例#3
0
    def test_create_wrong_date(self):
        """
        Test Create function if the date is older than now
        """
        service = code_clinic.startup()
        home = os.path.expanduser("~")
        username, email, name = code_clinic.get_credentials(home)

        testdate = "01/01/01"
        with patch('sys.stdin', StringIO(f'{testdate}\n')):
            orig_stdout = sys.stdout
            new_string = StringIO()
            sys.stdout = new_string
            create.create(service, username, email)
            output = sys.stdout.getvalue().strip()
            self.assertTrue(f"Bye {username}", output)
            sys.stdout = orig_stdout
示例#4
0
def run_clinic():
    '''Function to run Code Clinic and parse through commands from user'''

    service = startup()
    home = os.path.expanduser("~")
    username, email, name = '', '', ''
    username = username.upper()

    if os.path.exists(f"{home}/.config.ini"):
        username, email, name = get_credentials(home)

    option_req_args = ['book', 'delete', 'cancel']
    valid_option = [
        'add', 'view_created', 'view_available', 'view_booked', 'config',
        'version'
    ]
    uuid = None
    option = None

    # check if option was provided, if not default to help
    try:
        option = sys.argv[1]
    except IndexError as IndErr:
        pass

    # Check if provided option requires the uuid, if so and not provided, exit with a message
    if option in option_req_args:
        try:
            uuid = sys.argv[2]
        except IndexError as IndErr:
            print("This option requires a <uuid>")

    if option == 'help' or option == None:
        print(f"Welcome {name}\n")
        help()
        return True
    elif not option in option_req_args and not option in valid_option:
        print("An Invalid option was provided, redirected to \'help\'")
        help()
    elif option == 'version':
        version()
    '''Statements to handle args received from clinician'''

    if option == 'add' and os.path.exists(f"{home}/.config.ini"):
        print(f"Welcome {name}\n")
        create.create(service, name, email)

    elif option == 'delete' and uuid != None and os.path.exists(
            f"{home}/.config.ini"):
        print(f"Welcome {name}\n")
        delete.delete(service, email, uuid)

    elif option == 'view_created' and os.path.exists(f"{home}/.config.ini"):
        print(f"Welcome {name}\n")
        view_events.view(service, email)

    # Statements to handle args received from the patient

    elif option == 'view_available' and os.path.exists(f"{home}/.config.ini"):
        print(f"Welcome {name}\n")
        #If specific amount of days is provided as an argument then only those amount
        # of days will be displayed, else default is 7 days
        try:
            days_to_display = int(sys.argv[2])
            view_available.view_open_bookings(service, days_to_display)
        except IndexError as IndErr:
            days_to_display = 7
            view_available.view_open_bookings(service, days_to_display)
        except ValueError as ValErr:
            days_to_display = 7
            view_available.view_open_bookings(service, days_to_display)
    elif option == 'book' and uuid != None and os.path.exists(
            f"{home}/.config.ini"):
        print(f"Welcome {name}\n")
        make_booking.booking(service, username, email, uuid)

    elif option == 'view_booked' and os.path.exists(f"{home}/.config.ini"):
        print(f"Welcome {name}\n")
        view_booking.view_booking(service, email)

    elif option == 'cancel' and uuid != None and os.path.exists(
            f"{home}/.config.ini"):
        print(f"Welcome {name}\n")
        cancel_booking.cancel_booking(service, username, email, uuid)

    elif option == 'config':
        print("Welcome to Code Clinic")
        make_config(home)

    elif not os.path.exists(f"{home}/.config.ini"):
        print("\n")
        print('No config file please add a config file')
        print('Please run:\n> python3 code_clinic.py config')