def test_create_trip_with_same_name_but_different_creator_should_succeed(
         self):
     user1 = create_user("*****@*****.**")
     user2 = create_user("*****@*****.**")
     create_trip(get_trip_object(name="trip", creator=user1))
     user2_trip = create_trip(get_trip_object(name="trip", creator=user2))
     self.assertIsInstance(user2_trip, Trip)
 def test_add_participant_to_step_should_add_user(self):
     user = create_user("*****@*****.**")
     trip = create_trip(get_trip_object("trip", user))
     step = create_step(
         get_step_object("step", trip.id, "2020-05-03 10:00:00"))
     step = add_participant_to_step(user.id, step.id)
     self.assertTrue(user in step.users_steps)
def create_test_trip(creator: User, closed: bool) -> Trip:
    trip = Trip(name='Road-trip Tanzanie',
                picture_path="picture/path",
                creator_id=creator.id,
                closed=closed,
                users_trips=[creator])
    return create_trip(trip)
 def test_invite_to_trip_should_succeed(self):
     creator = create_user("*****@*****.**")
     participant = create_user("*****@*****.**")
     trip = create_trip(get_trip_object(name="trip", creator=creator))
     invite_to_trip(trip_id=trip.id, user_to_invite_email=participant.email)
     participants_email = map(lambda user: user.email, trip.users_trips)
     self.assertTrue(participant.email in participants_email)
    def test_invite_to_trip_should_raise_useremailnotfoundexception(self):
        creator = create_user("*****@*****.**")
        trip = create_trip(get_trip_object(name="trip", creator=creator))

        with self.assertRaises(UserEmailNotFoundException):
            invite_to_trip(trip_id=trip.id,
                           user_to_invite_email="*****@*****.**")
 def test_update_notes_with_too_long_string_should_raise_exception(self):
     user = create_user("*****@*****.**")
     trip = create_trip(get_trip_object("trip", user))
     step = create_step(
         get_step_object("step", trip.id, "2020-05-03 10:00:00"))
     with self.assertRaises(StringLengthOutOfRangeException):
         update_notes(step.id, 's' * 201)
    def test_calculate_future_operations(self):
        user = create_user("*****@*****.**")
        user2 = create_user("*****@*****.**")
        user3 = create_user("*****@*****.**")
        trip = create_trip(get_trip_object("trip", user))
        expense = create_expense(
            get_expense_object(150.50, "test", user.id, trip.id))
        reimbursement = create_reimbursement(
            get_reimbursement_object(100, expense.id, user.id, user2.id,
                                     trip.id))
        reimbursement2 = create_reimbursement(
            get_reimbursement_object(100, expense.id, user.id, user2.id,
                                     trip.id))
        reimbursement3 = create_reimbursement(
            get_reimbursement_object(100, expense.id, user3.id, user.id,
                                     trip.id))
        operations = calculate_future_operations(
            refunds_to_get_for_user(trip.id, user.id),
            get_user_reimbursements(trip.id, user.id))
        expected_result = [
            Operation(amount=100, emitter_id=user3.id, payee_id=user.id),
            Operation(amount=200, emitter_id=user.id, payee_id=user2.id)
        ]

        self.assertEquals(operations[0].amount, expected_result[0].amount)
        self.assertEquals(operations[1].amount, expected_result[1].amount)
        self.assertEquals(operations[0].emitter_id,
                          expected_result[0].emitter_id)
        self.assertEquals(operations[1].emitter_id,
                          expected_result[1].emitter_id)
        self.assertEquals(operations[0].payee_id, expected_result[0].payee_id)
        self.assertEquals(operations[1].payee_id, expected_result[1].payee_id)
 def test_add_participant_to_step_should_raise_stepnotfoundexception(self):
     user = create_user("*****@*****.**")
     trip = create_trip(get_trip_object("trip", user))
     step = create_step(
         get_step_object("step", trip.id, "2020-05-03 10:00:00"))
     with self.assertRaises(StepNotFoundException):
         add_participant_to_step(user.id, step.id + 1)
 def test_close_closed_trip_should_do_nothing(self):
     user = create_user("*****@*****.**")
     trip = create_trip(get_trip_object("trip", user))
     self.assertFalse(trip.closed)
     close_trip(trip.id)
     self.assertTrue(get_trip_by_id(trip.id).closed)
     close_trip(trip.id)
     self.assertTrue(get_trip_by_id(trip.id).closed)
