Ejemplo n.º 1
0
  def setUp(self):
    self.testUsers = ["*****@*****.**", "*****@*****.**", "*****@*****.**",
                      "*****@*****.**", "*****@*****.**"]
    self.serverName = 'localhost'

    # Sometimes, we may have entries left behind in the database if one of the tests failed
    # or threw an exception, so let us start by cleaning up all entries
    tests.common.dropAllCollections(get_db())
    self.ModesColl = get_mode_db()
    # self.ModesColl.remove()
    self.assertEquals(self.ModesColl.find().count(), 0)

    self.SectionsColl = get_section_db()
    # self.SectionsColl.remove()
    self.assertEquals(self.SectionsColl.find().count(), 0)

    load_database_json.loadTable(self.serverName, "Stage_Modes", "tests/data/modes.json")
    load_database_json.loadTable(self.serverName, "Stage_Sections", "tests/data/testCarbonFile")

    # Let's make sure that the users are registered so that they have profiles
    for userEmail in self.testUsers:
      User.register(userEmail)

    self.walkExpect = 1057.2524056424411
    self.busExpect = 2162.668467546699
    self.busCarbon = 267.0/1609

    self.now = datetime.now()
    self.dayago = self.now - timedelta(days=1)
    self.weekago = self.now - timedelta(weeks = 1)
    tests.common.updateSections(self)
Ejemplo n.º 2
0
    def setUp(self):
        self.testUsers = [
            "*****@*****.**", "*****@*****.**", "*****@*****.**",
            "*****@*****.**", "*****@*****.**"
        ]
        self.serverName = 'localhost'

        # Sometimes, we may have entries left behind in the database if one of the tests failed
        # or threw an exception, so let us start by cleaning up all entries
        tests.common.dropAllCollections(get_db())
        self.ModesColl = get_mode_db()
        # self.ModesColl.remove()
        self.assertEquals(self.ModesColl.find().count(), 0)

        self.SectionsColl = get_section_db()
        # self.SectionsColl.remove()
        self.assertEquals(self.SectionsColl.find().count(), 0)

        load_database_json.loadTable(self.serverName, "Stage_Modes",
                                     "tests/data/modes.json")
        load_database_json.loadTable(self.serverName, "Stage_Sections",
                                     "tests/data/testCarbonFile")

        # Let's make sure that the users are registered so that they have profiles
        for userEmail in self.testUsers:
            User.register(userEmail)

        self.walkExpect = 1057.2524056424411
        self.busExpect = 2162.668467546699
        self.busCarbon = 267.0 / 1609

        self.now = datetime.now()
        self.dayago = self.now - timedelta(days=1)
        self.weekago = self.now - timedelta(weeks=1)
        tests.common.updateSections(self)
Ejemplo n.º 3
0
    def testRunBackgroundTasksForDay(self):
        self.testUsers = [
            "*****@*****.**", "*****@*****.**", "*****@*****.**",
            "*****@*****.**", "*****@*****.**"
        ]
        load_database_json.loadTable(self.serverName, "Stage_Modes",
                                     "tests/data/modes.json")
        load_database_json.loadTable(self.serverName, "Stage_Sections",
                                     "tests/data/testCarbonFile")

        # Let's make sure that the users are registered so that they have profiles
        for userEmail in self.testUsers:
            User.register(userEmail)

        self.SectionsColl = get_section_db()
        tests.common.updateSections(self)

        self.assertNotEqual(len(self.uuid_list), 0)
        # Can access the zeroth element because we know that then length is greater than zero
        # (see above)
        test_uuid = self.uuid_list[0]
        test_user = User.fromUUID(test_uuid)
        self.assertNotIn('carbon_footprint', test_user.getProfile().keys())
        default.runBackgroundTasks(test_user.uuid)
        self.assertIn('carbon_footprint', test_user.getProfile().keys())
