Exemple #1
0
class TestTimeBreakdown():
    @pytest.fixture()
    def fixture(self):
        self.user = User(1, "Derrick", "Foo", "*****@*****.**", "abc123")
        self.user1 = User(2, "Zainab", "Alasadi", "*****@*****.**",
                          "abc123***")

        self.event = Event(1, self.user, "COMP4920 Meeting", "Standup",
                           datetime.datetime(2017, 11, 28, 22, 45),
                           datetime.datetime(2017, 11, 28, 23, 45), "Work",
                           "Work")
        self.event1 = Event(2, self.user, "21st Birthday",
                            "Bday party at Sydney",
                            datetime.datetime(2017, 11, 28, 22, 45),
                            datetime.datetime(2017, 11, 28, 23,
                                              45), "Work", "Work")
        self.event_edit = Event(1, self.user, "COMP4920 Meeting 2.0", "Online",
                                datetime.datetime.now(),
                                datetime.datetime.now(), "Personal", "Work")
        self.workCal = Calendar("Work", "red", self.user)
        self.personalCal = Calendar("Personal", "blue", self.user1)

        self.workCal.addEvent(self.event)
        self.user.addCalendars(self.workCal)

    def test_category_hours(self, fixture):
        assert (self.user.calculateHoursCategory(
            "Work", datetime.datetime(2017, 11, 27, 22, 45)) == 1)

    def test_category_hours_multiple_calendars(self, fixture):
        self.personalCal.addEvent(self.event1)
        self.user.addCalendars(self.personalCal)
        assert (self.user.calculateHoursCategory(
            "Work", datetime.datetime(2017, 11, 27, 22, 45)) == 2)

    def test_category_hours_diff_weeks(self, fixture):
        self.workCal.addEvent(self.event_edit)
        assert (self.user.calculateHoursCategory(
            "Work", datetime.datetime(2017, 11, 27, 22, 45)) == 1)

    def test_category_hours_multiple(self, fixture):
        self.workCal.addEvent(self.event1)
        assert (self.user.calculateHoursCategory(
            "Work", datetime.datetime(2017, 11, 27, 22, 45)) == 2)
Exemple #2
0
class TestUser():
    @pytest.fixture()
    def fixture(self):
        self.user = User(1, "Derrick", "Foo", "*****@*****.**", "abc123")
        self.user1 = User(2, "Zainab", "Alasadi", "*****@*****.**",
                          "abc123***")

        self.event = Event(1, self.user, "COMP4920 Meeting", "Standup",
                           datetime.datetime(2017, 11, 28, 22, 45),
                           datetime.datetime(2017, 11, 28, 23, 45), "Work",
                           "Work")
        self.event1 = Event(2, self.user, "21st Birthday",
                            "Bday party at Sydney",
                            datetime.datetime(2017, 11, 28, 22, 45),
                            datetime.datetime(2017, 11, 28, 23,
                                              45), "Work", "Work")
        self.event_edit = Event(1, self.user, "COMP4920 Meeting 2.0", "Online",
                                datetime.datetime.now(),
                                datetime.datetime.now(), "Personal", "Work")
        self.workCal = Calendar("Work", "red", self.user)
        self.personalCal = Calendar("Personal", "blue", self.user1)
        self.event.setCalendar(self.workCal)

        self.event.addInvitee(self.user1)
        self.workCal.addEvent(self.event)
        self.user1.addCalendars(self.personalCal)

    def test_user(self, fixture):
        assert (self.user.getID() == 1)
        assert (self.user.getFirstName() == "Derrick")
        assert (self.user.getLastName() == "Foo")
        assert (self.user.getEmail() == "*****@*****.**")
        assert (self.user.validate("abc123") == True)
        assert (len(self.user.getCalendars()) == 0)
        assert (len(self.user.getContacts()) == 0)
        assert (len(self.user.getGroups()) == 0)

    def test_accept_invite(self, fixture):
        assert (len(self.user1.getNotifications()) == 1)
        assert (len(self.personalCal.getEvents()) == 0)
        for notif in self.user1.getNotifications():
            self.user1.acceptInvite(notif, self.personalCal)
        assert (len(self.user1.getNotifications()) == 0)
        assert (len(self.personalCal.getEvents()) == 1)

    def test_maybe_invite(self, fixture):
        for notif in self.user1.getNotifications():
            self.user1.maybeInvite(notif, self.personalCal)
        assert (len(self.user1.getNotifications()) == 0)
        assert (len(self.personalCal.getEvents()) == 1)
        assert (len(self.user.getNotifications()) == 1)
        for notif in self.user.getNotifications():
            assert (notif.getNotifType() == 'maybe_invite')

    def test_decline_invite(self, fixture):
        for notif in self.user1.getNotifications():
            self.user1.declineInvite(notif)
        assert (len(self.user1.getNotifications()) == 0)
        assert (len(self.personalCal.getEvents()) == 0)
        assert (len(self.user.getNotifications()) == 1)
        for notif in self.user.getNotifications():
            assert (notif.getNotifType() == 'declined_invite')

    def test_update_event(self, fixture):
        self.user.updateEvent(
            self.event, "Wobcke Fanclub", "Wobcke Rocks!",
            datetime.datetime.now() - datetime.timedelta(days=5),
            datetime.datetime.now() - datetime.timedelta(days=5),
            self.personalCal, "Fun")
        assert (self.event.getCategory() == "Fun")
        assert (self.event.getName() == "Wobcke Fanclub")
        assert (self.event.getDescription() == "Wobcke Rocks!")
        assert (self.event.getCalendar() == self.personalCal)

    def test_update_event_with_invitees(self, fixture):
        self.user1 = User(2, "Zainab", "Alasadi", "*****@*****.**",
                          "abc123***")
        self.workCal1 = Calendar("Work", "red", self.user1)
        self.user1.addCalendars(self.workCal1)

        self.workCal.addEvent(self.event)
        self.event.addInvitee(self.user1)

        assert (len(self.workCal.getEvents()) == 1)
        assert (len(self.personalCal.getEvents()) == 0)

        self.user.updateEvent(
            self.event, "Wobcke Fanclub", "Wobcke Rocks!",
            datetime.datetime.now() - datetime.timedelta(days=5),
            datetime.datetime.now() - datetime.timedelta(days=5),
            self.personalCal, "Fun")

        assert (len(self.workCal.getEvents()) == 0)
        assert (len(self.personalCal.getEvents()) == 1)

        assert (len(self.user1.getNotifications()) == 1)
        for notif in self.user1.getNotifications():
            assert (len(notif.getChanges()) == 6)

        self.user.updateEvent(
            self.event, "Wobcke Fanclub", "Wobcke Rocks!",
            datetime.datetime.now() - datetime.timedelta(days=5),
            datetime.datetime.now() - datetime.timedelta(days=5),
            self.personalCal, "Fun")

        assert (len(self.workCal.getEvents()) == 0)
        assert (len(self.personalCal.getEvents()) == 1)

        assert (len(self.user1.getNotifications()) == 2)
        for notif in self.user1.getNotifications():
            assert (len(notif.getChanges()) == 6 or 2)