예제 #10
0
 def test_should_update_notes(self):
     user = create_user("*****@*****.**")
     trip = create_trip(get_trip_object("trip", user))
     step = create_step(
         get_step_object("step", trip.id, "2020-05-03 10:00:00"))
     notes = 's' * 200
     update_notes(step.id, notes)
     self.assertEqual(notes, get_step_by_id(step.id).notes)
예제 #11
0
 def test_create_step_should_succeed(self):
     user = create_user("*****@*****.**")
     trip = create_trip(get_trip_object(name="trip", creator=user))
     start_datetime = "2020-04-10 21:00:00"
     step = create_step(
         get_step_object(name="step",
                         trip_id=trip.id,
                         start_datetime=start_datetime))
     self.assertIsInstance(step, Step)
예제 #12
0
 def test_add_participant_to_step_should_raise_userdoesnotparticipatetotrip(
         self):
     creator = create_user("*****@*****.**")
     usurper = create_user("*****@*****.**")
     trip = create_trip(get_trip_object("trip", creator))
     step = create_step(
         get_step_object("step", trip.id, "2020-05-03 10:00:00"))
     with self.assertRaises(UserDoesNotParticipatesToTrip):
         add_participant_to_step(usurper.id, step.id)
예제 #13
0
    def test_create_step_should_raise_tripnotfoundexception(self):
        user = create_user("*****@*****.**")
        trip = create_trip(get_trip_object(name="trip", creator=user))
        start_datetime = "2020-04-10 21:00:00"

        with self.assertRaises(TripNotFoundException):
            create_step(
                get_step_object(name="step",
                                trip_id=trip.id + 1,
                                start_datetime=start_datetime))
예제 #14
0
 def test_get_uncreated_step_should_return_none(self):
     user = create_user("*****@*****.**")
     trip = create_trip(get_trip_object(name="trip", creator=user))
     start_datetime = "2020-04-10 21:00:00"
     created_step = create_step(
         get_step_object(name="step",
                         trip_id=trip.id,
                         start_datetime=start_datetime))
     step = get_step_by_id(created_step.id + 1)
     self.assertEqual(step, None)
예제 #15
0
 def test_create_reimbursement(self):
     user = create_user("*****@*****.**")
     user2 = create_user("*****@*****.**")
     trip = create_trip(get_trip_object("trip", user))
     expense = create_expense(
         get_expense_object(150.50, "test", user.id, trip.id))
     reimbursement = create_reimbursement(
         get_reimbursement_object(100.50, expense.id, user.id, user2.id,
                                  trip.id))
     self.assertIsInstance(reimbursement, Reimbursement)
예제 #16
0
    def test_create_step_with_no_name_should_raise_stringlengthoutofrangeexception(
            self):
        user = create_user("*****@*****.**")
        trip = create_trip(get_trip_object(name="trip", creator=user))
        start_datetime = "2020-04-10 21:00:00"
        name = ''

        with self.assertRaises(StringLengthOutOfRangeException):
            create_step(
                get_step_object(name=name,
                                trip_id=trip.id,
                                start_datetime=start_datetime))
예제 #17
0
    def test_get_user_personal_timeline(self):
        user = create_user("*****@*****.**")
        trip = create_trip(get_trip_object("trip", user))
        step = create_step(
            get_step_object("step", trip.id, "2020-05-03 10:00:00"))
        step2 = create_step(
            get_step_object("step2", trip.id, "2020-05-03 10:00:00"))
        step = add_participant_to_step(user.id, step.id)
        step2 = add_participant_to_step(user.id, step2.id)
        expected_result = [step, step2]

        self.assertListEqual(get_user_steps_participation(user, trip.id),
                             expected_result)
    def test_get_messages_from_trip(self):
        user1 = create_user("*****@*****.**")
        user2 = create_user("*****@*****.**")
        trip = create_trip(get_trip_object(name="first_trip", creator=user1))
        message1 = save_message(
            get_chat_message_object("first", trip.id, user1.id))
        message2 = save_message(
            get_chat_message_object("second", trip.id, user1.id))
        message3 = save_message(
            get_chat_message_object("first", trip.id, user2.id))
        messages_array = [message1, message2, message3]

        messages = get_messages(trip.id)
        self.assertListEqual(messages, messages_array)