Ejemplo n.º 4
0
    def setUp(self):
        self.testUsers = [
            "*****@*****.**", "*****@*****.**", "*****@*****.**",
            "*****@*****.**", "*****@*****.**"
        ]
        self.serverName = 'localhost'

        # Sometimes, we may have entries left behind in the database if one of the tests failed
        # or threw an exception, so let us start by cleaning up all entries
        tests.common.dropAllCollections(get_db())

        self.ModesColl = get_mode_db()
        self.assertEquals(self.ModesColl.find().count(), 0)

        self.SectionsColl = get_section_db()
        self.assertEquals(self.SectionsColl.find().count(), 0)

        load_database_json.loadTable(self.serverName, "Stage_Modes",
                                     "tests/data/modes.json")
        load_database_json.loadTable(self.serverName, "Stage_Sections",
                                     "tests/data/testModeInferFile")

        # Let's make sure that the users are registered so that they have profiles
        for userEmail in self.testUsers:
            User.register(userEmail)

        self.now = datetime.now()
        self.dayago = self.now - timedelta(days=1)
        self.weekago = self.now - timedelta(weeks=1)

        for section in self.SectionsColl.find():
            section['section_start_datetime'] = self.dayago
            section['section_end_datetime'] = self.dayago + timedelta(hours=1)
            if (section['confirmed_mode'] == 5):
                # We only cluster bus and train trips
                # And our test data only has bus trips
                section['section_start_point'] = {
                    u'type': u'Point',
                    u'coordinates': [-122.270039042, 37.8800285728]
                }
                section['section_end_point'] = {
                    u'type': u'Point',
                    u'coordinates': [-122.2690412952, 37.8739578595]
                }
            # print("Section start = %s, section end = %s" %
            #   (section['section_start_datetime'], section['section_end_datetime']))
            # Replace the user email with the UUID
            section['user_id'] = User.fromEmail(section['user_id']).uuid
            self.SectionsColl.save(section)

        self.pipeline = pipeline.ModeInferencePipeline()
        self.testLoadTrainingData()
Ejemplo n.º 5
0
    def testChangeUpdateTs(self):
        from datetime import datetime, timedelta

        user = User.register('*****@*****.**')
        self.assertTrue(User.isRegistered('*****@*****.**'))
        user.changeUpdateTs(timedelta(days=-20))
        self.assertEqual((datetime.now() - user.getUpdateTS()).days, 20)
Ejemplo n.º 6
0
    def testUnsetStudyExists(self):
        user = User.register('*****@*****.**')
        user.setStudy('testclient')
        self.assertEquals(userclient.countForStudy('testclient'), 1)

        user.unsetStudy('testclient')
        self.assertEquals(userclient.countForStudy('testclient'), 0)
Ejemplo n.º 7
0
 def setUp(self):
     import tests.common
     # Sometimes, we may have entries left behind in the database if one of the tests failed
     # or threw an exception, so let us start by cleaning up all entries
     tests.common.dropAllCollections(get_db())
     user = User.register("*****@*****.**")
     self.uuid = user.uuid
Ejemplo n.º 8
0
  def testUnsetStudyExists(self):
    user = User.register('*****@*****.**')
    user.setStudy('testclient')
    self.assertEquals(userclient.countForStudy('testclient'), 1)

    user.unsetStudy('testclient')
    self.assertEquals(userclient.countForStudy('testclient'), 0)
