コード例 #1
0
def test_group_add_events(group_1: Group):
    # init group model
    group_1.save()

    # create 10 events
    events: List[Event] = []
    for i in range(0, 10):
        event: Event = Event(
            meetup_id=str(i),
            created=datetime.now(),
            time=datetime.now(),
            name="",
            link="",
            date_in_series_pattern=False,
        )

        events.append(event)

    # add events to group
    group_1.add_events(events)
    group_1.save()
    sleep(1)

    # check if events was added
    group_2: Group = Group.get_group(urlname=group_1.urlname)
    group_events: List[Event] = group_2.events
    assert len(group_events) == 10
    for event in group_events:
        assert isinstance(group_events[i], Event)
        assert group_events[i].meetup_id == str(i)
コード例 #2
0
    def update_all_group_events(
            self,
            group: Group,
            max_entries_per_page: int = 200) -> List[Event]:
        """
        get all past events from meetup rest api & add it as child pages to the group

        Arguments:
            group {Group} -- Group to update

        Keyword Arguments:
            max_entries_per_page {int} -- How many events should be requestst at once on meetup
            (between 1 to 200) (default: {200})

        Returns:
            List[Event] -- List[Event] every new Events wich wasn't already in elasticsearch
        """

        # return [Event], init empty
        events: List[Event] = []

        # fetch all events
        while True:
            group_events: List[Event] = self.update_group_events(
                group=group, max_entries=max_entries_per_page)
            group.add_events(events=group_events)
            group.save()
            # todo replace sleep with wait for save done
            sleep(1)
            events.extend(group_events)
            if len(group_events) == 0:
                break

        return events
コード例 #3
0
def test_get_all_groups(group_1: Group, group_2: Group):
    # test with no group in es
    groups_1: List[Group] = Group.get_all_groups()
    assert len(groups_1) == 0

    # init groups
    group_1.save()
    group_2.save()
    sleep(1)

    # test with 2 group in es
    groups_2: List[Group] = Group.get_all_groups()
    assert len(groups_2) == 2
    assert isinstance(groups_2[0], Group)
コード例 #4
0
def test_group_delete_if_exists(group_1: Group):
    # check when there is no group
    assert Group.delete_if_exists(urlname=group_1.urlname) is False

    # save group
    group_1.save()
    sleep(1)

    # delete group
    assert Group.delete_if_exists(urlname=group_1.urlname) is True
    sleep(1)

    # check if group is really deleted
    with pytest.raises(GroupDoesNotExists):
        Group.get_group(urlname=group_1.urlname)
def test_update_groups(group_1: Group, meetup_groups: dict, app: Flask):
    runner: FlaskCliRunner = app.test_cli_runner()

    # init group to update
    group_1.urlname = meetup_groups["sandbox"]["urlname"]
    group_1.save()
    sleep(2)

    # update all groups
    result_1: Result = runner.invoke(update_groups)
    assert result_1.exit_code == 0
    sleep(2)

    # check if group was updated
    group_2: Group = Group.get_group(urlname=group_1.urlname)
    assert len(group_2.events) > 0
コード例 #6
0
def create_events_to_group(
    search_query: str,
    valid_events: bool,
    group: Group,
    amount: int = 1,
    venue: bool = False,
) -> List[Event]:
    """
    Create random test events and save them to a group

    Arguments:
        search_query {str} -- use query param for the search request
        valid_events {bool} -- should the groups searchable by the the query term
        group {Group} -- group to at the events

    Keyword Arguments:
        amount {int} -- how many events should be created (default: {1})
        venue {bool} -- if venue should be added to eventa (default: {False})

    Returns:
        List[Event] -- created & saved events
    """

    created_events: List[Event] = []

    for i in range(0, amount):
        event_name: str = random_string(search_query=search_query,
                                        valid=valid_events)
        event: Event = Event(
            meetup_id=event_name,
            time=datetime.now(),
            name=event_name,
            link="http://none",
            date_in_series_pattern=False,
        )

        if venue:
            event.venue_name = event_name
            event.venue_location = {"lat": i + 1, "lon": i + 1}

        created_events.append(event)

    group.add_events(events=created_events)
    group.save()
    sleep(1)

    return created_events
コード例 #7
0
def test_group_last_event_time(group_1: Group):
    events: dict = {
        "first": {
            "meetup_id": "first",
            "time": datetime(year=2000, month=1, day=1),
        },
        "middle": {
            "meetup_id": "middle",
            "time": datetime(year=2010, month=1, day=1),
        },
        "last": {
            "meetup_id": "last",
            "time": datetime(year=2020, month=1, day=1),
        },
    }

    # init group models
    group_1.save()

    # test with no event
    assert group_1.last_event_time is None

    # test with one event
    event_first: Event = Event(
        meetup_id=events["first"]["meetup_id"],
        time=events["first"]["time"],
        name="",
        link="",
        date_in_series_pattern=False,
    )
    group_1.add_event(event_first)
    group_1.save()
    assert group_1.last_event_time == events["first"]["time"]

    # test with 2 events
    event_last: Event = Event(
        meetup_id=events["last"]["meetup_id"],
        time=events["last"]["time"],
        name="",
        link="",
        date_in_series_pattern=False,
    )
    group_1.add_event(event_last)
    group_1.save()
    assert group_1.last_event_time == events["last"]["time"]

    # test with 3 events
    event_middle: Event = Event(
        meetup_id=events["middle"]["meetup_id"],
        time=events["middle"]["time"],
        name="",
        link="",
        date_in_series_pattern=False,
    )
    group_1.add_event(event_middle)
    group_1.save()
    assert group_1.last_event_time == events["last"]["time"]