class TestEvent():
    @pytest.fixture()
    def fixture(self):
        self.user = User(1, "Derrick", "Foo", "*****@*****.**", "abc123")
        self.user1 = User(2, "Zainab", "Alasadi", "*****@*****.**",
                          "abc123***")
        self.event = Event(1, self.user, "COMP4920 Meeting", "Standup",
                           datetime.datetime.now(), datetime.datetime.now(),
                           "Work", "Work")
        self.event1 = Event(2, self.user, "21st Birthday",
                            "Bday party at Sydney", datetime.datetime.now(),
                            datetime.datetime.now(), "Work", "Work")
        self.event_edit = Event(1, self.user, "COMP4920 Meeting 2.0", "Online",
                                datetime.datetime.now(),
                                datetime.datetime.now(), "Personal", "Work")
        self.workCal = Calendar("Work", "red", self.user)
        self.personalCal = Calendar("Personal", "blue", self.user)
        self.user.addCalendars(self.workCal)

        self.event.setCalendar(self.workCal)

        self.comment = Comment("Derrick", "So excited people!")
        self.comment1 = Comment("Derrick", "6pm don't be late!")
        self.commentReply = Comment("Zainab", "Cool")
        self.commentReply1 = Comment("Michael", "Me too!")

    def test_event(self, fixture):
        assert (self.event.getUser() == self.user)
        assert (self.event.getCalendar() == self.workCal)
        assert (self.event.getDescription() == "Standup")
        assert (self.event.getName() == "COMP4920 Meeting")
        assert (self.event.getID() == 1)
        assert (self.event.getStartDateTime() <= self.event.getEndDateTime())

    def test_edit_event(self, fixture):
        self.workCal.addEvent(self.event)
        self.event.editEvent("COMP4920 Meeting 2.0", "Online",
                             datetime.datetime.now(), datetime.datetime.now(),
                             self.workCal, "Work")
        for event in self.workCal.getEvents():
            assert (event.getName() == "COMP4920 Meeting 2.0")
        assert (len(self.workCal.getEvents()) == 1)

    def test_edit_event_change_calendar(self, fixture):
        self.workCal.addEvent(self.event)
        self.event.editEvent("COMP4920 Meeting 2.0", "Online",
                             datetime.datetime.now(), datetime.datetime.now(),
                             self.personalCal, "Work")

        assert (len(self.workCal.getEvents()) == 0)
        assert (len(self.personalCal.getEvents()) == 1)

    def test_bad_date_edit_event(self, fixture):
        self.workCal.addEvent(self.event)
        self.event.editEvent("COMP4920 Meeting 2.0", "Online",
                             datetime.date(2012, 12, 31),
                             datetime.date(2001, 12, 31), self.workCal, "Work")
        for event in self.workCal.getEvents():
            assert (event.getName() == "COMP4920 Meeting")
        assert (len(self.workCal.getEvents()) == 1)

    def test_add_invitee(self, fixture):
        self.event.addInvitee(self.user1)
        assert (len(self.user1.getNotifications()) == 1)
        for notif in self.user1.getNotifications():
            assert (notif.getNotifType() == 'invite')

    def test_remove_invitee_has_not_accepted(self, fixture):
        self.event.addInvitee(self.user1)
        self.event.removeInvitee(self.user1)

        assert (len(self.user1.getNotifications()) == 0)

    def test_remove_invitee_who_has_accepted(self, fixture):
        self.event.addInvitee(self.user1)

        self.workCal1 = Calendar("Work", "red", self.user1)
        self.user1.addCalendars(self.workCal1)

        for notif in self.user1.getNotifications():
            self.user1.acceptInvite(notif, self.workCal1)

        assert (len(self.workCal1.getEvents()) == 1)

        self.event.removeInvitee(self.user1)

        assert (len(self.workCal1.getEvents()) == 0)
        assert (len(self.user1.getNotifications()) == 0)