Ejemplo n.º 9
0
  def testClientSpecificSettersWithOverride(self):
    from dao.user import User

    fakeEmail = "*****@*****.**"

    client = Client("testclient")
    client.update(createKey = False)
    common.makeValid(client)

    (resultPre, resultReg) = client.preRegister("this_is_the_super_secret_id", fakeEmail)
    studyList = Client.getPendingClientRegs(fakeEmail)
    self.assertEqual(studyList, ["testclient"])

    user = User.register("*****@*****.**")
    self.assertEqual(user.getFirstStudy(), 'testclient')

    dummyPredModeMap = {'walking': 1.0}
    dummySection = common.createDummySection(startTime = datetime.now() - timedelta(seconds = 60 * 60),
        endTime = datetime.now(),
        startLoc = [-122, 34],
        endLoc = [-122, 35],
        predictedMode = dummyPredModeMap)

    clientSetQuery = client.clientSpecificSetters(user.uuid, dummySection['_id'], dummyPredModeMap)
    self.assertEqual(clientSetQuery, {'$set': {'test_auto_confirmed': {'mode': 1, 'prob': 1.0}}})

    # Apply the change
    get_section_db().update({'_id': dummySection['_id']}, clientSetQuery)
    retrievedSection = get_section_db().find_one({'_id': dummySection['_id']})
    self.assertEqual(retrievedSection['test_auto_confirmed']['mode'], 1)
Ejemplo n.º 10
0
  def testChangeUpdateTs(self):
    from datetime import datetime, timedelta

    user = User.register('*****@*****.**')
    self.assertTrue(User.isRegistered('*****@*****.**'))
    user.changeUpdateTs(timedelta(days = -20))
    self.assertEqual((datetime.now() - user.getUpdateTS()).days, 20)
Ejemplo n.º 11
0
  def setupClientTest(self):
    # At this point, the more important test is to execute the query and see
    # how well it works
    from dao.user import User
    from dao.client import Client
    import tests.common
    from get_database import get_section_db

    fakeEmail = "*****@*****.**"

    client = Client("testclient")
    client.update(createKey = False)
    tests.common.makeValid(client)

    (resultPre, resultReg) = client.preRegister("this_is_the_super_secret_id", fakeEmail)
    studyList = Client.getPendingClientRegs(fakeEmail)
    self.assertEqual(studyList, ["testclient"])

    user = User.register("*****@*****.**")
    self.assertEqual(user.getFirstStudy(), 'testclient')

    dummyPredModeMap = {'walking': 1.0}
    dummySection = tests.common.createDummySection(
        startTime = datetime.now() - timedelta(seconds = 60 * 60),
        endTime = datetime.now(),
        startLoc = [-122, 34],
        endLoc = [-122, 35],
        predictedMode = dummyPredModeMap)
    return (user, dummySection, dummyPredModeMap)
Ejemplo n.º 12
0
 def setUp(self):
     import tests.common
     # Sometimes, we may have entries left behind in the database if one of the tests failed
     # or threw an exception, so let us start by cleaning up all entries
     tests.common.dropAllCollections(get_db())
     user = User.register("*****@*****.**")
     self.uuid = user.uuid
Ejemplo n.º 13
0
  def testRegisterExistingUser(self):
    user = User.register('*****@*****.**')
    self.assertEquals(user.getStudy(), [])
    
    client = Client("testclient")
    client.update(createKey = False)
    common.makeValid(client)

    (resultPre, resultReg) = client.preRegister("this_is_the_super_secret_id", "*****@*****.**")
    self.assertEqual(resultPre, 0)
    self.assertEqual(resultReg, 1)

    user = User.fromEmail("*****@*****.**")
    self.assertEquals(user.getStudy(), ['testclient'])

    # Here's the key difference, now register again
    user = User.register('*****@*****.**')
    self.assertEquals(user.getStudy(), ['testclient'])
Ejemplo n.º 14
0
 def setUp(self):
     # Sometimes, we may have entries left behind in the database if one of the tests failed
     # or threw an exception, so let us start by cleaning up all entries
     tests.common.dropAllCollections(get_db())
     user = User.register("*****@*****.**")
     self.uuid = user.uuid
     self.serverName = "localhost"
     self.now = datetime.now()
     self.dayago = self.now - timedelta(days=1)
     self.weekago = self.now - timedelta(weeks = 1)
