def stop_session(self): """ Stops the current session :returns: nothing """ self.__data.set("session_" + str(self.session_id) + "_end", blitz_timestamp()) self.session_id = -1 self.__last_session_length = -1
def start_session(self): """ Starts a new session, creating the required session_N variables :returns: the ID of the newly created session """ self.__data.incr("session_id") self.session_id = self.__get_session_id() self.__data.lpush("sessions", self.session_id) self.__data.set("session_" + str(self.session_id) + "_start", blitz_timestamp()) self.__last_session_length = -1 return self.__get_session_id()
def test_add_reading(self): session_id = 1 timeLogged = blitz_timestamp() category_id = 1 value = 5.2 reading = self.db.add_reading(session_id, timeLogged, category_id, value) result = self.db.get_by_id(Reading, reading.id) assert result.sessionId == session_id, "Expected %s got %s" % (result.sessionId, session_id) assert result.timeLogged == timeLogged, "Expected %s got %s" % (result.timeLogged, timeLogged) assert result.categoryId == category_id, "Expected %s got %s" % (result.categoryId, category_id) assert result.value == str(value), "Expected %s got %s" % (result.value, value)
def test_add_cache(self): timeLogged = blitz_timestamp() category_id = 1 value = 5.2 cache = self.db.add_cache(timeLogged, category_id, value) result = self.db.get_by_id(Cache, cache.id) assert result.timeLogged == timeLogged, "Expected %s got %s" % (result.timeLogged, timeLogged) assert result.categoryId == category_id, "Expected %s got %s" % (result.categoryId, category_id) assert result.value == str(value), "Expected %s got %s" % (result.value, value) self.db.clear_cache() cached = self.db.all(Cache) assert len(cached) == 0, "Expected 0 cached items, found %s" % len(cached)
def log_error(self, description, severity=1): """ Log an error to the database - this will be sent to the client :param description: the description of the error :param severity: the severity of the error (defaults to 1) :returns: the Notification that was added """ notification = Notification( timeLogged=blitz_timestamp(), severity=severity, description=description ) self.add(notification) return notification
def test_add_reading(self): session_id = 1 timeLogged = blitz_timestamp() category_id = 1 value = 5.2 reading = self.db.add_reading(session_id, timeLogged, category_id, value) result = self.db.get_by_id(Reading, reading.id) assert result.sessionId == session_id, "Expected %s got %s" % ( result.sessionId, session_id) assert result.timeLogged == timeLogged, "Expected %s got %s" % ( result.timeLogged, timeLogged) assert result.categoryId == category_id, "Expected %s got %s" % ( result.categoryId, category_id) assert result.value == str( value), "Expected %s got %s" % (result.value, value)
def test_add_cache(self): timeLogged = blitz_timestamp() category_id = 1 value = 5.2 cache = self.db.add_cache(timeLogged, category_id, value) result = self.db.get_by_id(Cache, cache.id) assert result.timeLogged == timeLogged, "Expected %s got %s" % ( result.timeLogged, timeLogged) assert result.categoryId == category_id, "Expected %s got %s" % ( result.categoryId, category_id) assert result.value == str( value), "Expected %s got %s" % (result.value, value) self.db.clear_cache() cached = self.db.all(Cache) assert len( cached) == 0, "Expected 0 cached items, found %s" % len(cached)
def test_add_one_record(self): c = Cache(timeLogged=blitz_timestamp(), categoryId=1, value=3) res = self.db.add(c) assert type(res) == Cache assert res.id == 1
__author__ = 'Will Hart' from blitz.communications.tcp import TcpBase from blitz.utilities import blitz_timestamp time0 = blitz_timestamp() time1 = time0 - 1 time2 = time0 - 2 time3 = time0 - 3 time4 = time0 - 4 time5 = time0 - 5 time6 = time0 - 6 READING_FIXTURES = [ {"sessionId": 1, "timeLogged": time3, "categoryId": 1, "value": 3.75}, {"sessionId": 1, "timeLogged": time2, "categoryId": 1, "value": 9.12}, {"sessionId": 1, "timeLogged": time4, "categoryId": 1, "value": 7.56}, {"sessionId": 1, "timeLogged": time1, "categoryId": 2, "value": 5.2}, {"sessionId": 1, "timeLogged": time0, "categoryId": 2, "value": 4.3}, {"sessionId": 1, "timeLogged": time5, "categoryId": 2, "value": 1.23} ] CACHE_FIXTURES = [ {"timeLogged": time3, "categoryId": 1, "value": 3.75}, {"timeLogged": time2, "categoryId": 1, "value": 9.12}, {"timeLogged": time4, "categoryId": 1, "value": 7.56}, {"timeLogged": time1, "categoryId": 2, "value": 5.2}, {"timeLogged": time0, "categoryId": 2, "value": 4.3}, {"timeLogged": time5, "categoryId": 2, "value": 1.23} ]
__author__ = 'Will Hart' from blitz.communications.tcp import TcpBase from blitz.utilities import blitz_timestamp time0 = blitz_timestamp() time1 = time0 - 1 time2 = time0 - 2 time3 = time0 - 3 time4 = time0 - 4 time5 = time0 - 5 time6 = time0 - 6 READING_FIXTURES = [{ "sessionId": 1, "timeLogged": time3, "categoryId": 1, "value": 3.75 }, { "sessionId": 1, "timeLogged": time2, "categoryId": 1, "value": 9.12 }, { "sessionId": 1, "timeLogged": time4, "categoryId": 1, "value": 7.56 }, { "sessionId": 1, "timeLogged": time1,