def setUp(self):
     get_client_stats_db().remove()
     get_server_stats_db().remove()
     get_result_stats_db().remove()
     self.testInputJSON = \
       {'Metadata': {'client_app_version': '2.0.1',
                     'client_os_version': '4.3'},
        'Readings': {'sync_pull_list_size': [[1411418998701, 1111], [1411418998702, 2222], [1411418998703, 3333]],
                  'battery_level': [[1411418998704, 4444], [1411418998705, 5555], [1411418998706, 6666]],
                 }}
 def testStoreClientEntry(self):
     currTime = time.time()
     self.assertEqual(get_client_stats_db().find().count(), 0)
     stats.storeClientEntry("testuser", "testfield", currTime, 0.002,
                            {'metadata_key': "metadata_val"})
     self.assertEqual(get_client_stats_db().find().count(), 1)
     self.assertEqual(
         get_client_stats_db().find({
             'user': '******'
         }).count(), 1)
     self.assertEqual(get_client_stats_db().find({
         'ts': currTime
     }).count(), 1)
 def testSetClientMeasurements(self):
     currTime = time.time()
     stats.setClientMeasurements("testUser", self.testInputJSON)
     for savedEntry in get_client_stats_db().find():
         self.assertEquals(savedEntry['client_app_version'], '2.0.1')
         self.assertEquals(savedEntry['client_os_version'], '4.3')
         self.assertAlmostEqual(savedEntry['reported_ts'],
                                time.time(),
                                places=0)
         if savedEntry['stat'] == 'sync_pull_list_size':
             self.assertIn(savedEntry['ts'],
                           [1411418998701, 1411418998702, 1411418998703])
             self.assertIn(savedEntry['reading'], [1111, 2222, 3333])
 def tearDown(self):
     get_client_stats_db().remove()
     pass
Exemple #5
0
def storeClientEntry(user, key, ts, reading, metadata):
  logging.debug("storing client entry for user %s, key %s at timestamp %s" % (user, key, ts))
  currEntry = createEntry(user, key, ts, reading)
  # Add the os and app versions from the metadata dict
  currEntry.update(metadata)
  get_client_stats_db().insert(currEntry)