예제 #19
0
 def test_get_timeline_should_return_participant_of_step(self):
     user1 = create_user("*****@*****.**")
     user2 = create_user("*****@*****.**")
     trip = create_trip(get_trip_object(name="trip", creator=user1))
     invite_to_trip(trip_id=trip.id, user_to_invite_email=user2.email)
     step = create_step(
         get_step_object(name="step",
                         trip_id=trip.id,
                         start_datetime="2020-05-04 22:22:00"))
     add_participant_to_step(user_id=user1.id, step_id=step.id)
     add_participant_to_step(user_id=user2.id, step_id=step.id)
     timeline = get_timeline(trip_id=trip.id)
     participants = [user1, user2]
     self.assertEqual(timeline[0].users_steps, participants)
예제 #20
0
    def test_get_timeline_should_return_steps_ordered(self):
        user = create_user("*****@*****.**")
        trip = create_trip(get_trip_object(name="trip", creator=user))
        created_step_1 = create_step(
            get_step_object(name="step",
                            trip_id=trip.id,
                            start_datetime="2020-04-10 21:00:00"))
        created_step_2 = create_step(
            get_step_object(name="step",
                            trip_id=trip.id,
                            start_datetime="2020-04-05 21:00:00"))
        timeline = get_timeline(trip.id)

        self.assertEqual(timeline[0].id, created_step_2.id)
        self.assertEqual(timeline[1].id, created_step_1.id)
예제 #21
0
def get_coming_trips(user, current_date=datetime.date.today()):
    coming_trips = [
        get_trip_object("coming1", user),
        get_trip_object("coming2", user)
    ]
    coming_trips = create_trips(coming_trips)
    for trip in coming_trips:
        create_step(
            get_step_object(name="first",
                            trip_id=trip.id,
                            start_datetime=datetime.datetime(
                                current_date.year, current_date.month,
                                current_date.day + 1, 8, 0, 0)))
        create_step(
            get_step_object(name="second",
                            trip_id=trip.id,
                            start_datetime=datetime.datetime(
                                current_date.year, current_date.month,
                                current_date.day + 1, 10, 0, 0)))

    coming_trips.append(create_trip(get_trip_object("no steps", user)))
    return coming_trips
예제 #22
0
 def test_update_notes_of_unknown_step_should_raise_exception(self):
     user = create_user("*****@*****.**")
     trip = create_trip(get_trip_object("trip", user))
     with self.assertRaises(StepNotFoundException):
         update_notes(1, "notes")
예제 #23
0
 def test_get_expenses_should_raise_useridnotfoundexception(self):
     user = create_user("*****@*****.**")
     trip = create_trip(get_trip_object("trip", user))
     with self.assertRaises(UserNotFoundException):
         get_expenses(trip_id=trip.id, user_id=user.id + 1)
예제 #24
0
 def test_create_expense(self):
     user = create_user("*****@*****.**")
     trip = create_trip(get_trip_object("trip", user))
     expense = create_expense(
         get_expense_object(150.50, "test", user.id, trip.id))
     self.assertIsInstance(expense, Expense)
예제 #25
0
 def test_create_trip_with_no_name_should_raise_stringlengthoutofrangeexception(
         self):
     user = create_user("*****@*****.**")
     trip = get_trip_object(name='', creator=user)
     with self.assertRaises(StringLengthOutOfRangeException):
         create_trip(trip)
예제 #26
0
 def test_create_trip_should_raise_tripalreadyexistsexception(self):
     user = create_user("*****@*****.**")
     trip = get_trip_object(name="trip", creator=user)
     create_trip(trip)
     with self.assertRaises(TripAlreadyExistsException):
         create_trip(trip)
예제 #27
0
    def test_get_timeline_should_raise_tripnotfoundexception(self):
        user = create_user("*****@*****.**")
        trip = create_trip(get_trip_object(name="trip", creator=user))

        with self.assertRaises(TripNotFoundException):
            get_timeline(trip.id + 1)
예제 #28
0
 def test_create_trip_should_succeed(self):
     user = create_user("*****@*****.**")
     trip = create_trip(get_trip_object(name="trip", creator=user))
     self.assertIsInstance(trip, Trip)
예제 #29
0
 def test_create_trip_should_set_closed_to_false(self):
     user = create_user("*****@*****.**")
     trip = create_trip(get_trip_object(name="trip", creator=user))
     self.assertEqual(trip.closed, False)