Beispiel #1
0
 def un_follow(self, actor_id, following):
     """
     A convenience function to un-follow a person
     :param actor_id:  Actor ID who's link is being declared in the network
     :param following: The person that is being un-followed
     :return: Bool
     """
     a_linked_activity = LinkedActivity(following)
     a_link = Link(actor_id, a_linked_activity)
     return self.remove_network_link(a_link)
Beispiel #2
0
 def un_watch(self, actor_id, watch_id, watch_type):
     """
     A convenience function to un-watch an object
     :param actor_id: Actor ID who's link is being declared in the network
     :param watch_id: The object that is being un-watched
     :param watch_type: The object type that is being un-watched
     :return: Bool
     """
     a_linked_activity = LinkedActivity(watch_id, "object", watch_type)
     a_link = Link(actor_id, a_linked_activity, link_type="watch")
     return self.remove_network_link(a_link)
Beispiel #3
0
 def follow(self, actor_id, following, linked=datetime.datetime.now()):
     """
     A convenience function to declare a follow link
     :param actor_id:  Actor ID who's link is being declared in the network
     :param following: The person that is being followed
     :param linked: Datetime of the link
     :return: None
     """
     a_linked_activity = LinkedActivity(following)
     a_link = Link(actor_id, a_linked_activity, linked=linked)
     self.add_network_link(a_link)
Beispiel #4
0
 def watch(self, actor_id, watch_id, watch_type, linked=datetime.datetime.now()):
     """
     A convenience function to declare a watch link
     :param actor_id: Actor ID who's link is being declared in the network
     :param watch_id: The object that is being watched
     :param watch_type: The object type that is being watched
     :param linked: Datetime of the link
     :return: None
     """
     a_linked_activity = LinkedActivity(watch_id, "object", watch_type)
     a_link = Link(actor_id, a_linked_activity, linked=linked, link_type="watch")
     self.add_network_link(a_link)
Beispiel #5
0
 def follow(
         self,
         actor_id,
         following,
         linked=datetime.datetime.now(),
         activity_type="person",
 ):
     """
     A convenience function to declare a follow link
     :param actor_id:  Actor ID who's link is being declared in the network
     :param following: The person that is being followed
     :param linked: Datetime of the link
     :param activity_type: String. Single word. The type of feed component that is being followed or watched.
                           For example, if the class is "actor" then it's type could be "Person", "User" or "Member".
                           If the class is "object" then its type could be "Document", or "Project".
     :return: None
     """
     a_linked_activity = LinkedActivity(following,
                                        activity_type=activity_type)
     a_link = Link(actor_id, a_linked_activity, linked=linked)
     self.add_network_link(a_link)
