Esempio n. 1
0
    def test_search_event_disabled_on_exists(self, opensearch_with_collector):
        """Tests disabled_on is null filter."""
        url = reverse('api-v3:search:event')

        current_datetime = now()
        EventFactory.create_batch(5)
        EventFactory.create_batch(5, disabled_on=current_datetime)

        opensearch_with_collector.flush_and_refresh()

        response = self.api_client.post(
            url,
            data={
                'disabled_on_exists': True,
            },
        )

        assert response.status_code == status.HTTP_200_OK
        # We should get at least 5 disabled events, as some already exist
        assert response.data['count'] == 5
        assert len(response.data['results']) == 5

        disabled_ons = (result['disabled_on']
                        for result in response.data['results'])
        assert all(disabled_on is not None for disabled_on in disabled_ons)
Esempio n. 2
0
    def test_search_event_teams(self, opensearch_with_collector):
        """Tests teams filter."""
        url = reverse('api-v3:search:event')

        team_a = TeamFactory()
        team_b = TeamFactory()
        team_c = TeamFactory()
        EventFactory(teams=(team_c, ))
        EventFactory.create_batch(5, teams=(team_a, team_b))
        EventFactory.create_batch(5, teams=(team_b, ))

        opensearch_with_collector.flush_and_refresh()

        response = self.api_client.post(
            url,
            data={
                'teams': (team_a.id, team_c.id),
            },
        )

        assert response.status_code == status.HTTP_200_OK
        assert response.data['count'] == 6
        assert len(response.data['results']) == 6

        event_teams = (result['teams'] for result in response.data['results'])
        for teams in event_teams:
            team_ids = {team['id'] for team in teams}
            assert len(team_ids.intersection({str(team_a.id),
                                              str(team_c.id)})) > 0
Esempio n. 3
0
    def test_search_event_lead_team(self, opensearch_with_collector):
        """Tests lead_team filter."""
        url = reverse('api-v3:search:event')

        team = TeamFactory()
        EventFactory.create_batch(5)
        EventFactory.create_batch(5, lead_team_id=team.id)
        opensearch_with_collector.flush_and_refresh()

        response = self.api_client.post(
            url,
            data={
                'lead_team': team.id,
            },
        )

        assert response.status_code == status.HTTP_200_OK
        assert response.data['count'] == 5
        assert len(response.data['results']) == 5

        team_ids = [
            result['lead_team']['id'] for result in response.data['results']
        ]

        assert all(team_id == str(team.id) for team_id in team_ids)
Esempio n. 4
0
    def test_list(self):
        """Tests listing events."""
        EventFactory.create_batch(2)
        url = reverse('api-v3:event:collection')

        response = self.api_client.get(url)
        assert response.status_code == status.HTTP_200_OK
        response_data = response.json()

        assert response_data['count'] == 2
def test_event_dbmodels_to_es_documents(setup_es):
    """Tests conversion of db models to Elasticsearch documents."""
    events = EventFactory.create_batch(2)

    result = ESEvent.db_objects_to_es_documents(events)

    assert len(list(result)) == len(events)
Esempio n. 6
0
def test_event_dbmodels_to_documents(opensearch):
    """Tests conversion of db models to OpenSearch documents."""
    events = EventFactory.create_batch(2)

    result = SearchEvent.db_objects_to_documents(events)

    assert len(list(result)) == len(events)
Esempio n. 7
0
    def test_disable_selected_events(self):
        """Tests disable selected action."""
        events = EventFactory.create_batch(5)

        ids = [event.id for event in events]

        url = reverse('admin:event_event_changelist')
        data = {
            'action': 'disable_selected',
            helpers.ACTION_CHECKBOX_NAME: ids,
        }
        response = self.client.post(url, data)

        assert response.status_code == status.HTTP_200_OK

        # Check if we get confirmation page in the response.
        query = 'Are you sure you want to disable the selected events?'
        assert query in str(response.content)

        # Make sure none of selected events has been disabled.
        for event in events:
            event.refresh_from_db()
            assert event.disabled_on is None

        # Confirm the action
        data['confirm'] = 'yes'
        response = self.client.post(url, data)
        assert response.status_code == status.HTTP_302_FOUND

        # Check if selected events have been disabled.
        for event in events:
            event.refresh_from_db()
            assert event.disabled_on is not None
Esempio n. 8
0
    def test_search_event_nested_disabled_on_after_or_none(
            self, opensearch_with_collector):
        """Tests nested disabled_on filter."""
        url = reverse('api-v3:search:event')

        current_datetime = now()
        old_datetime = datetime.datetime(2000, 9, 12, 1, 2, 3, tzinfo=utc)
        EventFactory.create_batch(2)
        EventFactory.create_batch(3, disabled_on=old_datetime)
        EventFactory.create_batch(5, disabled_on=current_datetime)

        opensearch_with_collector.flush_and_refresh()

        response = self.api_client.post(
            url,
            data={
                'disabled_on': {
                    'exists': False,
                    'after': current_datetime,
                },
            },
        )

        assert response.status_code == status.HTTP_200_OK
        assert response.data['count'] == 7
        assert len(response.data['results']) == 7

        disabled_ons = [
            result['disabled_on'] for result in response.data['results']
        ]
        assert all(
            disabled_on is None or disabled_on == current_datetime.isoformat()
            for disabled_on in disabled_ons)
Esempio n. 9
0
def setup_data():
    """Sets up data for the tests."""
    EventFactory.create_batch(2)