Ejemplo n.º 15
0
def createUserProfile():
  logging.debug("Called createUserProfile")
  userToken = request.json['user']
  # This is the only place we should use the email, since we may not have a
  # UUID yet. All others should only use the UUID.
  userEmail = verifyUserToken(userToken)
  logging.debug("userEmail = %s" % userEmail)
  user = User.register(userEmail)
  logging.debug("Looked up user = %s" % user)
  logging.debug("Returning result %s" % {'uuid': str(user.uuid)})
  return {'uuid': str(user.uuid)}
Ejemplo n.º 16
0
  def testGetSettingsCustomUser(self):
    client = Client("testclient")
    client.update(createKey = False)
    common.makeValid(client)

    (resultPre, resultReg) = client.preRegister("this_is_the_super_secret_id", "*****@*****.**")
    self.assertEqual(resultPre, 1)
    self.assertEqual(resultReg, 0)

    user = User.register('*****@*****.**')
    self.assertRegexpMatches(user.getSettings()['result_url'], ".*/test/test/test")
Ejemplo n.º 17
0
  def testRegisterStudyUser(self):
    client = Client("testclient")
    client.update(createKey = False)
    common.makeValid(client)

    (resultPre, resultReg) = client.preRegister("this_is_the_super_secret_id", "*****@*****.**")
    self.assertEqual(resultPre, 1)
    self.assertEqual(resultReg, 0)

    user = User.register('*****@*****.**')
    self.assertEquals(user.getStudy(), ['testclient'])
Ejemplo n.º 18
0
    def testRegisterExistingUser(self):
        user = User.register('*****@*****.**')
        self.assertEquals(user.getStudy(), [])

        client = Client("testclient")
        client.update(createKey=False)
        common.makeValid(client)

        (resultPre,
         resultReg) = client.preRegister("this_is_the_super_secret_id",
                                         "*****@*****.**")
        self.assertEqual(resultPre, 0)
        self.assertEqual(resultReg, 1)

        user = User.fromEmail("*****@*****.**")
        self.assertEquals(user.getStudy(), ['testclient'])

        # Here's the key difference, now register again
        user = User.register('*****@*****.**')
        self.assertEquals(user.getStudy(), ['testclient'])
Ejemplo n.º 19
0
  def setUp(self):
    self.testUsers = ["*****@*****.**", "*****@*****.**", "*****@*****.**",
                      "*****@*****.**", "*****@*****.**"]
    self.serverName = 'localhost'

    # Sometimes, we may have entries left behind in the database if one of the tests failed
    # or threw an exception, so let us start by cleaning up all entries
    tests.common.dropAllCollections(get_db())
    self.ModesColl = get_mode_db()
    # self.ModesColl.remove()
    self.assertEquals(self.ModesColl.find().count(), 0)

    self.SectionsColl = get_section_db()
    # self.SectionsColl.remove()
    self.assertEquals(self.SectionsColl.find().count(), 0)

    load_database_json.loadTable(self.serverName, "Stage_Modes", "tests/data/modes.json")
    load_database_json.loadTable(self.serverName, "Stage_Sections", "tests/data/testCarbonFile")

    # Let's make sure that the users are registered so that they have profiles
    for userEmail in self.testUsers:
      User.register(userEmail)

    self.walkExpect = 1057.2524056424411
    self.busExpect = 2162.668467546699
    self.busCarbon = 267.0/1609

    self.now = datetime.now()
    self.dayago = self.now - timedelta(days=1)
    self.weekago = self.now - timedelta(weeks = 1)

    for section in self.SectionsColl.find():
      section['section_start_datetime'] = self.dayago
      section['section_end_datetime'] = self.dayago + timedelta(hours = 1)
      section['predicted_mode'] = [0, 0.4, 0.6, 0]
      section['confirmed_mode'] = ''
      # print("Section start = %s, section end = %s" %
      #   (section['section_start_datetime'], section['section_end_datetime']))
      # Replace the user email with the UUID
      section['user_id'] = User.fromEmail(section['user_id']).uuid
      self.SectionsColl.save(section)
