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