コード例 #1
0
    def test_toTimeOtherUnits(self):
        q = query.Query(_PROJECT_ID, timeUnit=TimeUnit.MICROSECONDS)
        ret = q.toTime(5500)
        self.assertEqual(5, q.getParams()["to"])
        self.assertEqual(q, ret)

        q = query.Query(_PROJECT_ID, timeUnit=TimeUnit.SECONDS)
        ret = q.toTime(5)
        self.assertEqual(5000, q.getParams()["to"])
        self.assertEqual(q, ret)
コード例 #2
0
 def test_constructorInvalidTimeUnit(self):
     tu = "fake"
     try:
         q = query.Query(_PROJECT_ID, timeUnit=tu)
         self.assertTrue(False)
     except ValueError:
         self.assertTrue(True)
コード例 #3
0
    def test_getUrl(self):
        def shouldFmt(pid, did, series):
            return "{}/{}/{}".format(pid, did, series)

        ALL = "all"
        q = query.Query(_PROJECT_ID)
        self.assertEqual(shouldFmt(_PROJECT_ID, ALL, ALL), q.getUrl())

        q = query.Query(_PROJECT_ID, deviceId=_DEVICE_ID)
        self.assertEqual(shouldFmt(_PROJECT_ID, _DEVICE_ID, ALL), q.getUrl())

        q = query.Query(_PROJECT_ID, seriesName=_SERIES)
        self.assertEqual(shouldFmt(_PROJECT_ID, ALL, _SERIES), q.getUrl())

        q = query.Query(_PROJECT_ID, deviceId=_DEVICE_ID, seriesName=_SERIES)
        self.assertEqual(shouldFmt(_PROJECT_ID, _DEVICE_ID, _SERIES),
                         q.getUrl())
コード例 #4
0
 def test_constructorWithTimeUnit(self):
     tu = query.TimeUnit.SECONDS
     q = query.Query(_PROJECT_ID, timeUnit=tu)
     self.assertEqual(_PROJECT_ID, q._pid)
     self.assertTrue(q._did is None)
     self.assertTrue(q._series is None)
     self.assertEqual(1, len(q.getParams()))
     self.assertTrue("timefmt" in q.getParams())
     self.assertEqual(tu.value, q.getParams()["timefmt"])
コード例 #5
0
    def test_equals(self):
        q = query.Query(_PROJECT_ID)
        self.paramNoneTest(q, q.equals)

        ret = q.equals(10)
        self.assertEqual(10, q.getParams()["equals"])
        self.assertEqual(q, ret)

        # Failure case: non-int
        self._checkInvalid(q.equals, "junk")
コード例 #6
0
    def test_lessThan(self):
        q = query.Query(_PROJECT_ID)
        self.paramNoneTest(q, q.lessThan)

        ret = q.lessThan(1000)
        self.assertEqual(1000, q.getParams()["less_than"])
        self.assertEqual(q, ret)

        # Failure case: non-int
        self._checkInvalid(q.lessThan, "junk")
コード例 #7
0
    def test_greaterThan(self):
        q = query.Query(_PROJECT_ID)
        self.paramNoneTest(q, q.greaterThan)

        ret = q.greaterThan(0)
        self.assertEqual(0, q.getParams()["greater_than"])
        self.assertEqual(q, ret)

        # Failure case: non-int
        self._checkInvalid(q.greaterThan, "junk")
コード例 #8
0
    def test_toTime(self):
        q = query.Query(_PROJECT_ID)
        self.paramNoneTest(q, q.toTime)

        ret = q.toTime(15000)
        self.assertEqual(15000, q.getParams()["to"])
        self.assertEqual(q, ret)

        # Failure case: non-int
        self._checkInvalid(q.toTime, "junk")
コード例 #9
0
    def test_limit(self):
        q = query.Query(_PROJECT_ID)
        self.paramNoneTest(q, q.limit)

        ret = q.limit(5)
        self.assertEqual(5, q.getParams()["limit"])
        self.assertEqual(q, ret)

        # Failure case: non-int
        self._checkInvalid(q.limit, "junk")
        # Failure cases: non-positive int
        self._checkInvalid(q.limit, 0)
        self._checkInvalid(q.limit, -1)
コード例 #10
0
    def test_inValueRange(self):
        q = query.Query(_PROJECT_ID)
        ret = q.inValueRange(None, None)
        self.assertEqual(0, len(q.getParams()))
        self.assertEqual(q, ret)

        ret = q.inValueRange(0, 123)
        self.assertEqual(2, len(q.getParams()))
        self.assertEqual(0, q.getParams()["greater_than"])
        self.assertEqual(123, q.getParams()["less_than"])

        # Failure case: non-int for either/both
        self._checkInvalid(q.inValueRange, "junk", 500)
        self._checkInvalid(q.inValueRange, 0, "junk")
        self._checkInvalid(q.inValueRange, "junk", "junk2")
        # Failure case: end < start
        self._checkInvalid(q.inValueRange, 500, 0)
コード例 #11
0
 def verify(badId, msg):
     try:
         q = query.Query(badId)
         self.assertTrue(False)
     except ValueError as e:
         self.assertEqual(msg, str(e))
コード例 #12
0
 def test_constructorOnlyProject(self):
     q = query.Query(_PROJECT_ID)
     self.assertEqual(_PROJECT_ID, q._pid)
     self.assertTrue(q._did is None)
     self.assertTrue(q._series is None)
     self.assertEqual(0, len(q._params))