Exemplo n.º 1
0
    def simple_setup(self):
        # Reset container.
        Container.reset_services()

        # Set up models.
        self.user = self.create_user()
        self.timeline = self.create_timeline(self.user)
Exemplo n.º 2
0
    def test_swap_service(self):
        """
        Testing that we can swap services.
        """
        class DummyService:
            pass

        self.assertEquals(Container.services['events_service'], Events.Service)

        # Swapping service and make sure we get another instance.
        Container.set_service('events_service', DummyService)
        self.assertEquals(Container.services['events_service'], DummyService)
Exemplo n.º 3
0
    def test_service_container_init(self):
        """
        Testing the service container is initialize and we pulling services of
        other packages.
        """

        Container.reset_services()

        # Checking event service.
        self.assertEquals(Container.services['events_service'], Events.Service)
        self.assertEquals(Container.events_service().info(),
                          Events.Service().info())

        # Testing location service.
        self.assertEquals(Container.services['location_service'],
                          Location.Service)
Exemplo n.º 4
0
    def test_accommodation_event_creation(self):
        """
        Testing the creation of accommodation event.
        """
        meeting = Container.events_service().create_general_event(
            title='Dummy flight',
            starting_date=datetime.now(),
            timeline=self.timeline,
        )

        self.assertEquals(
            self.user.timeline_set.first().generalevent_set.first(), meeting)
Exemplo n.º 5
0
    def test_lunch_event(self):
        """
        Testing the lunch event.
        """
        lunch = Container.events_service().create_lunch(
            title='Lunch',
            starting_date=datetime.now(),
            timeline=self.timeline,
            location=self.create_location())

        self.assertEquals(lunch,
                          self.user.timeline_set.first().lunch_set.first())
Exemplo n.º 6
0
    def test_create_flight(self):
        """
        Testing the creation of a flight.
        """
        flight = Container.events_service().create_flight_event(
            title='Dummy flight',
            starting_date=datetime.now(),
            timeline=self.timeline,
            origin='House of cats',
            destination='Another house of cats',
            extra_info='Keep calm',
            location=self.create_location())

        self.assertEquals(self.user.timeline_set.first().flight_set.first(),
                          flight)
Exemplo n.º 7
0
    def test_accommodation_event_creation(self):
        """
        Testing the creation of accommodation event.
        """
        accommodation = Container.events_service().create_accommodation(
            title='Dummy flight',
            starting_date=datetime.now(),
            timeline=self.timeline,
            hotel_name='Special Diabetes hotel',
            room='213',
        )

        self.assertEquals(
            self.user.timeline_set.first().accommodation_set.first(),
            accommodation)
Exemplo n.º 8
0
    def test_picking_car_event(self):
        """
        Testing the car picking event.
        """
        picking_car = Container.events_service().create_picking_car(
            title='Dummy flight',
            starting_date=datetime.now(),
            timeline=self.timeline,
            agency="Hertz",
            type="BMW",
            license_number="OutOfTime",
            location=self.create_location())

        self.assertEquals(
            picking_car,
            self.user.timeline_set.first().pickingcar_set.first())
Exemplo n.º 9
0
    def resolve_timeline(self, info, **kwargs):
        user = info.context.user
        id = kwargs.get('id')

        try:
            timeline = TimelineModel.objects.filter(id=id).first()
        except TimelineModel.DoesNotExist:
            return None

        if timeline.user.id == user.id:
            # The timeline belongs to the user.
            return timeline

        if Container.timeline_service().is_shared_timeline(
                info.context.user, timeline):
            return timeline

        return None
Exemplo n.º 10
0
    def test_create_meeting_conjunction(self):
        """
        Testing the creation of a meeting conjunction.
        """
        create_meeting_conjunction_kwargs = {
            'members': (self.alice, self.bob),
            'title': 'Dummy flight',
            'starting_date': datetime.now(),
            'timeline': self.timeline,
            'location': self.create_location()
        }
        meeting_conjunction = Container.events_service()\
            .create_meeting_conjunction(**create_meeting_conjunction_kwargs)

        referenced_conjunctions = self.user.timeline_set.first()\
            .meetingconjunction_set.first()

        self.assertEquals(referenced_conjunctions, meeting_conjunction)
        self.assertTrue(self.alice in referenced_conjunctions.members.all())
        self.assertTrue(self.bob in referenced_conjunctions.members.all())
Exemplo n.º 11
0
    def prepare_trip(self, user):
        """"
        Preparing the trip for a given user: timeline, flight etc. etc.
        """

        timeline = self.create_timeline(user)

        picking_car = Container.events_service().create_picking_car(
            title=f'Dummy flight for user {user.username}',
            starting_date=datetime.now(),
            timeline=timeline,
            agency="Hertz",
            type="BMW",
            license_number="OutOfTime",
            location=self.location
        )

        connection_flight = Container.events_service().create_flight_event(
            title=f'Connection dummy flight {user.username}',
            starting_date=datetime.now(),
            origin='House of cats',
            destination='Another house of cats',
            extra_info='Keep calm',
            location=self.location
        )

        flight = Container.events_service().create_flight_event(
            title=f'Dummy flight {user.username}',
            starting_date=datetime.now(),
            timeline=timeline,
            origin='House of cats',
            destination='Another house of cats',
            extra_info='Keep calm',
            location=self.location,
            connection_flight=connection_flight
        )

        create_meeting_conjunction_kwargs = {
            'members': (self.alice, self.bob),
            'title': f'Dummy flight {user.username}',
            'starting_date': datetime.now(),
            'timeline': timeline,
            'location': self.location
        }
        meeting_conjunction = Container.events_service()\
            .create_meeting_conjunction(**create_meeting_conjunction_kwargs)

        accommodation = Container.events_service().create_accommodation(
            title=f'Dummy flight {user.username}',
            starting_date=datetime.now(),
            timeline=timeline,
            hotel_name='Special Diabetes hotel',
            room='213',
        )

        lunch = Container.events_service().create_lunch(
            title='Lunch',
            starting_date=datetime.now(),
            timeline=timeline,
            location=self.location
        )

        meeting = Container.events_service().create_meeting(
            title='Lunch',
            starting_date=datetime.now(),
            timeline=timeline,
            location=self.location
        )

        general_event = Container.events_service().create_general_event(
            title='Lunch',
            starting_date=datetime.now(),
            timeline=timeline,
            location=self.location
        )

        return {
            'timeline': timeline,
            'picking_car': picking_car,
            'flight': flight,
            'connection_flight': connection_flight,
            'meeting_conjunction': meeting_conjunction,
            'accommodation': accommodation,
            'lunch': lunch,
            'meeting': meeting,
            'general_event': general_event,
        }
Exemplo n.º 12
0
def declare_services(sender, **kwargs):
    Container.set_service('location_service', Location.Service)
Exemplo n.º 13
0
def declare_services(sender, **kwargs):
    Container.set_service('timeline_service', Timeline.Service)
Exemplo n.º 14
0
def declare_services(sender, **kwargs):
    Container.set_service('events_service', Events.Service)