Beispiel #1
0
 def test_is_delayed(self):
     sub = submission.Submission("abc", "SPARK")
     self.assertEqual(sub.is_delayed(), False)
     sub = submission.Submission("abc",
                                 "SPARK",
                                 delay=const.SUBMISSION_DELAY_MIN)
     self.assertEqual(sub.is_delayed(), False)
     sub = submission.Submission("abc",
                                 "SPARK",
                                 delay=const.SUBMISSION_DELAY_MAX)
     self.assertEqual(sub.is_delayed(), True)
Beispiel #2
0
 def test_set_status(self):
     sub = submission.Submission("abc", "SPARK")
     self.assertEqual(sub.status, const.SUBMISSION_PENDING)
     sub.set_status(const.SUBMISSION_RUNNING)
     self.assertEqual(sub.status, const.SUBMISSION_RUNNING)
     with self.assertRaises(ValueError):
         sub.set_status(None)
Beispiel #3
0
 def test_init_simple(self):
     with self.assertRaises(ValueError):
         submission.Submission("", "")
     # simple init
     sub = submission.Submission("abc", "SPARK")
     self.assertNotEqual(sub.uid, None)
     self.assertEqual(sub.name, "abc")
     self.assertEqual(sub.system_code, "SPARK")
     self.assertEqual(sub.priority, const.PRIORITY_2)
     self.assertEqual(sub.is_deleted, False)
     self.assertEqual(sub.is_template, False)
     self.assertEqual(sub.status, const.SUBMISSION_PENDING)
     self.assertNotEqual(sub.createtime, None)
     self.assertNotEqual(sub.submittime, None)
     self.assertEqual(sub.starttime, None)
     self.assertEqual(sub.finishtime, None)
     self.assertEqual(sub.payload, {})
     self.assertEqual(sub.username, "default")
Beispiel #4
0
def test_binorder():
    """
    Test if order returned while get_X-ing is correct
    """

    for csv in CSVS:
        week53 = csv.name.startswith("week53")
        s = sub.Submission(csv=csv)
        for region in sub.MAP_REGION:
            for target in sub.MAP_TARGET:
                _, bin_order = s.get_X(region, target)
                assert np.allclose(bin_order,
                                   get_expected_bin_order(target, week53),
                                   equal_nan=True)
Beispiel #5
0
 def test_dumps_loads(self):
     sub1 = submission.Submission("abc",
                                  "SPARK",
                                  priority=const.PRIORITY_0,
                                  delay=30,
                                  payload={"a": 1})
     sub2 = submission.Submission.loads(sub1.dumps())
     self.assertEqual(sub2.uid, sub1.uid)
     self.assertEqual(sub2.name, sub1.name)
     self.assertEqual(sub2.system_code, sub1.system_code)
     self.assertEqual(sub2.priority, sub1.priority)
     self.assertEqual(sub2.is_deleted, sub1.is_deleted)
     self.assertEqual(sub2.is_template, sub1.is_template)
     self.assertEqual(sub2.status, sub1.status)
     self.assertEqual(sub2.createtime, sub1.createtime)
     self.assertEqual(sub2.submittime, sub1.submittime)
     self.assertEqual(sub2.starttime, sub1.starttime)
     self.assertEqual(sub2.finishtime, sub1.finishtime)
     self.assertEqual(sub2.payload, sub1.payload)
     self.assertEqual(sub2.username, sub1.username)
Beispiel #6
0
    def PUT(self):
        """
        Create submission out of request JSON. This forces certain fields to exist in JSON.
        - name (string) - submission name
        - code (string) - session code to handle
        - priority (int) - priority for the submission, currently defaults to PRIORITY_2.
        - delay (int) - delay in seconds, defaults to 0 seconds
        - payload (dict) - payload to create task, defaults to '{...}'

        Field validation is done in submission and task, this method only validates existence of
        menitoned above fields. Current logic is that submission + task are created, stored in
        database, scheduled if necessary, and result is returned.
        """
        data = cherrypy.request.json
        # Validate keys
        if "name" not in data:
            raise KeyError("Expected required field 'name' from %s" % data)
        if "code" not in data:
            raise KeyError("Expected required field 'code' from %s" % data)
        name = data["name"]
        system_code = data["code"]
        pr = util.safe_int(
            data["priority"],
            fail=True) if "priority" in data else const.PRIORITY_2
        delay = util.safe_int(data["delay"],
                              fail=True) if "delay" in data else 0
        payload = util.safe_dict(data["payload"],
                                 fail=True) if "payload" in data else {}
        username = None
        sub = submission.Submission(name,
                                    system_code,
                                    priority=pr,
                                    delay=delay,
                                    payload=payload,
                                    username=username)
        task = self.session.create_task(sub)
        cherrypy.engine.publish(EVENT_CREATE, sub, task)
        return {"uid": sub.uid, "msg": "Submission created"}
Beispiel #7
0
 def test_init_delayed(self):
     sub = submission.Submission("abc", "SPARK", delay=30)
     self.assertTrue((sub.submittime - sub.createtime).total_seconds >= 30)
     self.assertEqual(sub.is_delayed(), True)
Beispiel #8
0
 def test_mark_deleted(self):
     sub = submission.Submission("abc", "SPARK")
     self.assertEqual(sub.is_deleted, False)
     sub.mark_deleted()
     self.assertEqual(sub.is_deleted, True)
Beispiel #9
0
 def test_mark_finish(self):
     sub = submission.Submission("abc", "SPARK")
     self.assertEqual(sub.finishtime, None)
     sub.mark_finish()
     self.assertNotEqual(sub.finishtime, None)
     self.assertTrue((sub.finishtime - sub.createtime).total_seconds() >= 0)