Example #1
0
    def set_me(new_user_id: Text):
        """
        Sets up a new subscription for the given user id

        :param new_user_id: The signed in user
        """
        if UserMeGetter._user_id is not "":
            Firestore.unsubscribe(
                u'users/{user_id}/'.format(user_id=new_user_id))
            Firestore.unsubscribe(
                u'users/{user_id}/packages'.format(user_id=new_user_id))
            Firestore.unsubscribe(
                u'users/{user_id}/deliveries'.format(user_id=new_user_id))

        UserMeGetter._user_id = new_user_id

        if new_user_id != "":
            UserMeGetter.user = UserGetter.get_by_id(new_user_id)
            Firestore.subscribe_document("users", new_user_id,
                                         UserMeGetter._on_snapshot_user)
            Firestore.subscribe(
                u'users/{user_id}/packages'.format(user_id=new_user_id),
                UserMeGetter._on_snapshot_user_packages)
            Firestore.subscribe(
                u'users/{user_id}/deliveries'.format(user_id=new_user_id),
                UserMeGetter._on_snapshot_user_deliveries)
Example #2
0
    def test_subscription(self):
        event = threading.Event()

        callback_with_event = functools.partial(lambda *_: event.set(), event)
        Firestore.subscribe("packages", callback_with_event)

        request = create_delivery_request()
        self.assertIsNotNone(request)
        DeliveryRequestUploader.upload(request)

        event.wait()

        self.assertTrue(event.is_set())

        Firestore.unsubscribe("packages")

        Firestore.unsubscribe("some_invalid_thing_to_unsubscribe_from")
Example #3
0
 def __init__(self, **kwargs):
     """Initializes the delivery list"""
     super(MyDeliveries, self).__init__(**kwargs)
     Firestore.subscribe(
         u'users/{}/deliveries'.format(UserMeGetter._user_id),
         self._pre_update_content)