def test_updated_large_capital_opportunity_synced(opensearch_with_signals): """Test that when a large capital opportunity is updated it is synced to OpenSearch.""" opportunity = LargeCapitalOpportunityFactory() opportunity.total_investment_sought = 12345 opportunity.save() opensearch_with_signals.indices.refresh() doc = _get_documents(opensearch_with_signals, opportunity.pk) assert doc['_source']['total_investment_sought'] == 12345
def test_audit_log_view(self): """Test retrieval of audit log.""" initial_datetime = now() with reversion.create_revision(): opportunity = LargeCapitalOpportunityFactory( name='This amazing opportunity', ) reversion.set_comment('Initial') reversion.set_date_created(initial_datetime) reversion.set_user(self.user) changed_datetime = now() with reversion.create_revision(): opportunity.name = 'That amazing opportunity' opportunity.save() reversion.set_comment('Changed') reversion.set_date_created(changed_datetime) reversion.set_user(self.user) versions = Version.objects.get_for_object(opportunity) version_id = versions[0].id url = reverse('api-v4:large-capital-opportunity:audit-item', kwargs={'pk': opportunity.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']['name'] == [ 'This amazing opportunity', 'That amazing opportunity' ] assert not set(EXCLUDED_BASE_MODEL_FIELDS) & entry['changes'].keys()