class TestNotification():
    @pytest.fixture()
    def fixture(self):
        self.user = User(1, "Derrick", "Foo", "*****@*****.**", "abc123")
        self.event = Event(1, self.user, "COMP4920 Meeting", "Standup",
                           datetime.datetime.now(), datetime.datetime.now(),
                           "Work", "Work")
        self.eventCopy = Event(1, self.user, "COMP4920 Meeting", "Standup",
                               datetime.datetime.now(),
                               datetime.datetime.now(), "Personal", "Work")
        self.event1 = Event(2, self.user, "21st Birthday",
                            "Bday party at Sydney", datetime.datetime.now(),
                            datetime.datetime.now(), "Work", "Work")
        self.event_edit = Event(1, self.user, "COMP4920 Meeting 2.0", "Online",
                                datetime.datetime.now(),
                                datetime.datetime.now(), "Personal", "Work")
        self.workCal = Calendar("Work", "red", self.user)
        self.personalCal = Calendar("Personal", "blue", self.user)
        self.user.addCalendars(self.workCal)

    def test_delete_accepted_shared_event_invitee(self, fixture):
        self.user1 = User(2, "Zainab", "Alasadi", "*****@*****.**",
                          "abc123***")
        self.workCal1 = Calendar("Work", "red", self.user1)
        self.user1.addCalendars(self.workCal1)

        self.workCal.addEvent(self.event)
        self.event.addInvitee(self.user1)

        assert (len(self.user1.getNotifications()) == 1)
        assert (len(self.event.getInvitees()) == 1)

        for notif in self.user1.getNotifications():
            self.user1.acceptInvite(notif, self.workCal1)

        assert (len(self.user1.getNotifications()) == 0)

        self.user1.deleteEvent(self.event)

        assert (len(self.workCal.getEvents()) == 1)
        assert (len(self.workCal1.getEvents()) == 0)
        assert (len(self.user1.getNotifications()) == 0)
        assert (len(self.user.getNotifications()) == 0)

    def test_delete_accepted_shared_event_creator(self, fixture):
        self.user1 = User(2, "Zainab", "Alasadi", "*****@*****.**",
                          "abc123***")
        self.workCal1 = Calendar("Work", "red", self.user1)
        self.user1.addCalendars(self.workCal1)

        self.workCal.addEvent(self.event)
        self.event.addInvitee(self.user1)

        for notif in self.user1.getNotifications():
            self.user1.acceptInvite(notif, self.workCal1)

        self.user.deleteEvent(self.event)

        assert (len(self.workCal.getEvents()) == 0)
        assert (len(self.workCal1.getEvents()) == 0)
        assert (len(self.user1.getNotifications()) == 1)
        for notif in self.user1.getNotifications():
            assert (notif.getNotifType() == 'deleted_event')

    def test_delete_unaccepted_shared_event_creator(self, fixture):
        self.user1 = User(2, "Zainab", "Alasadi", "*****@*****.**",
                          "abc123***")
        self.workCal1 = Calendar("Work", "red", self.user1)
        self.user1.addCalendars(self.workCal1)

        self.workCal.addEvent(self.event)
        self.event.addInvitee(self.user1)

        self.user.deleteEvent(self.event)

        assert (len(self.workCal.getEvents()) == 0)
        assert (len(self.workCal1.getEvents()) == 0)
        assert (len(self.user1.getNotifications()) == 0)
