コード例 #1
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
コード例 #2
0
    def test_did_not_volunteer(self):
        service = startup()

        email = "*****@*****.**"
        orig_stdout = sys.stdout
        new_string = StringIO()
        sys.stdout = new_string
        result = view_events.view(service, email)

        self.assertEqual(result, 'You have not volunteered')
        sys.stdout = orig_stdout
コード例 #3
0
 def test_delete_invalid(self):
     service = code_clinic.startup()
     home = os.path.expanduser("~")
     username, email, name = code_clinic.get_credentials(home)
     orig_stdout = sys.stdout
     new_string = StringIO()
     sys.stdout = new_string
     delete.delete(service, email, 'tom')
     output = sys.stdout.getvalue().strip()
     self.assertTrue('Invalid ID' in output)
     sys.stdout = orig_stdout
コード例 #4
0
    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
コード例 #5
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
コード例 #6
0
    def test_delete_true(self):
        service = code_clinic.startup()
        home = os.path.expanduser("~")
        username, email, name = code_clinic.get_credentials(home)

        Summary = 'KLM'
        Description = 'klmno'
        startD = datetime.datetime.now().date() + datetime.timedelta(days=5)
        startT = '12:30'
        endT = '13:00'
        event = create.do_create(service, Summary, Description, startD, startT,
                                 endT, username, email)
        event_id = event['id']
        orig_stdout = sys.stdout
        new_string = StringIO()
        sys.stdout = new_string
        delete.delete(service, email, event_id)
        output = sys.stdout.getvalue().strip()
        self.assertTrue("Event Deleted" in output)
        sys.stdout = orig_stdout
コード例 #7
0
    def test_valid_user_event(self):
        service = startup()
        home = os.path.expanduser("~")
        user, email, name = get_credentials(home)
        date = datetime.datetime.now().date() + datetime.timedelta(days=5)
        summary = "Morglin Test Case"
        descript = "Testing"
        orig_stdout = sys.stdout
        new_string = StringIO()
        sys.stdout = new_string
        event=create.do_create(service,summary,descript,date,"12:00","12:30"\
            ,user,email)

        result = view_events.view(service, email)

        self.assertEqual(result, "You have volunteered")
        id = event['id']

        deleting = delete.do_delete(service, email, id)

        sys.stdout = orig_stdout
コード例 #8
0
    def test_delete_false(self):
        service = code_clinic.startup()
        home = os.path.expanduser("~")
        username, email, name = code_clinic.get_credentials(home)

        Summary = 'KLM'
        Description = 'klmno'
        startD = datetime.datetime.now().date() + datetime.timedelta(days=7)
        startT = '13:30'
        endT = '14:00'
        event = create.do_create(service, Summary, Description, startD, startT,
                                 endT, username, email)
        event_id = event['id']
        email2 = f'not{email}'
        orig_stdout = sys.stdout
        new_string = StringIO()
        sys.stdout = new_string
        delete.delete(service, email2, event_id)
        output = sys.stdout.getvalue().strip()
        self.assertTrue('Your are not allowed to delete this event' in output)
        delete.do_delete(service, email, event_id)
        sys.stdout = orig_stdout
コード例 #9
0
import code_clinic
from clinician import create
import datetime
from patient import make_booking, cancel_booking, view_booking, view_available

# for booking

summary = 'Testing for unittests Booking.'
description = 'Test booking and cancelling with the unittest as summary'
start_d = datetime.datetime.now().date() + datetime.timedelta(hours=24)
start_t = '10:00'
end_t = '10:30'

# functions that help with testing for booking and cancellations

service = code_clinic.startup()
creator, admin = "Fake Creator", "*****@*****.**"
create_slot = create.do_create(service, summary, description, start_d, start_t,
                               end_t, creator, admin)
test_id = create_slot['id']


class PatientTest(unittest.TestCase):
    def test_patient_make_booking(self):
        the_stdout = sys.stdout
        new_string = StringIO()
        sys.stdout = new_string
        username, email = "Booker", "*****@*****.**"
        book = make_booking.booking(service, username, email, test_id)
        test_result = f"{summary} is successfully booked.."
        self.assertTrue(book, test_result)
コード例 #10
0
import io
import sys
import unittest
import patient.view_booking as patient
from code_clinic import startup


service = startup()
class test_booked(unittest.TestCase):


    def test_no_slots_booked(self):
        patient.n = 0
        suppress_text = io.StringIO()
        sys.stdout = suppress_text 
   
        self.assertEqual(patient.view_booking(service,"*****@*****.**")
                         , "You have no booked slots\n")
        sys.stdout = sys.__stdout__


    def test_1_booked_slot(self):
        suppress_text = io.StringIO()
        sys.stdout = suppress_text 
        patient.n = 1
        self.assertEqual(patient.view_booking(service,"*****@*****.**")
                         , "\nYou have 1 booked slot\n")
        patient.n = 0
        sys.stdout = sys.__stdout__

    def test_2_booked_slots(self):