コード例 #8
0
def test_group_get_group(group_1: Group):
    # check when there is no group
    with pytest.raises(GroupDoesNotExists):
        Group.get_group(urlname=group_1.urlname)

    # save group
    group_1.save()
    sleep(1)

    # get group
    group_2: Group = Group.get_group(urlname=group_1.urlname)

    # check when there is a group
    assert isinstance(group_2, Group)
    assert group_2.urlname == group_1.urlname
    assert group_2.meetup_id == group_1.meetup_id
    assert group_2.created == group_1.created
コード例 #9
0
def test_group_get_or_create_by_urlname(group_2: Group):
    # test with non exiting Group
    group_1: Group = Group.get_or_create_by_urlname(
        urlname=group_2.urlname,
        meetup_id=0,
        created=datetime.now(),
        description="",
        name="",
        link="",
        lat=0,
        lon=0,
        members=0,
        status="",
        timezone="",
        visibility="",
    )
    sleep(1)

    # assert if request does not exist
    assert isinstance(group_1, Group)
    assert group_1.meetup_id == 0

    # test with exiting Group
    group_2.save()
    sleep(1)

    # assert if request does exist
    group_3: Group = Group.get_or_create_by_urlname(
        urlname=group_2.urlname,
        meetup_id=0,
        created=datetime.now(),
        description="",
        name="",
        link="",
        lat=0,
        lon=0,
        members=0,
        status="",
        timezone="",
        visibility="",
    )
    assert isinstance(group_3, Group)
    assert group_3.urlname == group_2.urlname
    assert group_3.meetup_id == group_2.meetup_id
コード例 #10
0
def test_group_add_topic(group_1: Group):
    # init group model
    group_1.save()

    # add 10 topics & check if there was added
    for i in range(0, 10):
        topic: Topic = Topic(meetup_id=str(i),
                             lang=str(i),
                             name=str(i),
                             urlkey=str(i))

        group_1.add_topic(topic=topic)
        group_1.save()
        sleep(1)

        group_2: Group = Group.get_group(urlname=group_1.urlname)
        group_topics: List[Topic] = group_2.topics
        assert len(group_topics) == i + 1
        assert isinstance(group_topics[i], Topic)
        assert group_topics[i].meetup_id == str(i)
コード例 #11
0
def test_group_event_exists(group_1: Group, group_2: Group):
    # init group models
    group_1.save()
    group_2.save()

    # init event
    search_event: Event = Event(
        meetup_id=0,
        created=datetime.now(),
        time=datetime.now(),
        name="",
        link="",
        date_in_series_pattern=False,
    )

    # test when event does not exists
    assert group_1.event_exists(
        event_meetup_id=search_event.meetup_id) is False

    # test with existing event
    group_1.add_event(search_event)
    group_1.save()
    assert group_1.event_exists(event_meetup_id=search_event.meetup_id) is True

    # test with saved event in wrong group
    assert group_2.event_exists(
        event_meetup_id=search_event.meetup_id) is False
コード例 #12
0
def test_group_add_event(group_1: Group):
    # init group model
    group_1.save()

    # add 10 events & check if there was added
    for i in range(0, 10):
        event: Event = Event(
            meetup_id=str(i),
            created=datetime.now(),
            time=datetime.now(),
            name="",
            link="",
            date_in_series_pattern=False,
        )

        group_1.add_event(event=event)
        group_1.save()
        sleep(1)

        group_2: Group = Group.get_group(urlname=group_1.urlname)
        group_events: List[Event] = group_2.events
        assert len(group_events) == i + 1
        assert isinstance(group_events[i], Event)
        assert group_events[i].meetup_id == str(i)
コード例 #13
0
def test_search_geo_distance(client: FlaskClient, group_1: Group):
    """
    Test geo_distance filter

    Arguments:
        client {FlaskClient} -- client to access flask web ressource
    """
    # init group with no location
    group_1.save()
    sleep(1)

    # test no location in groups, search for potsdam
    response_1: JSONResponse = client.put(
        url_for("meetupsearchapi"),
        data=generate_search_dict(query="*",
                                  geo_distance="100km",
                                  geo_lat=52.396149,
                                  geo_lon=13.058540),
    )
    assert response_1.status_code == 200
    assert len(response_1.json["results"]) == 0
    assert response_1.json["hits"] == 0
    assert isinstance(response_1, JSONResponse)

    # add berlin as location for group
    event_berlin: Event = Event(
        meetup_id="berlin",
        time=datetime.now(),
        name="berlin",
        link="http://none",
        date_in_series_pattern=False,
        venue_name="Café",
        venue_location={
            "lat": 52.520008,
            "lon": 13.404954
        },
    )
    group_1.add_event(event=event_berlin)
    group_1.save()
    sleep(1)

    # check if potsdam is in 100km from berlin center
    response_2: JSONResponse = client.put(
        url_for("meetupsearchapi"),
        data=generate_search_dict(query="*",
                                  geo_distance="100km",
                                  geo_lat=52.396149,
                                  geo_lon=13.058540),
    )
    assert response_2.status_code == 200
    assert len(response_2.json["results"]) == 1
    assert response_2.json["hits"] == 1
    assert isinstance(response_2, JSONResponse)

    # check if potsdam is in 1km from berlin center
    response_3: JSONResponse = client.put(
        url_for("meetupsearchapi"),
        data=generate_search_dict(query="*",
                                  geo_distance="0.5km",
                                  geo_lat=52.396149,
                                  geo_lon=13.058540),
    )
    assert response_3.status_code == 200
    assert len(response_3.json["results"]) == 0
    assert response_3.json["hits"] == 0
    assert isinstance(response_3, JSONResponse)