def test_manager():
    es_host = "localhost"
    es_port = 9200
    use_ssl = "False"
    ready = False
    print("Waiting for ES to be ready")
    while not ready:
        try:
            if use_ssl == "False":
                resp = requests.get("http://{}:{}/_cluster/health".format(
                    es_host, es_port))
            else:
                resp = requests.get("https://{}:{}/_cluster/health".format(
                    es_host, es_port))
            data = resp.json()
            if data["status"] == "yellow" or data["status"] == "green":
                ready = True
            else:
                time.sleep(30)
        except Exception as e:
            print(str(e))
            time.sleep(30)

    print("ES is ready")

    now = datetime.datetime.now()
    tst_manager = Manager(
        "testfeeds",
        "testnetwork",
        delete_network_if_exists=True,
        delete_feeds_if_exists=True,
    )
    # Creates a linked activity
    tst_linked_activity = LinkedActivity("cquiros")
    # Testing properties
    tst_linked_activity.activity_id = "cquiros"
    tst_linked_activity.activity_class = "actor"
    tst_linked_activity.activity_type = "person"

    # Creates a link
    tst_link = Link("cquiros", tst_linked_activity)
    # Testing properties
    tst_link.actor_id = "cquiros"
    tst_link.linked_activity = tst_linked_activity
    tst_link.linked = now
    tst_link.link_type = "follow"
    tst_link.link_weight = 1
    tst_link.extra = {"some_extra_data": "test"}

    # Adds the network link
    tst_manager.add_network_link(tst_link)

    # Carlos follow Eduardo. Test of convenience function
    tst_manager.follow("cquiros", "edoquiros", now)

    # --------------------------- Adds some activity feeds ------------------------------

    # An actor called cquiros adds project A

    # Creates an actor
    tst_actor = Actor("cquiros", "person")
    # Creates an object
    tst_object = Object("50a808d3-1227-4149-80e9-20922bded1cf", "project")
    # Creates an Activity
    tst_activity = Activity("add",
                            tst_actor,
                            tst_object,
                            published=now + datetime.timedelta(minutes=12))
    # Adds the activity
    tst_manager.add_activity_feed(tst_activity)

    # cquiros adds project B

    # Creates an object
    tst_object = Object("152a3304-e78d-4fdf-9449-0943d6072596", "project")
    # Creates an Activity
    tst_activity = Activity("add",
                            tst_actor,
                            tst_object,
                            published=now + datetime.timedelta(minutes=24))
    # Adds the activity
    tst_manager.add_activity_feed(tst_activity)

    # cquiros adds Form 1 in project A

    # Creates an object
    tst_object = Object("326c1f4e-a489-4e36-9d0c-5638ef193f6f", "form")
    # Creates a target
    tst_target = Target("50a808d3-1227-4149-80e9-20922bded1cf", "project")
    # Creates an Activity
    tst_activity = Activity(
        "add",
        tst_actor,
        tst_object,
        activity_target=tst_target,
        published=now + datetime.timedelta(minutes=48),
    )
    # Adds the activity
    tst_manager.add_activity_feed(tst_activity)

    # An actor called cquiros moves Form 1 from Project A to Project B

    # Creates an actor
    tst_actor = Actor("cquiros", "person", {"some_extra_data": "test"})
    # Testing properties
    tst_actor.actor_id = "cquiros"
    tst_actor.actor_type = "person"
    tst_actor.extra = {"some_extra_data": "test"}
    # Creates an object
    tst_object = Object("326c1f4e-a489-4e36-9d0c-5638ef193f6f", "form",
                        {"some_extra_data": "test"})
    # Testing properties
    tst_object.object_id = "326c1f4e-a489-4e36-9d0c-5638ef193f6f"
    tst_object.object_type = "form"
    tst_object.extra = {"some_extra_data": "test"}
    # Creates an origin
    tst_origin = Origin("50a808d3-1227-4149-80e9-20922bded1cf", "project",
                        {"some_extra_data": "test"})
    # Testing properties
    tst_origin.origin_id = "50a808d3-1227-4149-80e9-20922bded1cf"
    tst_origin.origin_type = "project"
    tst_origin.extra = {"some_extra_data": "test"}
    # Creates a target
    tst_target = Target("152a3304-e78d-4fdf-9449-0943d6072596", "project",
                        {"some_extra_data": "test"})
    # Testing properties
    tst_target.target_id = "152a3304-e78d-4fdf-9449-0943d6072596"
    tst_target.target_type = "project"
    tst_target.extra = {"some_extra_data": "test"}
    # Creates an Activity
    tst_activity = Activity(
        "move",
        tst_actor,
        tst_object,
        activity_origin=tst_origin,
        activity_target=tst_target,
        extra={"some_extra_data": "test"},
    )
    # Testing properties
    tst_activity.activity_type = "move"
    tst_activity.activity_actor = tst_actor
    tst_activity.activity_object = tst_object
    tst_activity.published = datetime.datetime.now() + datetime.timedelta(
        minutes=72)
    tst_activity.activity_origin = tst_origin
    tst_activity.activity_target = tst_target
    tst_activity.extra = {"some_extra_data": "test"}
    # Adds the activity
    tst_manager.add_activity_feed(tst_activity)

    # Carlos Watches project A. Test of convenience function
    tst_manager.watch("cquiros", "50a808d3-1227-4149-80e9-20922bded1cf",
                      "project")
    # Wait 2 seconds for ES to store previous data. This is only for this testing script
    time.sleep(2)
