def test_spi_fields_are_serialised(self, data_flow_api_client, ist_adviser): """Test that SPI fields are serialised.""" pm_assigned_by = AdviserFactory() pm_assigned_on = now() investment_project = VerifyWinInvestmentProjectFactory( project_manager=ist_adviser, project_manager_first_assigned_on=pm_assigned_on, project_manager_first_assigned_by=pm_assigned_by, ) spi1 = InvestmentProjectInteractionFactory( investment_project=investment_project, service_id=ServiceConstant. investment_enquiry_requested_more_information.value.id, ) spi2 = InvestmentProjectInteractionFactory( investment_project=investment_project, service_id=ServiceConstant.investment_enquiry_assigned_to_ist_cmc. value.id, ) with freeze_time('2017-01-01'): investment_project.stage_id = InvestmentProjectStageConstant.won.value.id investment_project.save() spi5 = InvestmentProjectInteractionFactory( investment_project=investment_project, service_id=ServiceConstant.investment_ist_aftercare_offered.value. id, ) response = data_flow_api_client.get(self.view_url) assert response.status_code == status.HTTP_200_OK response_results = response.json()['results'] assert response_results == [ { 'enquiry_processed': spi1.created_on.isoformat(), 'enquiry_type': spi1.service.name, 'enquiry_processed_by_id': str(spi1.created_by.id), 'assigned_to_ist': spi2.created_on.isoformat(), 'project_manager_assigned': pm_assigned_on.isoformat(), 'project_manager_assigned_by_id': str(pm_assigned_by.id), 'investment_project_id': str(investment_project.id), 'project_moved_to_won': '2017-01-01T00:00:00+00:00', 'aftercare_offered_on': spi5.created_on.isoformat(), 'propositions': [], }, ]
def test_can_get_spi5_start_and_end(spi_report, ist_adviser): """Tests if we can see spi5 start and end dates.""" investment_project = VerifyWinInvestmentProjectFactory( project_manager=ist_adviser, ) with freeze_time('2017-01-01'): investment_project.stage_id = InvestmentProjectStage.won.value.id investment_project.save() with freeze_time('2017-01-15'): InvestmentProjectInteractionFactory( service_id=Service.investment_ist_aftercare_offered.value.id, investment_project=investment_project, ) rows = list(spi_report.rows()) assert len(rows) == 1 assert rows[0]['Project moved to won'] == '2017-01-01T00:00:00+00:00' assert rows[0]['Aftercare offered on'] == '2017-01-15T00:00:00+00:00'
def test_cannot_get_spi5_start_and_end_for_non_new_investor( spi_report, ist_adviser, ): """Tests if we are not going to see spi5 start and end dates if investor is not new.""" investment_project = VerifyWinInvestmentProjectFactory( project_manager=ist_adviser, investor_type_id=InvestorType.existing_investor.value.id, ) with freeze_time('2017-01-01'): investment_project.stage_id = InvestmentProjectStage.won.value.id investment_project.save() with freeze_time('2017-01-15'): InvestmentProjectInteractionFactory( service_id=Service.investment_ist_aftercare_offered.value.id, investment_project=investment_project, ) rows = list(spi_report.rows()) assert len(rows) == 1 assert 'Project moved to won' not in rows[0] assert 'Aftercare offered on' not in rows[0]
def test_write_report(ist_adviser): """Test that SPI report CSV is generated correctly.""" pm_assigned_by = AdviserFactory() pm_assigned_on = now() investment_project = VerifyWinInvestmentProjectFactory( project_manager=ist_adviser, project_manager_first_assigned_on=pm_assigned_on, project_manager_first_assigned_by=pm_assigned_by, ) spi1 = InvestmentProjectInteractionFactory( investment_project=investment_project, service_id=ServiceConstant.investment_enquiry_requested_more_information.value.id, ) spi2 = InvestmentProjectInteractionFactory( investment_project=investment_project, service_id=ServiceConstant.investment_enquiry_assigned_to_ist_cmc.value.id, ) proposition = PropositionFactory( deadline='2017-01-05', status='ongoing', adviser=pm_assigned_by, investment_project=investment_project, created_by=ist_adviser, ) investment_project.stage_id = InvestmentProjectStageConstant.won.value.id investment_project.save() spi5 = InvestmentProjectInteractionFactory( investment_project=investment_project, service_id=ServiceConstant.investment_ist_aftercare_offered.value.id, ) lines = [] file = Mock() file.write = lambda line: lines.append(line.decode('utf8')) write_report(file) headers = ','.join(SPIReport.field_titles.keys()) assert lines[1] == f'{headers}\r\n' row = [ str(investment_project.pk), investment_project.project_code, investment_project.name, investment_project.created_on.isoformat(), spi1.created_on.isoformat(), spi1.service.name, spi1.created_by.name, spi2.created_on.isoformat(), investment_project.project_manager_first_assigned_on.isoformat(), investment_project.project_manager_first_assigned_by.name, investment_project.stage_log.get( stage_id=InvestmentProjectStageConstant.won.value.id, ).created_on.isoformat(), spi5.created_on.isoformat(), f'{proposition.deadline};{proposition.status};;{proposition.adviser.name}', ] expected_line = ','.join(row) assert lines[2] == f'{expected_line}\r\n'