Ejemplo n.º 20
0
    def testRunBackgroundTasksForDay(self):
        self.testUsers = ["*****@*****.**", "*****@*****.**", "*****@*****.**",
                          "*****@*****.**", "*****@*****.**"]
        load_database_json.loadTable(self.serverName, "Stage_Modes", "tests/data/modes.json")
        load_database_json.loadTable(self.serverName, "Stage_Sections", "tests/data/testCarbonFile")

        # Let's make sure that the users are registered so that they have profiles
        for userEmail in self.testUsers:
          User.register(userEmail)

        self.SectionsColl = get_section_db()
        tests.common.updateSections(self)

        self.assertNotEqual(len(self.uuid_list), 0)
        # Can access the zeroth element because we know that then length is greater than zero
        # (see above)
        test_uuid = self.uuid_list[0]
        test_user = User.fromUUID(test_uuid)
        self.assertNotIn('carbon_footprint', test_user.getProfile().keys())
        data.runBackgroundTasks(test_user.uuid)
        self.assertIn('carbon_footprint', test_user.getProfile().keys())
    def setUp(self):
        self.testUsers = ["*****@*****.**", "*****@*****.**", "*****@*****.**",
                          "*****@*****.**", "*****@*****.**"]
        self.serverName = 'localhost'

        # Sometimes, we may have entries left behind in the database if one of the tests failed
        # or threw an exception, so let us start by cleaning up all entries
        tests.common.dropAllCollections(get_db())

        self.ModesColl = get_mode_db()
        self.assertEquals(self.ModesColl.find().count(), 0)

        self.SectionsColl = get_section_db()
        self.assertEquals(self.SectionsColl.find().count(), 0)

        load_database_json.loadTable(self.serverName, "Stage_Modes", "tests/data/modes.json")
        load_database_json.loadTable(self.serverName, "Stage_Sections", "tests/data/testModeInferFile")

        # Let's make sure that the users are registered so that they have profiles
        for userEmail in self.testUsers:
          User.register(userEmail)

        self.now = datetime.now()
        self.dayago = self.now - timedelta(days=1)
        self.weekago = self.now - timedelta(weeks = 1)

        for section in self.SectionsColl.find():
          section['section_start_datetime'] = self.dayago
          section['section_end_datetime'] = self.dayago + timedelta(hours = 1)
          if (section['confirmed_mode'] == 5):
            # We only cluster bus and train trips
            # And our test data only has bus trips
            section['section_start_point'] = {u'type': u'Point', u'coordinates': [-122.270039042, 37.8800285728]}
            section['section_end_point'] = {u'type': u'Point', u'coordinates': [-122.2690412952, 37.8739578595]}
          # print("Section start = %s, section end = %s" %
          #   (section['section_start_datetime'], section['section_end_datetime']))
          # Replace the user email with the UUID
          section['user_id'] = User.fromEmail(section['user_id']).uuid
          self.SectionsColl.save(section)
          self.pr = precompute_results.PrecomputeResults()
Ejemplo n.º 22
0
    def testCountForStudy(self):
        client = Client("testclient")
        client.update(createKey=False)
        common.makeValid(client)

        (resultPre,
         resultReg) = client.preRegister("this_is_the_super_secret_id",
                                         "*****@*****.**")
        self.assertEqual(resultPre, 1)
        self.assertEqual(resultReg, 0)

        user = User.register('*****@*****.**')
        self.assertEquals(userclient.countForStudy('testclient'), 1)
Ejemplo n.º 23
0
  def testGetFirstStudy(self):
    user = User.register('*****@*****.**')
    self.assertTrue(User.isRegistered('*****@*****.**'))

    client = Client("testclient")
    client.update(createKey = False)
    common.makeValid(client)

    (resultPre, resultReg) = client.preRegister("this_is_the_super_secret_id", "*****@*****.**")
    self.assertEqual(resultPre, 0)
    self.assertEqual(resultReg, 1)

    user = User.fromEmail('*****@*****.**')
    self.assertEqual(user.getFirstStudy(), 'testclient')