Beispiel #7
0
def test_manager():
    now = datetime.datetime.now()
    tst_manager = Manager(
        "testfeeds",
        "testnetwork",
        delete_network_if_exists=True,
        delete_feeds_if_exists=True,
    )
    # Creates a linked activity
    tst_linked_activity = LinkedActivity("cquiros")
    # Testing properties
    tst_linked_activity.activity_id = "cquiros"
    tst_linked_activity.activity_class = "actor"
    tst_linked_activity.activity_type = "person"

    # Creates a link
    tst_link = Link("cquiros", tst_linked_activity)
    # Testing properties
    tst_link.actor_id = "cquiros"
    tst_link.linked_activity = tst_linked_activity
    tst_link.linked = now
    tst_link.link_type = "follow"
    tst_link.link_weight = 1
    tst_link.extra = {"some_extra_data": "test"}

    # Adds the network link
    tst_manager.add_network_link(tst_link)

    # Carlos follow Eduardo. Test of convenience function
    tst_manager.follow("cquiros", "edoquiros", now)

    # --------------------------- Adds some activity feeds ------------------------------

    # An actor called cquiros adds project A

    # Creates an actor
    tst_actor = Actor("cquiros", "person")
    # Creates an object
    tst_object = Object("50a808d3-1227-4149-80e9-20922bded1cf", "project")
    # Creates an Activity
    tst_activity = Activity("add",
                            tst_actor,
                            tst_object,
                            published=now + datetime.timedelta(minutes=12))
    # Adds the activity
    tst_manager.add_activity_feed(tst_activity)

    # cquiros adds project B

    # Creates an object
    tst_object = Object("152a3304-e78d-4fdf-9449-0943d6072596", "project")
    # Creates an Activity
    tst_activity = Activity("add",
                            tst_actor,
                            tst_object,
                            published=now + datetime.timedelta(minutes=24))
    # Adds the activity
    tst_manager.add_activity_feed(tst_activity)

    # cquiros adds Form 1 in project A

    # Creates an object
    tst_object = Object("326c1f4e-a489-4e36-9d0c-5638ef193f6f", "form")
    # Creates a target
    tst_target = Target("50a808d3-1227-4149-80e9-20922bded1cf", "project")
    # Creates an Activity
    tst_activity = Activity(
        "add",
        tst_actor,
        tst_object,
        activity_target=tst_target,
        published=now + datetime.timedelta(minutes=48),
    )
    # Adds the activity
    tst_manager.add_activity_feed(tst_activity)

    # An actor called cquiros moves Form 1 from Project A to Project B

    # Creates an actor
    tst_actor = Actor("cquiros", "person", {"some_extra_data": "test"})
    # Testing properties
    tst_actor.actor_id = "cquiros"
    tst_actor.actor_type = "person"
    tst_actor.extra = {"some_extra_data": "test"}
    # Creates an object
    tst_object = Object("326c1f4e-a489-4e36-9d0c-5638ef193f6f", "form",
                        {"some_extra_data": "test"})
    # Testing properties
    tst_object.object_id = "326c1f4e-a489-4e36-9d0c-5638ef193f6f"
    tst_object.object_type = "form"
    tst_object.extra = {"some_extra_data": "test"}
    # Creates an origin
    tst_origin = Origin("50a808d3-1227-4149-80e9-20922bded1cf", "project",
                        {"some_extra_data": "test"})
    # Testing properties
    tst_origin.origin_id = "50a808d3-1227-4149-80e9-20922bded1cf"
    tst_origin.origin_type = "project"
    tst_origin.extra = {"some_extra_data": "test"}
    # Creates a target
    tst_target = Target("152a3304-e78d-4fdf-9449-0943d6072596", "project",
                        {"some_extra_data": "test"})
    # Testing properties
    tst_target.target_id = "152a3304-e78d-4fdf-9449-0943d6072596"
    tst_target.target_type = "project"
    tst_target.extra = {"some_extra_data": "test"}
    # Creates an Activity
    tst_activity = Activity(
        "move",
        tst_actor,
        tst_object,
        activity_origin=tst_origin,
        activity_target=tst_target,
        extra={"some_extra_data": "test"},
    )
    # Testing properties
    tst_activity.activity_type = "move"
    tst_activity.activity_actor = tst_actor
    tst_activity.activity_object = tst_object
    tst_activity.published = datetime.datetime.now() + datetime.timedelta(
        minutes=72)
    tst_activity.activity_origin = tst_origin
    tst_activity.activity_target = tst_target
    tst_activity.extra = {"some_extra_data": "test"}
    # Adds the activity
    tst_manager.add_activity_feed(tst_activity)

    # Carlos Watches project A. Test of convenience function
    tst_manager.watch("cquiros", "50a808d3-1227-4149-80e9-20922bded1cf",
                      "project")
    # Wait 2 seconds for ES to store previous data. This is only for this testing script
    time.sleep(2)