class TestCalendar():
    @pytest.fixture()
    def fixture(self):
        self.user = User(1, "Derrick", "Foo", "*****@*****.**", "abc123")
        self.event = Event(1, self.user, "COMP4920 Meeting", "Standup",
                           datetime.datetime.now(), datetime.datetime.now(),
                           "Work", "Work")
        self.eventCopy = Event(1, self.user, "COMP4920 Meeting", "Standup",
                               datetime.datetime.now(),
                               datetime.datetime.now(), "Personal", "Work")
        self.event1 = Event(2, self.user, "21st Birthday",
                            "Bday party at Sydney", datetime.datetime.now(),
                            datetime.datetime.now(), "Work", "Work")
        self.event_edit = Event(1, self.user, "COMP4920 Meeting 2.0", "Online",
                                datetime.datetime.now(),
                                datetime.datetime.now(), "Personal", "Work")
        self.workCal = Calendar("Work", "red", self.user)
        self.personalCal = Calendar("Personal", "blue", self.user)
        self.user.addCalendars(self.workCal)

        self.event.setCalendar(self.workCal)

    def test_add_event(self, fixture):
        assert (self.workCal.addEvent(self.event))
        assert (len(self.user.getCalendars()) == 1)
        assert (len(self.workCal.getEvents()) == 1)

    def test_add_same_event_same_calendar(self, fixture):
        assert (self.workCal.addEvent(self.event))
        assert (len(self.workCal.getEvents()) == 1)
        assert not (self.workCal.addEvent(self.event))
        assert (len(self.workCal.getEvents()) == 1)

    def test_add_same_event_diff_calendars(self, fixture):
        assert (self.workCal.addEvent(self.event))
        assert (len(self.workCal.getEvents()) == 1)
        assert (self.personalCal.addEvent(self.event))
        self.user.addCalendars(self.personalCal)
        assert (len(self.personalCal.getEvents()) == 1)

    def test_add_multiple_events(self, fixture):
        assert (self.workCal.addEvent(self.event))
        assert (len(self.workCal.getEvents()) == 1)
        assert (self.workCal.addEvent(self.event1))
        assert (len(self.workCal.getEvents()) == 2)

    def test_delete_events_when_none_exist(self, fixture):
        assert not (self.workCal.deleteEvent(self.event))

    def test_delete_event(self, fixture):
        assert (self.workCal.addEvent(self.event))
        assert (len(self.workCal.getEvents()) == 1)
        assert (self.workCal.deleteEvent(self.event))
        assert (len(self.workCal.getEvents()) == 0)
        assert not (self.workCal.deleteEvent(self.event))

    def test_delete_event_diff_calendars(self, fixture):
        assert (self.workCal.addEvent(self.event))
        assert (len(self.workCal.getEvents()) == 1)
        assert (self.personalCal.addEvent(self.eventCopy))
        self.user.addCalendars(self.personalCal)
        assert (len(self.personalCal.getEvents()) == 1)

        self.user.deleteEvent(self.event)
        assert (len(self.personalCal.getEvents()) == 1)
        assert (len(self.workCal.getEvents()) == 0)

    def test_delete_event_all_calendars(self, fixture):
        assert (self.workCal.addEvent(self.event))
        assert (len(self.workCal.getEvents()) == 1)
        assert (self.personalCal.addEvent(self.event))
        self.user.addCalendars(self.personalCal)
        assert (len(self.personalCal.getEvents()) == 1)

        self.user.deleteEvent(self.event)
        assert (len(self.personalCal.getEvents()) == 0)
        assert (len(self.workCal.getEvents()) == 0)

    def test_delete_all_when_none(self, fixture):
        self.user.deleteEvent(self.event)
        assert (len(self.personalCal.getEvents()) == 0)
        assert (len(self.workCal.getEvents()) == 0)

    def test_delete_event_one_calendar(self, fixture):
        assert (self.workCal.addEvent(self.event))
        assert (len(self.workCal.getEvents()) == 1)
        self.event.setCalendar(self.workCal)
        assert (self.personalCal.addEvent(self.eventCopy))
        self.user.addCalendars(self.personalCal)
        self.eventCopy.setCalendar(self.personalCal)
        assert (len(self.personalCal.getEvents()) == 1)

        assert (self.user.deleteEventOneCalendar(self.event))
        assert (len(self.personalCal.getEvents()) == 1)
        assert (len(self.workCal.getEvents()) == 0)

    def test_delete_one_when_none(self, fixture):
        self.user.deleteEventOneCalendar(self.event)
        assert (len(self.personalCal.getEvents()) == 0)
        assert (len(self.workCal.getEvents()) == 0)