Пример #1
0
 def test_get_entries_newer_than_25_days(self):
     with test_database(test_db, (Log, Topic), create_tables=True):
         self.msg.topic = Settings.ROOT_TOPIC + '/log/days'
         Log.create(timestamp=datetime.now() - timedelta(days=30), value="12", topic='/test/topic')
         Log.create(timestamp=datetime.now() - timedelta(days=20), value="12", topic='/test/topic2')
         Log.create(timestamp=datetime.now() - timedelta(days=20), value="12", topic='/test/topic')
         Log.create(timestamp=datetime.now() - timedelta(days=10), value="12", topic='/test/topic')
         logs = LogController()
         query_result = logs.get_topic_entries(self.msg)
         dic_result = json.loads(query_result)
         self.assertEqual(2, len(dic_result['values']))
Пример #2
0
 def test_get_last_entry_from_topic(self):
     with test_database(test_db, (Log, Topic), create_tables=True):
         self.msg.topic = Settings.ROOT_TOPIC + '/log/last'
         Log.create(timestamp=datetime.now() - timedelta(seconds=30), value="12", topic='/test/topic')
         Log.create(timestamp=datetime.now() - timedelta(seconds=20), value="12", topic='/test/topic2')
         Log.create(timestamp=datetime.now() - timedelta(seconds=20), value="12", topic='/test/topic')
         timestamp = datetime.now()
         Log.create(timestamp=timestamp, value="12", topic='/test/topic')
         logs = LogController()
         query_result = logs.get_topic_entries(self.msg)
         dic_result = json.loads(query_result)
         self.assertEqual(timestamp.strftime("%Y-%m-%d %H:%M:%S"), dic_result['values'][0]['timestamp'])
Пример #3
0
 def test_get_entries_newer_than_25_days_invalid_topic(self):
     with test_database(test_db, (Log, Topic), create_tables=True):
         self.msg.topic = Settings.ROOT_TOPIC + '/log/days'
         self.payload['topic'] = '/test/invalid/topic'
         self.msg.payload = json.dumps(self.payload)
         Log.create(timestamp=datetime.now() - timedelta(days=30), value="12", topic='/test/topic')
         Log.create(timestamp=datetime.now() - timedelta(days=20), value="12", topic='/test/topic2')
         Log.create(timestamp=datetime.now() - timedelta(days=20), value="12", topic='/test/topic')
         Log.create(timestamp=datetime.now() - timedelta(days=10), value="12", topic='/test/topic')
         logs = LogController()
         query_result = logs.get_topic_entries(self.msg)
         dic_result = json.loads(query_result)
         self.assertEqual('OK', dic_result['result'])
         self.assertFalse('values' in dic_result)