def test_unique(self):
        job = Job()
        tagA = Tag()
        tagB = Tag()
        tagA.jobs = [job]
        tagA.tag = "foo0"
        tagB.jobs = [job]
        tagB.tag = "foo1"
        db.session.add_all([job, tagA, tagB])

        with self.assertRaises(DatabaseError):
            db.session.commit()
    def test_insert(self):
        # A job can not be created without a jobtype, create one first
        jobtype = JobType()
        jobtype.name = "foo"
        jobtype.description = "this is a job type"
        jobtype.classname = "Foobar"
        jobtype.code = dedent("""
        class Foobar(JobType):
            pass""").encode("utf-8")
        jobtype.mode = JobTypeLoadMode.OPEN
        db.session.add(jobtype)

        job = Job()
        job.job_type = jobtype
        tag = Tag()
        tag.jobs = [job]
        tag.tag = "foo456"
        db.session.add_all([tag, job])
        db.session.commit()
        model_id = tag.id
        job_id = job.id
        db.session.remove()
        result = Tag.query.filter_by(id=model_id).first()
        self.assertEqual(result.tag, "foo456")
        self.assertEqual(result.jobs[0].id, job_id)
    def test_insert(self):
        # A job can not be created without a jobtype, create one first
        jobtype = JobType()
        jobtype.name = "foo"
        jobtype.description = "this is a job type"
        jobtype_version = JobTypeVersion()
        jobtype_version.jobtype = jobtype
        jobtype_version.version = 1
        jobtype_version.classname = "Foobar"
        jobtype_version.code = ("""
            class Foobar(JobType):
                pass""").encode("utf-8")
        db.session.add(jobtype_version)

        queue = JobQueue()
        queue.name = "FooQueue"

        job = Job()
        job.title = "Test Job"
        job.jobtype_version = jobtype_version
        job.queue = queue

        tag = Tag()
        tag.jobs = [job]
        tag.tag = "foo456"
        db.session.add_all([tag, job])
        db.session.commit()
        model_id = tag.id
        job_id = job.id
        db.session.remove()
        result = Tag.query.filter_by(id=model_id).first()
        self.assertEqual(result.tag, "foo456")
        self.assertEqual(result.jobs[0].id, job_id)
示例#4
0
 def test_tags_validation(self):
     for agent_foobar in self.models(limit=1):
         tag = Tag()
         tag.agent = [agent_foobar]
         tag.tag = "foo123"
         db.session.add(tag)
         db.session.commit()
         self.assertEqual(tag.tag, "foo123")
示例#5
0
 def test_tags_validation(self):
     for agent_foobar in self.models(limit=1):
         tag = Tag()
         tag.agent = [agent_foobar]
         tag.tag = "foo123"
         db.session.add(tag)
         db.session.commit()
         self.assertEqual(tag.tag, "foo123")
示例#6
0
    def test_tags_validation_error(self):
        for agent_foobar in self.models(limit=1):
            tag = Tag()
            tag.agents = [agent_foobar]
            tag.tag = None

        with self.assertRaises(DatabaseError):
            db.session.add(tag)
            db.session.commit()
示例#7
0
    def test_tags_validation_error(self):
        for agent_foobar in self.models(limit=1):
            tag = Tag()
            tag.agents = [agent_foobar]
            tag.tag = None

        with self.assertRaises(DatabaseError):
            db.session.add(tag)
            db.session.commit()
    def test_null(self):
        with self.assertRaises(DatabaseError):
            model = Tag()
            db.session.add(model)
            db.session.commit()

        db.session.remove()

        with self.assertRaises(DatabaseError):
            tag = Tag()
            tag.tag = "foo789"
            db.session.add(model)
            db.session.commit()
示例#9
0
    def test_tags(self):
        for agent_foobar in self.models(limit=1):
            db.session.add(agent_foobar)

            tags = []
            rand = lambda: uuid.uuid4().hex
            for tag_name in (rand(), rand(), rand()):
                tag = Tag()
                tag.tag = tag_name
                tags.append(tag_name)
                agent_foobar.tags.append(tag)

            db.session.commit()
            agent_id = agent_foobar.id
            db.session.remove()
            agent = Agent.query.filter_by(id=agent_id).first()
            self.assertIsNotNone(agent)
            tags.sort()
            agent_tags = list(str(tag.tag) for tag in agent.tags)
            agent_tags.sort()
            self.assertListEqual(agent_tags, tags)
示例#10
0
    def test_tags(self):
        for agent_foobar in self.models(limit=1):
            db.session.add(agent_foobar)

            tags = []
            rand = lambda: uuid.uuid4().hex
            for tag_name in (rand(), rand(), rand()):
                tag = Tag()
                tag.tag = tag_name
                tags.append(tag_name)
                agent_foobar.tags.append(tag)

            db.session.commit()
            agent_id = agent_foobar.id
            db.session.remove()
            agent = Agent.query.filter_by(id=agent_id).first()
            self.assertIsNotNone(agent)
            tags.sort()
            agent_tags = list(str(tag.tag) for tag in agent.tags)
            agent_tags.sort()
            self.assertListEqual(agent_tags, tags)