Ejemplo n.º 24
0
    def testGetSettingsCustomUser(self):
        client = Client("testclient")
        client.update(createKey=False)
        common.makeValid(client)

        (resultPre,
         resultReg) = client.preRegister("this_is_the_super_secret_id",
                                         "*****@*****.**")
        self.assertEqual(resultPre, 1)
        self.assertEqual(resultReg, 0)

        user = User.register('*****@*****.**')
        self.assertRegexpMatches(user.getSettings()['result_url'],
                                 ".*/test/test/test")
Ejemplo n.º 25
0
  def testSetClientSpecificFields(self):
    user = User.register('*****@*****.**')
    self.assertTrue(User.isRegistered('*****@*****.**'))

    # Check that the field doesn't exist initially    
    self.assertTrue(user.getProfile().get('test_field', 'blank'), 'blank')

    # Check that a simple value update works
    user.setClientSpecificProfileFields({'test_field': 'something beautiful'})
    self.assertTrue(user.getProfile().get('test_field', 'blank'), 'something beautiful')

    # Check that a data structure update works
    user.setClientSpecificProfileFields({'test_field': {'something': 'beautiful'}})
    self.assertTrue(user.getProfile().get('test_field', 'blank'), {'something': 'beautiful'})
Ejemplo n.º 26
0
def createUserProfile():
  logging.debug("Called createUserProfile")
  userToken = request.json['user']
  # This is the only place we should use the email, since we may not have a
  # UUID yet. All others should only use the UUID.
  if skipAuth:
    userEmail = userToken
  else: 
    userEmail = verifyUserToken(userToken)
  logging.debug("userEmail = %s" % userEmail)
  user = User.register(userEmail)
  logging.debug("Looked up user = %s" % user)
  logging.debug("Returning result %s" % {'uuid': str(user.uuid)})
  return {'uuid': str(user.uuid)}
Ejemplo n.º 27
0
  def testPreRegisterExistingUser(self):
    from dao.user import User

    user = User.register("*****@*****.**")

    client = Client("testclient")
    client.update(createKey = False)
    common.makeValid(client)
    (resultPre, resultReg) = client.preRegister("this_is_the_super_secret_id", "*****@*****.**")
    self.assertEqual(resultPre, 0)
    self.assertEqual(resultReg, 1)

    self.assertEqual(user.getStudy(), ['testclient'])
    pendingRegs = Client.getPendingClientRegs("*****@*****.**")
    self.assertEqual(pendingRegs, [])
Ejemplo n.º 28
0
    def testGetFirstStudy(self):
        user = User.register('*****@*****.**')
        self.assertTrue(User.isRegistered('*****@*****.**'))

        client = Client("testclient")
        client.update(createKey=False)
        common.makeValid(client)

        (resultPre,
         resultReg) = client.preRegister("this_is_the_super_secret_id",
                                         "*****@*****.**")
        self.assertEqual(resultPre, 0)
        self.assertEqual(resultReg, 1)

        user = User.fromEmail('*****@*****.**')
        self.assertEqual(user.getFirstStudy(), 'testclient')
Ejemplo n.º 29
0
  def testClientSpecificSettersNoOverride(self):
    from dao.user import User

    fakeEmail = "*****@*****.**"
    user = User.register("*****@*****.**")
    self.assertEqual(user.getFirstStudy(), None)

    dummyPredModeMap = {'walking': 1.0}
    dummySection = common.createDummySection(startTime = datetime.now() - timedelta(seconds = 60 * 60),
        endTime = datetime.now(),
        startLoc = [-122, 34],
        endLoc = [-122, 35],
        predictedMode = dummyPredModeMap)

    clientSetQuery = Client(user.getFirstStudy()).clientSpecificSetters(user.uuid, dummySection, dummyPredModeMap)
    self.assertEqual(clientSetQuery, None)
