def test_audit_log(s3_stubber): """Test that the audit log is being created.""" investment_project = InvestmentProjectFactory() bucket = 'test_bucket' object_key = 'test_key' csv_content = f"""id,createdon {investment_project.id},2015-09-29 11:03:20.000 """ s3_stubber.add_response( 'get_object', { 'Body': BytesIO(bytes(csv_content, encoding='utf-8')), }, expected_params={ 'Bucket': bucket, 'Key': object_key, }, ) call_command('update_investment_project_created_on', bucket, object_key) investment_project.refresh_from_db() assert investment_project.created_on == datetime(2015, 9, 29, 11, 3, 20, tzinfo=utc) versions = Version.objects.get_for_object(investment_project) assert len(versions) == 1 assert versions[0].revision.get_comment() == 'Created On migration.'
def test_audit_log(s3_stubber): """Test that the audit log is being created.""" investment_project = InvestmentProjectFactory() file_companies = CompanyFactory.create_batch(3) bucket = 'test_bucket' object_key = 'test_key' csv_content = f"""id,investor_company_id,intermediate_company_id,uk_company_id,uk_company_decided {investment_project.id},{file_companies[0].pk},{file_companies[1].pk},{file_companies[2].pk},1 """ s3_stubber.add_response( 'get_object', { 'Body': BytesIO(bytes(csv_content, encoding='utf-8')), }, expected_params={ 'Bucket': bucket, 'Key': object_key, }, ) call_command('update_investment_project_company', bucket, object_key) investment_project.refresh_from_db() assert investment_project.investor_company == file_companies[0] assert investment_project.intermediate_company == file_companies[1] assert investment_project.uk_company == file_companies[2] assert investment_project.uk_company_decided is True versions = Version.objects.get_for_object(investment_project) assert len(versions) == 1 assert versions[0].revision.get_comment() == 'Companies data migration.'
def test_audit_log(s3_stubber): """Test that audit log is being created.""" new_sector = SectorFactory() investment_project = InvestmentProjectFactory() old_sector = investment_project.sector bucket = 'test_bucket' object_key = 'test_key' csv_content = f"""id,old_sector,new_sector {investment_project.id},{old_sector.id},{new_sector.id} """ s3_stubber.add_response( 'get_object', { 'Body': BytesIO(bytes(csv_content, encoding='utf-8')), }, expected_params={ 'Bucket': bucket, 'Key': object_key, }, ) call_command('update_investment_project_sector', bucket, object_key) investment_project.refresh_from_db() assert investment_project.sector == new_sector versions = Version.objects.get_for_object(investment_project) assert len(versions) == 1 assert versions[0].revision.get_comment() == 'Sector migration.'
def test_audit_log(s3_stubber): """Test that audit log is being created.""" investment_project = InvestmentProjectFactory() new_referral_activity = ReferralSourceActivityFactory() new_referral_website = ReferralSourceWebsiteFactory() bucket = 'test_bucket' object_key = 'test_key' csv_content = f"""id,referral_source_activity_id,referral_source_activity_website_id {investment_project.id},{new_referral_activity.id},{new_referral_website.id} """ s3_stubber.add_response( 'get_object', { 'Body': BytesIO(bytes(csv_content, encoding='utf-8')), }, expected_params={ 'Bucket': bucket, 'Key': object_key, }, ) call_command( 'update_investment_project_referral_source_activity_website', bucket, object_key, ) investment_project.refresh_from_db() assert investment_project.referral_source_activity == new_referral_activity assert investment_project.referral_source_activity_website == new_referral_website versions = Version.objects.get_for_object(investment_project) assert len(versions) == 1 assert versions[0].revision.get_comment( ) == 'ReferralSourceActivityWebsite migration.'