Esempio n. 1
0
def test_contact_auto_updates_to_opensearch(opensearch_with_signals):
    """Tests if contact gets updated in OpenSearch."""
    test_name = 'very_hard_to_find_contact_ii'
    contact = ContactFactory(first_name=test_name, )
    contact.save()

    new_test_name = 'very_hard_to_find_contact_v'
    contact.first_name = new_test_name
    contact.save()
    opensearch_with_signals.indices.refresh()

    result = get_basic_search_query(Contact, new_test_name).execute()

    assert result.hits.total.value == 1
    assert result.hits[0].id == str(contact.id)
Esempio n. 2
0
def test_contact_auto_updates_to_es(setup_es):
    """Tests if contact gets updated in Elasticsearch."""
    test_name = 'very_hard_to_find_contact_ii'
    contact = ContactFactory(first_name=test_name, )
    contact.save()

    new_test_name = 'very_hard_to_find_contact_v'
    contact.first_name = new_test_name
    contact.save()
    setup_es.indices.refresh()

    result = get_basic_search_query(new_test_name,
                                    entities=(Contact, )).execute()

    assert result.hits.total == 1
    assert result.hits[0].id == str(contact.id)
Esempio n. 3
0
    def test_audit_log_view(self):
        """Test retrieval of audit log."""
        initial_datetime = now()
        with reversion.create_revision():
            contact = ContactFactory(notes='Initial notes', )

            reversion.set_comment('Initial')
            reversion.set_date_created(initial_datetime)
            reversion.set_user(self.user)

        changed_datetime = now()
        with reversion.create_revision():
            contact.notes = 'New notes'
            contact.save()

            reversion.set_comment('Changed')
            reversion.set_date_created(changed_datetime)
            reversion.set_user(self.user)

        versions = Version.objects.get_for_object(contact)
        version_id = versions[0].id
        url = reverse('api-v3:contact:audit-item', kwargs={'pk': contact.pk})

        response = self.api_client.get(url)
        response_data = response.json()['results']

        # No need to test the whole response
        assert len(response_data) == 1
        entry = response_data[0]

        assert entry['id'] == version_id
        assert entry['user']['name'] == self.user.name
        assert entry['comment'] == 'Changed'
        assert entry['timestamp'] == format_date_or_datetime(changed_datetime)
        assert entry['changes']['notes'] == ['Initial notes', 'New notes']
        assert not set(EXCLUDED_BASE_MODEL_FIELDS) & entry['changes'].keys()