feat: household recording destinations and verified Baidu segment archive
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import json
|
||||
import time
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
import test_households as fixtures
|
||||
|
||||
app=fixtures.app
|
||||
|
||||
|
||||
class LocationTests(unittest.TestCase):
|
||||
setUp=fixtures.HouseholdTests.setUp
|
||||
stop_server=fixtures.HouseholdTests.stop_server
|
||||
|
||||
def paired(self):
|
||||
code=app.LOCATIONS.manage(self.owner,dict(action='pair',consent=True,days=1))['code']
|
||||
grant=app.LOCATIONS.pair(dict(code=code),'fixture')
|
||||
app.LOCATIONS.native(grant['token'],dict(action='start',consent=True))
|
||||
app.LOCATIONS.latest[self.owner['id']]['seen']=0
|
||||
return grant['token']
|
||||
|
||||
def test_explicit_two_stage_consent(self):
|
||||
with self.assertRaises(app.Problem):app.LOCATIONS.manage(self.owner,dict(action='pair'))
|
||||
code=app.LOCATIONS.manage(self.owner,dict(action='pair',consent=True))['code']
|
||||
g=app.LOCATIONS.pair(dict(code=code),'fixture')
|
||||
self.assertEqual(app.LOCATIONS.listing(self.aid),[])
|
||||
with self.assertRaises(app.Problem):app.LOCATIONS.native(g['token'],dict(action='start'))
|
||||
with self.assertRaises(app.Problem):app.LOCATIONS.pair(dict(code=code),'fixture')
|
||||
|
||||
def test_scope_and_no_coordinate_persistence(self):
|
||||
token=self.paired()
|
||||
app.LOCATIONS.native(token,dict(action='update',signal='available',position=dict(latitude=36.61,longitude=117.1,accuracy=9,at=time.time())))
|
||||
self.assertEqual(app.LOCATIONS.listing(self.aid)[0]['status'],'live')
|
||||
self.assertEqual(app.LOCATIONS.listing(self.bid),[])
|
||||
self.assertNotIn('36.61','\n'.join(app.DB.iterdump()))
|
||||
self.assertNotIn(token,'\n'.join(app.DB.iterdump()))
|
||||
with self.assertRaises(app.Problem):app.LOCATIONS.manage(self.roots[self.bid],dict(action='pair',consent=True))
|
||||
|
||||
def test_stop_clears_and_revokes(self):
|
||||
token=self.paired();app.LOCATIONS.manage(self.owner,dict(action='stop'))
|
||||
self.assertNotIn(self.owner['id'],app.LOCATIONS.latest)
|
||||
with self.assertRaises(app.Problem):app.LOCATIONS.native(token,dict(action='update'))
|
||||
|
||||
def test_stale_and_disabled_user(self):
|
||||
token=self.paired()
|
||||
app.LOCATIONS.latest[self.owner['id']]['started']=time.time()-901
|
||||
self.assertEqual(app.LOCATIONS.listing(self.aid)[0]['status'],'stale')
|
||||
user=app.get_object('users',self.owner['id']);user['disabled']=True;app.save_object('users',user)
|
||||
self.assertEqual(app.LOCATIONS.listing(self.aid),[])
|
||||
with self.assertRaises(app.Problem):app.LOCATIONS.native(token,dict(action='update'))
|
||||
|
||||
def test_invalid_fix_rejected(self):
|
||||
token=self.paired()
|
||||
for lat in (True,float('nan'),91):
|
||||
with self.assertRaises(app.Problem):app.LOCATIONS.native(token,dict(action='update',position=dict(latitude=lat,longitude=1,accuracy=1,at=time.time())))
|
||||
|
||||
|
||||
if __name__=='__main__':unittest.main()
|
||||
Reference in New Issue
Block a user