def testExport(self): # Create game backend = content.Content() theAnalytics = analytics.Analytics() session = content.models.getSession() a = backend.addApplication('Export Data Game') for i in range(10): update = { 'liftpass-application': a.key, 'liftpass-ip': '', 'user': '******' * 32, 'events': [{ 'name': 'liftpass-metric', 'progress': [None] * 32, 'time': extras.unixTimestamp() }] * 5 } theAnalytics.processUpdate(update, session) query = { 'application': a.key, 'from': extras.unixTimestamp() - 86400, 'to': extras.unixTimestamp() + 86400, } (status, a) = self.request('GET', '/export/json/v1/', query, raw=True) self.assertEqual(len(a.split('\n')), 51)
def testExport(self): # Create game backend = content.Content() theAnalytics = analytics.Analytics() session = content.models.getSession() a = backend.addApplication('Export Data Game') for i in range(10): update = { 'liftpass-application': a.key, 'liftpass-ip': '', 'user': '******'*32, 'events':[ { 'name': 'liftpass-metric', 'progress': [None]*32, 'time': extras.unixTimestamp() } ]*5 } theAnalytics.processUpdate(update, session) query = { 'application': a.key, 'from': extras.unixTimestamp()-86400, 'to': extras.unixTimestamp()+86400, } (status, a) = self.request('GET', '/export/json/v1/', query, raw=True) self.assertEqual(len(a.split('\n')), 51)
def testMissingEventMetrics(self): update = { 'name': 'liftpass-metric', 'progress': [None]*23, 'time': extras.unixTimestamp(), } with self.assertRaises(analytics.EventMissingMetricError): event = analytics.Analytics().processEvent(None, None, None, None, update) update = { 'name': 'liftpass-metric', 'time': extras.unixTimestamp(), } with self.assertRaises(analytics.EventAttributeMissingError): event = analytics.Analytics().processEvent(None, None, None, None, update)
def testLog(self): backend = content.Content() a = backend.addApplication('Test SDK') jsonPricesA = backend.addPrices(a.key, 'JSON', json.dumps({'sword':1000}), None) jsonPricesB = backend.addPrices(a.key, 'JSON', json.dumps({'sword':2000}), None) backend.setABTest(a.key, {'groupAPrices_key': jsonPricesA.key}) backend.setABTest(a.key, {'groupBPrices_key': jsonPricesB.key}) data = { 'user': '******'*32, 'liftpass-debug': True, 'events': [ { 'name': 'liftpass-metric', 'progress': ['','','','','','','','']+[0]*32, 'time': extras.unixTimestamp() } ] } (status, b) = self.request('POST', '/sdk/update/v1/', data, application=a) theTerminal = terminal.getTerminal() res = theTerminal.get(a.key) self.assertEqual(len(res), 2)
def testLog(self): backend = content.Content() a = backend.addApplication('Test SDK') jsonPricesA = backend.addPrices(a.key, 'JSON', json.dumps({'sword': 1000}), None) jsonPricesB = backend.addPrices(a.key, 'JSON', json.dumps({'sword': 2000}), None) backend.setABTest(a.key, {'groupAPrices_key': jsonPricesA.key}) backend.setABTest(a.key, {'groupBPrices_key': jsonPricesB.key}) data = { 'user': '******' * 32, 'liftpass-debug': True, 'events': [{ 'name': 'liftpass-metric', 'progress': ['', '', '', '', '', '', '', ''] + [0] * 32, 'time': extras.unixTimestamp() }] } (status, b) = self.request('POST', '/sdk/update/v1/', data, application=a) theTerminal = terminal.getTerminal() res = theTerminal.get(a.key) self.assertEqual(len(res), 3)
def testCall(self): backend = content.Content() a = backend.addApplication('Test SDK') jsonPricesA = backend.addPrices(a.key, 'JSON', json.dumps({'sword':1000}), None) jsonPricesB = backend.addPrices(a.key, 'JSON', json.dumps({'sword':2000}), None) backend.setABTest(a.key, {'groupAPrices_key': jsonPricesA.key}) backend.setABTest(a.key, {'groupBPrices_key': jsonPricesB.key}) data = { 'user': '******'*32, 'events': [ { 'name': 'liftpass-metric', 'progress': ['','','','','','','','']+[0]*24, 'time': extras.unixTimestamp() } ] } (status, b) = self.request('POST', '/sdk/update/v1/', data, application=a) self.assertEqual(b['goods']['sword'][0], 1000) data['user'] = '******'*32 (status, c) = self.request('POST', '/sdk/update/v1/', data, application=a) self.assertEqual(c['goods']['sword'][0], 2000)
def testCall(self): backend = content.Content() a = backend.addApplication('Test SDK') jsonPricesA = backend.addPrices(a.key, 'JSON', json.dumps({'sword': 1000}), None) jsonPricesB = backend.addPrices(a.key, 'JSON', json.dumps({'sword': 2000}), None) backend.setABTest(a.key, {'groupAPrices_key': jsonPricesA.key}) backend.setABTest(a.key, {'groupBPrices_key': jsonPricesB.key}) data = { 'user': '******' * 32, 'events': [{ 'name': 'liftpass-metric', 'progress': ['', '', '', '', '', '', '', ''] + [0] * 24, 'time': extras.unixTimestamp() }] } (status, b) = self.request('POST', '/sdk/update/v1/', data, application=a) self.assertEqual(b['goods']['sword'][0], 1000) data['user'] = '******' * 32 (status, c) = self.request('POST', '/sdk/update/v1/', data, application=a) self.assertEqual(c['goods']['sword'][0], 2000)
def testNormalUpdate(self): update = { 'name': 'liftpass-metric', 'progress': [], 'time': extras.unixTimestamp(), } for i in range(8): update['progress'].append(extras.genRandomStrings(1, 12)[0]) for i in range(24): update['progress'].append(random.random()) event = analytics.Analytics().processEvent(None, None, None, None, update) self.assertEqual(event['name'], update['name']) self.assertEqual(event['timestamp'], datetime.datetime.utcfromtimestamp(update['time'])) for i in range(8): self.assertEqual(event['metricString%d' % (i + 1)], update['progress'][i]) for i in range(24): self.assertEqual(event['metricNumber%d' % (i + 1)], update['progress'][8 + i])
def testMissingEventName(self): update = { 'progress': [None] * 23, 'time': extras.unixTimestamp(), } with self.assertRaises(analytics.EventAttributeMissingError): event = analytics.Analytics().processEvent(None, None, None, None, update)
def testMissingAttribute(self): update = { 'name': 'liftpass-metric', 'progress': [None] * 32, 'attributes': [None] * 12, 'time': extras.unixTimestamp(), } with self.assertRaises(analytics.EventMissingAttributeError): event = analytics.Analytics().processEvent(None, None, None, None, update)
def testNullMetrics(self): update = { 'name': 'liftpass-metric', 'progress': [None]*32, 'time': extras.unixTimestamp(), } event = analytics.Analytics().processEvent(None, None, None, None, update) for i in range(8): self.assertEqual(event['metricString%d'%(i+1)], update['progress'][i]) for i in range(24): self.assertEqual(event['metricNumber%d'%(i+1)], update['progress'][8+i])
def makeProgress(length): progress = ['','','','','','','','']+[0]*24 res = [] for i in range(length): progress[random.randint(8, 31)] += 1 res.append({ 'name': 'liftpass-metric', 'progress': progress[:], 'time': extras.unixTimestamp()+i }) return res
def testNullMetrics(self): update = { 'name': 'liftpass-metric', 'progress': [None] * 32, 'time': extras.unixTimestamp(), } event = analytics.Analytics().processEvent(None, None, None, None, update) for i in range(8): self.assertEqual(event['metricString%d' % (i + 1)], update['progress'][i]) for i in range(24): self.assertEqual(event['metricNumber%d' % (i + 1)], update['progress'][8 + i])
def makeRequest(*args, **kwargs): global api, application data = { 'user': '******'*32, 'events': [ { 'name': 'liftpass-metric', 'progress': ['','','','','','','','']+[0]*24, 'time': extras.unixTimestamp() } ] } start = time.time() (status, b) = api.request('POST', '/sdk/update/v1/', data, application=application) data['user'] = '******'*32 (status, c) = api.request('POST', '/sdk/update/v1/', data, application=application) return time.time() - start
def testNormalUpdate(self): update = { 'name': 'liftpass-metric', 'progress': [], 'time': extras.unixTimestamp(), } for i in range(8): update['progress'].append(extras.genRandomStrings(1, 12)[0]) for i in range(24): update['progress'].append(random.random()) event = analytics.Analytics().processEvent(None, None, None, None, update) self.assertEqual(event['name'], update['name']) self.assertEqual(event['timestamp'], datetime.datetime.utcfromtimestamp(update['time'])) for i in range(8): self.assertEqual(event['metricString%d'%(i+1)], update['progress'][i]) for i in range(24): self.assertEqual(event['metricNumber%d'%(i+1)], update['progress'][8+i])