def test_ct_without_revisions_error(self, logger): """Tests that notifications for CycleTask without revisions are handled properly.""" contract = factories.ContractFactory(title=u"Test Contract") cycle_task = wf_factories.CycleTaskGroupObjectTaskFactory( title=u"task1") relationship = factories.RelationshipFactory(source=contract, destination=cycle_task) db.session.delete(relationship) db.session.commit() relationship_revision = Revision(obj=relationship, modified_by_id=None, action="deleted", content="{}") revisions = [relationship_revision] factories.EventFactory(modified_by_id=login.get_current_user_id(), action="DELETE", resource_id=relationship.id, resource_type=relationship.type, revisions=revisions) contract_revision = db.session.query(Revision).filter( Revision.resource_type == "Contract", Revision.action == "created", Revision.resource_id == contract.id).one() db.session.delete(contract_revision) db.session.commit() get_cycle_task_dict(cycle_task) logger.warning.assert_called_once_with( "Unmapped %s id %s from CycleTask id %s has no revisions logged. ", "Contract", contract.id, cycle_task.id)
def test_multiple_relevant_query(self): """Test multiple relevant query""" with factories.single_commit(): policies = [factories.PolicyFactory(title="policy-{}".format(i)) for i in range(1, 5)] contracts = [factories.ContractFactory(title="contract-{}".format(i)) for i in range(1, 5)] programs = [factories.ProgramFactory(title="program-{}".format(i)) for i in range(1, 10)] policy_slugs = [policy.slug for policy in policies] contract_slugs = [contract.slug for contract in contracts] program_slugs = [program.slug for program in programs] program_data = [ get_object_data("Program", program_slugs[0], "", ""), get_object_data("Program", program_slugs[1], contract_slugs[0], ""), get_object_data("Program", program_slugs[2], '\n'.join(contract_slugs[1:3]), ""), get_object_data("Program", program_slugs[3], "", policy_slugs[0]), get_object_data("Program", program_slugs[4], contract_slugs[1], policy_slugs[1]), get_object_data("Program", program_slugs[5], '\n'.join(contract_slugs[2:4]), policy_slugs[2]), get_object_data("Program", program_slugs[6], "", '\n'.join(policy_slugs[1:3])), get_object_data("Program", program_slugs[7], contract_slugs[1], '\n'.join(policy_slugs[2:4])), get_object_data("Program", program_slugs[8], '\n'.join(contract_slugs[:2]), '\n'.join(policy_slugs[:2])), ] self.import_data(*program_data) data = [{ "object_name": "Program", "filters": { "expression": define_op_expr( define_relevant_expr("Policy", policy_slugs[1:2]), "AND", define_relevant_expr("Contract", contract_slugs[:2]) ), }, "fields": "all", }] response = self.export_csv(data) expected = set([5, 9]) for i in range(1, 10): if i in expected: self.assertIn(",program-{},".format(i), response.data) else: self.assertNotIn(",program-{},".format(i), response.data)
def test_get_cycle_task_dict(self): """Tests get_cycle_task_dict functionality.""" contract = factories.ContractFactory(title=u"Contract1") cycle_task = wf_factories.CycleTaskGroupObjectTaskFactory( title=u"task1") relationship = factories.RelationshipFactory(source=contract, destination=cycle_task) db.session.delete(relationship) db.session.commit() relationship_revision = Revision(obj=relationship, modified_by_id=None, action="deleted", content="{}") contract_revision = Revision(obj=contract, modified_by_id=None, action="deleted", content='{"display_name": "Contract1"}') revisions = [relationship_revision, contract_revision] factories.EventFactory(modified_by_id=login.get_current_user_id(), action="DELETE", resource_id=relationship.id, resource_type=relationship.type, revisions=revisions) task_dict = get_cycle_task_dict(cycle_task) self.assertEqual(task_dict["related_objects"][0], u"Contract1 [removed from task]") # Test if we handle the title of the object being empty contract = factories.ContractFactory(title=u"") cycle_task = wf_factories.CycleTaskGroupObjectTaskFactory( title=u"task1") factories.RelationshipFactory(source=contract, destination=cycle_task) task_dict = get_cycle_task_dict(cycle_task) self.assertEqual(task_dict["related_objects"][0], u"Untitled object")
def test_simple_relevant_query(self): """Test simple relevant query""" contract_slugs = [] program_slugs = [] with factories.single_commit(): for i in range(1, 5): contract = factories.ContractFactory(title="contract-{}".format(i)) contract_slugs.append(contract.slug) program = factories.ProgramFactory(title="program-{}".format(i)) program_slugs.append(program.slug) factories.RelationshipFactory(source=contract, destination=program) data = [ get_related_objects("Contract", "Program", contract_slugs[:2]) ] response = self.export_csv(data) expected = set([1, 2]) for i in range(1, 5): if i in expected: self.assertIn(",program-{},".format(i), response.data) else: self.assertNotIn(",program-{},".format(i), response.data)