def create_user_agents(self): user_agent_string = "" hash = utils.compute_text_md5(user_agent_string) user_agent = UserAgentEntity.create(user_agent=user_agent_string, hash=hash, platform="Linux", browser="Firefox", version="latest", language="EN-US") self.assertIsNotNone(user_agent)
def get_user_agent(): """Find an existing user agent or insert a new one""" # The raw user agent string received from the browser uag = request.user_agent hash = utils.compute_text_md5(uag.string) # The entity representing the user agent user_agent = UserAgentEntity.get_by_hash(hash) if user_agent is None: platform = uag.platform if uag.platform is not None else '' browser = uag.browser if uag.browser is not None else '' version = uag.version if uag.version is not None else '' language = uag.language if uag.language is not None else '' user_agent = UserAgentEntity.create(user_agent=uag.string, hash=hash, platform=platform, browser=browser, version=version, language=language) return user_agent
def test_log_creation(self): """ Test CRUD operations """ # LogType log_login = LogTypeEntity.create(type=LOG_TYPE_LOGIN, description='') log_logout = LogTypeEntity.create(type=LOG_TYPE_LOGOUT, description='') self.assertEquals(1, log_login.id) self.assertEquals(2, log_logout.id) # UserAgent user_agent_string = "Long text..." hash = compute_text_md5(user_agent_string) user_agent = UserAgentEntity.create(user_agent=user_agent_string, hash=hash, platform="Linux", browser="Firefox", version="latest", language="EN-US") # print(user_agent) self.assertEquals(1, user_agent.id) self.assertEquals("467ffa17419afeffe09bb98af4828a30", user_agent.hash) self.assertEquals("Linux", user_agent.platform) self.assertEquals("latest", user_agent.version) self.assertEquals("EN-US", user_agent.language) # WebSession web_session = WebSessionEntity.create(user_agent_id=user_agent.id) self.assertEquals(1, web_session.id) self.assertEquals(user_agent, web_session.user_agent) # print(web_session.user_agent) # Log log = LogEntity.create(type_id=log_login.id, web_session_id=web_session.id, date_time=datetime.now(), details='just a test') log2 = LogEntity.create(type_id=log_logout.id, web_session_id=web_session.id, date_time=datetime.now(), details='just a test') self.assertEquals(1, log.id) self.assertEquals(2, log2.id) self.assertEquals(LOG_TYPE_LOGIN, log.log_type.type) self.assertEquals(LOG_TYPE_LOGOUT, log2.log_type.type)