def test_program_slave_not_exist_error(self): slave = SlaveFactory() script = ScriptFactory() self.assertRaises( ProgramNotExistError, ScriptEntryProgram( 0, -1, int(slave.id), ).save, script, ) self.assertRaises( ProgramNotExistError, ScriptEntryProgram( 0, "", int(slave.id), ).save, script, ) slave.delete() self.assertRaises( SlaveNotExistError, ScriptEntryProgram( 0, -1, -1, ).save, script, )
def test_from_json_program(self): string = '{"index": 0, "slave": 0, "program": "no name"}' script = ScriptEntryProgram(0, "no name", 0) self.assertEqual(ScriptEntryProgram.from_json(string), script) self.assertEqual( ScriptEntryProgram.from_json(script.to_json()), script, )
def test_string_identifiers(self): slave = SlaveFactory() program = ProgramFactory(slave=slave) filesystem = FileFactory(slave=slave) script_name = ScriptFactory.build().name Script( script_name, [ScriptEntryProgram(0, program.name, slave.name)], [ScriptEntryFilesystem(0, filesystem.name, slave.name)], ).save() script = ScriptModel.objects.get(name=script_name) self.assertTrue(ScriptModel.objects.filter(name=script_name).exists()) self.assertTrue( SGP.objects.filter( script=script, index=0, program=program, ).exists()) self.assertTrue( SGF.objects.filter( script=script, index=0, filesystem=filesystem, ).exists())
def test_model_references_same_int(self): program = ProgramFactory() slave = program.slave script = ScriptFactory() ScriptEntryProgram(0, program.id, slave.id).save(script) with_str = ScriptEntryProgram( 0, program.name, slave.name, ) self.assertRaises( ValidationError, with_str.save, script, )
def test_program_not_exist(self): program = ProgramFactory() slave = program.slave script_name = ScriptFactory.build().name script = Script( script_name, [ ScriptEntryProgram(0, program.id, slave.id), ScriptEntryProgram(0, program.id + 1, slave.id), ], [], ) self.assertRaises( ProgramNotExistError, script.save, ) self.assertFalse(ScriptModel.objects.filter(name=script_name).exists()) self.assertTrue(len(SGP.objects.all()) == 0)
def test_from_json(self): string = '{"name": "test", "filesystems": [{"index": 0, "slave": 0, "filesystem": \ "no name"}], "programs": [{"index": 0, "slave": 0, \ "program": "no name"}]}' script = Script( "test", [ScriptEntryProgram(0, "no name", 0)], [ScriptEntryFilesystem(0, "no name", 0)], ) self.assertEqual(Script.from_json(string), script) self.assertEqual(Script.from_json(script.to_json()), script)
def test_name_not_equal(self): self.assertNotEqual( Script("test", [ScriptEntryProgram(0, 0, 0)], []), Script("test2", [ScriptEntryProgram(0, 0, 0)], []), )