def test_structure_job_create(): # TODO: test structures with dependency 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() 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() with pytest.raises(Exception) as execinfo: createJob('destroy', s, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' with pytest.raises(Exception) as execinfo: createJob('other', s, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' assert createJob('create', s, TestUser()) is not None assert s.state == 'planned' with pytest.raises(Exception) as execinfo: createJob('create', s, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' s.structurejob.delete() s = Structure.objects.get(pk=s.pk) f.setBuilt() with pytest.raises(Exception) as execinfo: createJob('destroy', s, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' with pytest.raises(Exception) as execinfo: createJob('other', s, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' s.setBuilt() with pytest.raises(Exception) as execinfo: createJob('create', s, TestUser()) assert str(execinfo.value.code) == 'ALLREADY_BUILT' assert s.state == 'built' assert createJob('other', s, TestUser()) is not None assert s.state == 'built' with pytest.raises(Exception) as execinfo: createJob('other', s, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' s.structurejob.delete() s = Structure.objects.get(pk=s.pk) assert createJob('destroy', s, TestUser()) is not None assert s.state == 'built' with pytest.raises(Exception) as execinfo: createJob('destroy', s, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' s.structurejob.delete() s = Structure.objects.get(pk=s.pk) f.setLocated() with pytest.raises(Exception) as execinfo: createJob('destroy', s, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' # test job type checking s.setDestroyed() f.setDestroyed() s = Structure.objects.get(pk=s.pk) f = Foundation.objects.get(pk=f.pk) assert createJob('create', f, TestUser()) is not None assert createJob('create', s, TestUser()) is not None s.structurejob.delete() f.foundationjob.delete() s = Structure.objects.get(pk=s.pk) f = Foundation.objects.get(pk=f.pk) s.setDestroyed() f.setBuilt() s = Structure.objects.get(pk=s.pk) f = Foundation.objects.get(pk=f.pk) assert createJob('other', f, TestUser()) is not None with pytest.raises(Exception) as execinfo: createJob('create', s, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' f.foundationjob.delete() s = Structure.objects.get(pk=s.pk) f = Foundation.objects.get(pk=f.pk) s.setBuilt() f.setBuilt() s = Structure.objects.get(pk=s.pk) f = Foundation.objects.get(pk=f.pk) assert createJob('destroy', f, TestUser()) is not None assert createJob('destroy', s, TestUser()) is not None s.structurejob.delete() f.foundationjob.delete() s = Structure.objects.get(pk=s.pk) f = Foundation.objects.get(pk=f.pk) s.setBuilt() f.setBuilt() s = Structure.objects.get(pk=s.pk) f = Foundation.objects.get(pk=f.pk) assert createJob('other', f, TestUser()) is not None with pytest.raises(Exception) as execinfo: createJob('destroy', s, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' f.foundationjob.delete() s = Structure.objects.get(pk=s.pk) f = Foundation.objects.get(pk=f.pk)
def test_foundation_job_create( ): # TODO: should also do tests depending on a Dependency 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() with pytest.raises(Exception) as execinfo: createJob('destroy', f, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' with pytest.raises(Exception) as execinfo: createJob('other', f, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' assert createJob('create', f, TestUser()) is not None assert f.state == 'planned' with pytest.raises(Exception) as execinfo: createJob('create', f, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) f.setLocated() with pytest.raises(Exception) as execinfo: createJob('destroy', f, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' with pytest.raises(ValueError) as execinfo: createJob('other', f, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' assert createJob('create', f, TestUser()) is not None assert f.state == 'located' with pytest.raises(Exception) as execinfo: createJob('create', f, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) f.setBuilt() with pytest.raises(Exception) as execinfo: createJob('create', f, TestUser()) assert str(execinfo.value.code) == 'ALLREADY_BUILT' assert f.state == 'built' assert createJob('other', f, TestUser()) is not None assert f.state == 'built' with pytest.raises(Exception) as execinfo: createJob('other', f, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) assert createJob('destroy', f, TestUser()) is not None assert f.state == 'built' with pytest.raises(Exception) as execinfo: createJob('destroy', f, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk)
def test_foundation_with_structure_job_create(): 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() 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() f.setDestroyed() assert createJob('create', f, TestUser()) is not None f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) f.setLocated() assert createJob('create', f, TestUser()) is not None f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) f.setBuilt() with pytest.raises(Exception) as execinfo: createJob('create', f, TestUser()) assert str(execinfo.value.code) == 'ALLREADY_BUILT' f.setDestroyed() s.setBuilt() assert createJob('create', f, TestUser()) is not None f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) f.setLocated() s.setBuilt() assert createJob('create', f, TestUser()) is not None f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) f.setBuilt() s.setBuilt() with pytest.raises(Exception) as execinfo: createJob('create', f, TestUser()) assert str(execinfo.value.code) == 'ALLREADY_BUILT' s.setDestroyed() f.setBuilt() assert createJob('destroy', f, TestUser()) is not None f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) f.setLocated() with pytest.raises(Exception) as execinfo: createJob('destroy', f, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' f.setDestroyed() with pytest.raises(Exception) as execinfo: createJob('destroy', f, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' s.setBuilt() f.setBuilt() assert createJob('destroy', f, TestUser()) is not None f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) f.setLocated() s.setBuilt() with pytest.raises(Exception) as execinfo: createJob('destroy', f, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' f.setDestroyed() s.setBuilt() with pytest.raises(Exception) as execinfo: createJob('destroy', f, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT'
def test_can_start_mixed(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() 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() d = Dependency() d.structure = s d.link = 'soft' d.full_clean() d.save() f.setBuilt() s.setDestroyed() createJob('create', s, TestUser()) createJob('destroy', f, TestUser()) assert f.foundationjob.can_start is False assert s.structurejob.can_start is True f.foundationjob.delete() s.structurejob.delete() f = Foundation.objects.get(pk=f.pk) s = Structure.objects.get(pk=s.pk) d = Dependency.objects.get(pk=d.pk) d.foundation = f d.full_clean() d.save() d.setBuilt() s.setBuilt() d.setDestroyed() d = Dependency.objects.get(pk=d.pk) createJob('create', d, TestUser()) createJob('destroy', s, TestUser()) assert s.structurejob.can_start is False assert d.dependencyjob.can_start is True s.structurejob.delete() d.dependencyjob.delete() s = Structure.objects.get(pk=s.pk) d = Dependency.objects.get(pk=d.pk) s.setBuilt() d.setBuilt() f.setLocated() s = Structure.objects.get(pk=s.pk) createJob('create', f, TestUser()) createJob('destroy', d, TestUser()) d = Dependency.objects.get(pk=d.pk) d.setBuilt() assert d.dependencyjob.can_start is False assert f.foundationjob.can_start is True d.dependencyjob.delete() f.foundationjob.delete() d = Dependency.objects.get(pk=d.pk) f = Foundation.objects.get(pk=f.pk)