def _create_snapshotable_objects(): """Create original objects that will be snapshotted.""" text_cad = factories.CustomAttributeDefinitionFactory( title="text cad", definition_type="market", ) date_cad = factories.CustomAttributeDefinitionFactory( title="date cad", definition_type="market", attribute_type="Date", ) for i in range(5): factories.ControlFactory(title="Control {}".format(i + 1)) factories.OrgGroupFactory() market = factories.MarketFactory(title="Market {}".format(i + 1)) factories.CustomAttributeValueFactory( custom_attribute=date_cad, attributable=market, attribute_value="2016-11-0{}".format(i + 3), ) factories.CustomAttributeValueFactory( custom_attribute=text_cad, attributable=market, attribute_value="2016-11-0{}".format(i + 1), )
def _setup_objects(): """Create and reindex objects needed for tests""" text_cad = factories.CustomAttributeDefinitionFactory( title="text cad", definition_type="market", ) date_cad = factories.CustomAttributeDefinitionFactory( title="date cad", definition_type="market", attribute_type="Date", ) audit = factories.AuditFactory() for i in range(5): factories.OrgGroupFactory() market = factories.MarketFactory() factories.CustomAttributeValueFactory( custom_attribute=date_cad, attributable=market, attribute_value="2016-11-0{}".format(i + 3), ) factories.CustomAttributeValueFactory( custom_attribute=text_cad, attributable=market, attribute_value="2016-11-0{}".format(i + 1), ) revisions = models.Revision.query.filter( models.Revision.resource_type.in_(["OrgGroup", "Market"]), models.Revision.id.in_( db.session.query(func.max(models.Revision.id)).group_by( models.Revision.resource_type, models.Revision.resource_id, ) ), ) for revision in revisions: factories.SnapshotFactory( child_id=revision.resource_id, child_type=revision.resource_type, revision=revision, parent=audit, ) views.do_reindex()
def _setup_objects(): """Create and reindex objects needed for tests""" text_cad = factories.CustomAttributeDefinitionFactory( title="text cad", definition_type="market", ) date_cad = factories.CustomAttributeDefinitionFactory( title="date cad", definition_type="market", attribute_type="Date", ) person_cad = factories.CustomAttributeDefinitionFactory( title="CA person", definition_type="market", attribute_type="Map:Person", ) users = [ "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**" ] for user in users: factories.PersonFactory(email=user) audit = factories.AuditFactory() for i in range(5): factories.ControlFactory(title="Control {}".format(i + 1)) factories.OrgGroupFactory() market = factories.MarketFactory(title="Market {}".format(i + 1)) factories.CustomAttributeValueFactory( custom_attribute=date_cad, attributable=market, attribute_value="2016-11-0{}".format(i + 3), ) factories.CustomAttributeValueFactory( custom_attribute=text_cad, attributable=market, attribute_value="2016-11-0{}".format(i + 1), ) factories.CustomAttributeValueFactory( custom_attribute=person_cad, attributable=market, attribute_value="user{}@example.com".format(i + 1), ) revisions = models.Revision.query.filter( models.Revision.resource_type.in_( ["OrgGroup", "Market", "Control"]), models.Revision.id.in_( db.session.query(func.max(models.Revision.id)).group_by( models.Revision.resource_type, models.Revision.resource_id, )), ) snapshots = [ factories.SnapshotFactory( child_id=revision.resource_id, child_type=revision.resource_type, revision=revision, parent=audit, ) for revision in revisions ] snapshot_map = { snapshot.revision.content["title"]: snapshot for snapshot in snapshots } # create Assessments and issues and map some snapshots to them # Markets and Controls represent snapshots of those objects. assessment_issues = ( factories.AssessmentFactory, factories.IssueFactory, ) for i in range(4): for factory in assessment_issues: # pylint: disable=protected-access obj = factory(title="{} {}".format( factory._meta.model.__name__, i + 1), ) factories.RelationshipFactory( source=audit if i % 2 == 0 else obj, destination=audit if i % 2 == 1 else obj, ) market = snapshot_map["Market {}".format(i + 1)] factories.RelationshipFactory( source=market if i % 2 == 0 else obj, destination=market if i % 2 == 1 else obj, ) for j in range(i): control = snapshot_map["Control {}".format(j + 1)] factories.RelationshipFactory( source=control if i % 2 == 0 else obj, destination=control if i % 2 == 1 else obj, ) # Create an unmapped control for base tests factories.ControlFactory(title="Control 0") views.do_reindex()