Ejemplo n.º 30
0
 def testGetCarbonFootprintForMode(self):
   user = User.register('*****@*****.**')
   user.setMpgArray([45, 50, 31])
   # Avg MPG = 42
   correctCarbonFootprintForMode = {'walking' : 0,
                         'running' : 0,
                         'cycling' : 0,
                           'mixed' : 0,
                       'bus_short' : 267.0/1609,
                        'bus_long' : 267.0/1609,
                     'train_short' : 92.0/1609,
                      'train_long' : 92.0/1609,
                       'car_short' : (1/(42*1.6093))*8.91,
                        'car_long' : (1/(42*1.6093))*8.91,
                       'air_short' : 217.0/1609,
                        'air_long' : 217.0/1609
                     }
   self.assertEquals(user.getCarbonFootprintForMode(), correctCarbonFootprintForMode)
Ejemplo n.º 31
0
    def testSetClientSpecificFields(self):
        user = User.register('*****@*****.**')
        self.assertTrue(User.isRegistered('*****@*****.**'))

        # Check that the field doesn't exist initially
        self.assertTrue(user.getProfile().get('test_field', 'blank'), 'blank')

        # Check that a simple value update works
        user.setClientSpecificProfileFields(
            {'test_field': 'something beautiful'})
        self.assertTrue(user.getProfile().get('test_field', 'blank'),
                        'something beautiful')

        # Check that a data structure update works
        user.setClientSpecificProfileFields(
            {'test_field': {
                'something': 'beautiful'
            }})
        self.assertTrue(user.getProfile().get('test_field', 'blank'),
                        {'something': 'beautiful'})
Ejemplo n.º 32
0
 def testGetCarbonFootprintForMode(self):
     user = User.register('*****@*****.**')
     user.setMpgArray([45, 50, 31])
     # Avg MPG = 42
     correctCarbonFootprintForMode = {
         'walking': 0,
         'running': 0,
         'cycling': 0,
         'mixed': 0,
         'bus_short': 267.0 / 1609,
         'bus_long': 267.0 / 1609,
         'train_short': 92.0 / 1609,
         'train_long': 92.0 / 1609,
         'car_short': (1 / (42 * 1.6093)) * 8.91,
         'car_long': (1 / (42 * 1.6093)) * 8.91,
         'air_short': 217.0 / 1609,
         'air_long': 217.0 / 1609
     }
     self.assertEquals(user.getCarbonFootprintForMode(),
                       correctCarbonFootprintForMode)
Ejemplo n.º 33
0
  def testGetSectionFilter(self):
    from dao.user import User

    fakeEmail = "*****@*****.**"

    client = Client("testclient")
    client.update(createKey = False)
    common.makeValid(client)

    (resultPre, resultReg) = client.preRegister("this_is_the_super_secret_id", fakeEmail)
    studyList = Client.getPendingClientRegs(fakeEmail)
    self.assertEqual(studyList, ["testclient"])

    user = User.register("*****@*****.**")
    self.assertEqual(user.getFirstStudy(), 'testclient')

    self.assertEqual(client.getSectionFilter(user.uuid), [])
    # Now, set the update timestamp to two weeks ago
    common.updateUserCreateTime(user.uuid)
    self.assertEqual(client.getSectionFilter(user.uuid), [{'test_auto_confirmed.prob': {'$lt': 0.9}}])
Ejemplo n.º 34
0
    def setupUserAndClient(self):
        # At this point, the more important test is to execute the query and see
        # how well it works
        from dao.user import User
        from dao.client import Client
        import tests.common
        from datetime import datetime, timedelta
        from get_database import get_section_db

        fakeEmail = "*****@*****.**"

        client = Client("gamified")
        client.update(createKey = False)
        tests.common.makeValid(client)

        (resultPre, resultReg) = client.preRegister("this_is_the_super_secret_id", fakeEmail)
        studyList = Client.getPendingClientRegs(fakeEmail)
        self.assertEqual(studyList, ["gamified"])

        user = User.register("*****@*****.**")
        self.assertEqual(user.getFirstStudy(), 'gamified')
        self.user = user
