def test_updateConfig_structure(mocker): mocker.patch('contractor.Records.lib._connect', fake_connect) global fake_key global fake_item s = Site() s.name = 'site_test' s.description = 'testing Site' s.full_clean() s.save() fb = FoundationBluePrint() fb.name = 'fdnbp_test' fb.description = 'testing FBP' fb.foundation_type_list = ['Unknown'] fb.full_clean() fb.save() fdn = Foundation() fdn.locator = 'fdn_test' fdn.blueprint = fb fdn.site = s fdn.full_clean() fdn.save() sb = StructureBluePrint() sb.name = 'strbp_test' sb.description = 'testing SBP' sb.full_clean() sb.save() sb.foundation_blueprint_list = [fb] sb.full_clean() sb.save() fake_key = None fake_item = None str = Structure() str.hostname = 'testme' str.site = s str.blueprint = sb str.foundation = fdn str.full_clean() str.save() pk = str.pk assert fake_key == { '_id': pk } # the auto inc value could be all sorts of values assert _tweek_variables(fake_item) == { '__last_modified': '*DATETIME*', '__timestamp': '*DATETIME*', '_site': 'site_test', '_blueprint': 'strbp_test', '_foundation_class_list': [], '_foundation_id': 'fdn_test', '_foundation_id_map': None, '_foundation_interface_list': [], '_foundation_locator': 'fdn_test', '_foundation_state': 'planned', '_foundation_type': 'Unknown', '_fqdn': 'testme', '_hostname': 'testme', '_domain_name': None, '_interface_map': {}, '_provisioning_interface': None, '_provisioning_interface_mac': None, '_provisioning_address': None, '_primary_interface': None, '_primary_interface_mac': None, '_primary_address': None, '_structure_config_uuid': '*UUID*', '_structure_id': '*ID*', '_structure_state': 'planned' } fake_key = None fake_item = None str.config_values = {'sdf': {'a': 'rrrr', 'b': [1, 2, 3, 4]}} str.full_clean() str.save() assert fake_key == {'_id': pk} assert _tweek_variables(fake_item) == { '__last_modified': '*DATETIME*', '__timestamp': '*DATETIME*', '_site': 'site_test', '_blueprint': 'strbp_test', '_foundation_class_list': [], '_foundation_id': 'fdn_test', '_foundation_id_map': None, '_foundation_interface_list': [], '_foundation_locator': 'fdn_test', '_foundation_state': 'planned', '_foundation_type': 'Unknown', '_fqdn': 'testme', '_hostname': 'testme', '_domain_name': None, '_interface_map': {}, '_provisioning_interface': None, '_provisioning_interface_mac': None, '_provisioning_address': None, '_primary_interface': None, '_primary_interface_mac': None, '_primary_address': None, '_structure_config_uuid': '*UUID*', '_structure_id': '*ID*', '_structure_state': 'planned', 'sdf': { 'a': 'rrrr', 'b': [1, 2, 3, 4] } } fake_key = None str.delete() assert fake_key == {'_id': pk}
def test_can_start_destroy(mocker): mocker.patch('contractor.Building.models.Foundation._canSetState', fake_canSetState) # disable the job checking mocker.patch('contractor.Building.models.Structure._canSetState', fake_canSetState) mocker.patch('contractor.Building.models.Dependency._canSetState', fake_canSetState) si = Site() si.name = 'test' si.description = 'test' si.full_clean() si.save() fb = FoundationBluePrint(name='fdnb1', description='Foundation BluePrint 1') fb.foundation_type_list = ['Unknown'] fb.full_clean() fb.save() f = Foundation() f.locator = 'test' f.site = si f.blueprint = fb f.full_clean() f.save() f.setBuilt() createJob('destroy', f, TestUser()) assert f.foundationjob.can_start is True sb = StructureBluePrint(name='strb1', description='Structure BluePrint 1') sb.full_clean() sb.save() sb.foundation_blueprint_list.add(fb) s = Structure() s.foundation = f s.hostname = 'test' s.site = si s.blueprint = sb s.full_clean() s.save() s.setBuilt() createJob('destroy', s, TestUser()) assert f.foundationjob.can_start is False assert s.structurejob.can_start is True d = Dependency() d.structure = s d.link = 'soft' d.full_clean() d.save() d.setBuilt() createJob('destroy', d, TestUser()) assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is True d2 = Dependency() d2.dependency = d d2.link = 'soft' d2.full_clean() d2.save() d2.setBuilt() createJob('destroy', d2, TestUser()) assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is False assert d2.dependencyjob.can_start is True d2.setDestroyed() assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is True assert d2.dependencyjob.can_start is False d.setDestroyed() assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is False assert d2.dependencyjob.can_start is False s.setDestroyed() assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is False assert d2.dependencyjob.can_start is False f.setDestroyed() assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is False assert d2.dependencyjob.can_start is False d2.setDestroyed() d.setBuilt() s.setBuilt() f.setBuilt() assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is True assert d2.dependencyjob.can_start is False d = Dependency.objects.get(pk=d.pk) d.foundation = f d.full_clean() d.save() assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is False assert d2.dependencyjob.can_start is False f.setDestroyed() s.setBuilt( ) # setting foundation to destoyed, destroys the structure, which destroys the dependency d.setBuilt() assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is False assert d2.dependencyjob.can_start is False f.setBuilt() assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is False assert d2.dependencyjob.can_start is False d2.dependencyjob.delete() d2.setDestroyed() f = Foundation.objects.get(pk=f.pk) s = Structure.objects.get(pk=s.pk) d = Dependency.objects.get(pk=d.pk) assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is False d.dependencyjob.delete() d.setDestroyed() f = Foundation.objects.get(pk=f.pk) s = Structure.objects.get(pk=s.pk) assert f.foundationjob.can_start is False assert s.structurejob.can_start is True s.structurejob.delete() s.setDestroyed() f = Foundation.objects.get(pk=f.pk) assert f.foundationjob.can_start is True s.delete() # setting foundation.structure to None f = Foundation.objects.get(pk=f.pk) assert f.foundationjob.can_start is True