def test_modified_on( self, automatic_company_archive_feature_flag, modified_on_delta, expected_archived, ): """ Test that a company modified_on dates around the 3m boundary are archived or not as expected. """ gt_3m_ago = timezone.now() - relativedelta(months=3, days=1) with freeze_time(gt_3m_ago): company = CompanyFactory() CompanyInteractionFactory( company=company, date=timezone.now() - relativedelta(years=8, days=1), ) with freeze_time(timezone.now() - modified_on_delta): company.save() task_result = automatic_company_archive.apply_async( kwargs={'simulate': False}) assert task_result.successful() archived_company = Company.objects.get(pk=company.id) assert archived_company.archived == expected_archived assert archived_company.modified_on == company.modified_on
def test_update_investor_company_updates_country_of_origin_for_in_progress_project( self): """ Test that in progress investment projects' country investment originates from field is updated when corresponding investor company address country is updated. """ investor_company = CompanyFactory( address_country_id=CountryConstant.japan.value.id, ) projects = InvestmentProjectFactory.create_batch( 2, investor_company=investor_company, stage_id=InvestmentProjectStageConstant.prospect.value.id, ) for project in projects: assert (str(project.country_investment_originates_from_id) == CountryConstant.japan.value.id) investor_company.address_country_id = CountryConstant.united_states.value.id investor_company.save() for project in projects: project.refresh_from_db() assert (str(project.country_investment_originates_from_id) == CountryConstant.united_states.value.id)
def test_notify_signal_company_updated_no_investigation(self): """ Test that a notification would not be sent when a company pending investigation is updated. """ client = self._get_dnb_investigation_notify_client() company = CompanyFactory(pending_dnb_investigation=True) client.reset_mock() company.name = 'foobar' company.save() client.send_email_notification.assert_not_called()
def test_edit_company_syncs_large_investor_profile_in_es(es_with_signals): """Tests that updating company details also updated the relevant investor profiles.""" new_company_name = 'SYNC TEST' investor_company = CompanyFactory() investor_profile = LargeCapitalInvestorProfileFactory( investor_company=investor_company) es_with_signals.indices.refresh() investor_company.name = new_company_name investor_company.save() result = _get_es_document(es_with_signals, investor_profile.pk) assert result['_source']['investor_company']['name'] == new_company_name
def test_company_auto_updates_to_es(setup_es): """Tests if company gets updated in Elasticsearch.""" test_name = 'very_hard_to_find_company_international' company = CompanyFactory(name=test_name, ) new_test_name = 'very_hard_to_find_company_local' company.name = new_test_name company.save() setup_es.indices.refresh() result = get_basic_search_query(Company, new_test_name).execute() assert result.hits.total == 1 assert result.hits[0].id == str(company.id)
def test_company_auto_updates_to_opensearch(opensearch_with_signals): """Tests if company gets updated in OpenSearch.""" test_name = 'very_hard_to_find_company_international' company = CompanyFactory(name=test_name, ) new_test_name = 'very_hard_to_find_company_local' company.name = new_test_name company.save() opensearch_with_signals.indices.refresh() result = get_basic_search_query(Company, new_test_name).execute() assert result.hits.total.value == 1 assert result.hits[0].id == str(company.id)
def test_company_can_have_one_list_owner_assigned(): """Test that company can have one list owner assigned.""" company = CompanyFactory() adviser = AdviserFactory() assert company.one_list_account_owner is None # Test that it's nullable company.one_list_account_owner = adviser company.save() # re-fetch object for completeness company_refetch = Company.objects.get(pk=str(company.pk)) assert company_refetch.one_list_account_owner_id == adviser.pk
def test_company_subsidiaries_auto_update_to_opensearch( opensearch_with_signals): """Tests if company subsidiaries get updated in OpenSearch.""" account_owner = AdviserFactory() global_headquarters = CompanyFactory(one_list_account_owner=account_owner) subsidiaries = CompanyFactory.create_batch( 2, global_headquarters=global_headquarters) opensearch_with_signals.indices.refresh() subsidiary_ids = [subsidiary.id for subsidiary in subsidiaries] result = get_documents_by_ids( opensearch_with_signals, CompanySearchApp, subsidiary_ids, ) expected_results = {(str(subsidiary_id), str(account_owner.id)) for subsidiary_id in subsidiary_ids} search_results = { (doc['_id'], doc['_source']['one_list_group_global_account_manager']['id']) for doc in result['docs'] } assert len(result['docs']) == 2 assert search_results == expected_results new_account_owner = AdviserFactory() global_headquarters.one_list_account_owner = new_account_owner global_headquarters.save() opensearch_with_signals.indices.refresh() new_result = get_documents_by_ids( opensearch_with_signals, CompanySearchApp, subsidiary_ids, ) new_expected_results = {(str(subsidiary_id), str(new_account_owner.id)) for subsidiary_id in subsidiary_ids} new_search_results = { (doc['_id'], doc['_source']['one_list_group_global_account_manager']['id']) for doc in new_result['docs'] } assert len(new_result['docs']) == 2 assert new_search_results == new_expected_results
def test_edit_promoter_syncs_large_capital_opportunity_in_opensearch( opensearch_with_signals): """ Tests that updating promoter company details also updated the relevant large capital opportunity. """ new_company_name = 'SYNC TEST' promoter = CompanyFactory() opportunity = LargeCapitalOpportunityFactory(promoters=[promoter]) opensearch_with_signals.indices.refresh() promoter.name = new_company_name promoter.save() result = _get_documents(opensearch_with_signals, opportunity.pk) assert result['_source']['promoters'][0]['name'] == new_company_name
def test_edit_company_does_not_sync_growth_investor_profile(setup_es): """ Tests that updating company details of a company with a growth investor profile, the profile is not synced to elasticsearch. """ investor_company = CompanyFactory() setup_es.indices.refresh() with mock.patch('datahub.search.tasks.sync_object_task.apply_async' ) as mock_sync_object: growth_profile = GrowthInvestorProfileFactory( investor_company=investor_company) investor_company.name = 'SYNC TEST' investor_company.save() assert mock_sync_object.call_args[1]['args'][ 0] != 'large-investor-profile' assert mock_sync_object.call_count == 1 # Updating the company instance with pytest.raises(NotFoundError): assert _get_es_document(setup_es, growth_profile.id) is None
def test_audit_log_view(self): """Test retrieval of audit log.""" initial_datetime = now() with reversion.create_revision(): company = CompanyFactory( description='Initial desc', ) reversion.set_comment('Initial') reversion.set_date_created(initial_datetime) reversion.set_user(self.user) changed_datetime = now() with reversion.create_revision(): company.description = 'New desc' company.save() reversion.set_comment('Changed') reversion.set_date_created(changed_datetime) reversion.set_user(self.user) versions = Version.objects.get_for_object(company) version_id = versions[0].id url = reverse('api-v4:company:audit-item', kwargs={'pk': company.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']['description'] == ['Initial desc', 'New desc'] assert not set(EXCLUDED_BASE_MODEL_FIELDS) & entry['changes'].keys()