Ejemplo n.º 35
0
    def setupUserAndClient(self):
        # At this point, the more important test is to execute the query and see
        # how well it works
        from dao.user import User
        from dao.client import Client
        import tests.common
        from datetime import datetime, timedelta
        from get_database import get_section_db

        fakeEmail = "*****@*****.**"

        client = Client("gamified")
        client.update(createKey=False)
        tests.common.makeValid(client)

        (resultPre,
         resultReg) = client.preRegister("this_is_the_super_secret_id",
                                         fakeEmail)
        studyList = Client.getPendingClientRegs(fakeEmail)
        self.assertEqual(studyList, ["gamified"])

        user = User.register("*****@*****.**")
        self.assertEqual(user.getFirstStudy(), 'gamified')
        self.user = user
Ejemplo n.º 36
0
 def testUnregister(self):
     user = User.register('*****@*****.**')
     self.assertTrue(User.isRegistered('*****@*****.**'))
     User.unregister('*****@*****.**')
     self.assertFalse(User.isRegistered('*****@*****.**'))
Ejemplo n.º 37
0
 def testGetSettingsDefaultUser(self):
     user = User.register('*****@*****.**')
     self.assertRegexpMatches(user.getSettings()['result_url'],
                              ".*/compare")
Ejemplo n.º 38
0
 def testRegisterNonStudyUser(self):
     user = User.register('*****@*****.**')
     self.assertEquals(user.getStudy(), [])
Ejemplo n.º 39
0
 def testRegisterNonStudyUser(self):
   user = User.register('*****@*****.**')
   self.assertEquals(user.getStudy(), [])
Ejemplo n.º 40
0
 def testIsRegistered(self):
     user = User.register('*****@*****.**')
     self.assertTrue(User.isRegistered('*****@*****.**'))
Ejemplo n.º 41
0
 def testUnregister(self):
   user = User.register('*****@*****.**')
   self.assertTrue(User.isRegistered('*****@*****.**'))
   User.unregister('*****@*****.**')
   self.assertFalse(User.isRegistered('*****@*****.**'))
Ejemplo n.º 42
0
 def testGetSettingsDefaultUser(self):
   user = User.register('*****@*****.**')
   self.assertRegexpMatches(user.getSettings()['result_url'], ".*/compare")
Ejemplo n.º 43
0
 def testCountForStudyDefault(self):
   from get_database import get_profile_db, get_uuid_db, get_client_db, get_pending_signup_db
   user = User.register('*****@*****.**')
   self.assertEquals(userclient.countForStudy('testclient'), 0)
   self.assertEquals(userclient.countForStudy(None), 1)
Ejemplo n.º 44
0
 def testIsRegistered(self):
   user = User.register('*****@*****.**')
   self.assertTrue(User.isRegistered('*****@*****.**'))
Ejemplo n.º 45
0
 def testCountForStudyDefault(self):
     from get_database import get_profile_db, get_uuid_db, get_client_db, get_pending_signup_db
     user = User.register('*****@*****.**')
     self.assertEquals(userclient.countForStudy('testclient'), 0)
     self.assertEquals(userclient.countForStudy(None), 1)
Ejemplo n.º 46
0
 def testGetAvgMpg(self):
   user = User.register('*****@*****.**')
   user.setMpgArray([45, 50, 31])
   self.assertEquals(user.getAvgMpg(), 42)
Ejemplo n.º 47
0
 def testGetAvgMpg(self):
     user = User.register('*****@*****.**')
     user.setMpgArray([45, 50, 31])
     self.assertEquals(user.getAvgMpg(), 42)