Exemplo n.º 1
0
def getUserObjectFromStorage(userId):
  # in lieue of db connection

  # two methods, both are fake about the id

  from services_tb import createTestUsers
  tmpUser = createTestUsers(1)
  tmpUser.id = userId

  from services_tb import genRandomUser
  # deliberately create user with same id but different data to verify that user data is being looked up correctly
  testUser = genRandomUser(**{
      'seed':userId, 
      'mystream':['sheets','pillows'],
      'theirstream':'phantoms',
    })

  #< old way >
  if(0):
    import os.path
    jsonUserDB = 'data.json'
    if(os.path.isfile(jsonUserDB)):
      del testUser # make sure no remnants of previous methods
      userDataJson = open(jsonUserDB).read()
      userDataDict = json.loads(userDataJson)
      if(type(userDataDict) is dict):
        testUser = User(userId)
        testUser.stream_add(userDataDict[userId]['streams_mine'])
        testUser.stream_sub(userDataDict[userId]['streams_subscribed'])
    del userDataDict
  #</old way >

  del testUser
  userDataDict = getObjectFromStorage(userId)
  if(userDataDict):
    testUser = User(userId)
    testUser.stream_add(userDataDict['streams_mine'])
    testUser.stream_sub(userDataDict['streams_subscribed'])

  return testUser
Exemplo n.º 2
0
def getUserObjectFromStorage(userId):
  # in lieue of db connection

  # two methods, both are fake about the id

  from services_tb import createTestUsers
  tmpUser = createTestUsers(1)
  tmpUser.id = userId

  from services_tb import genRandomUser
  # deliberately create user with same id but different data to verify that user data is being looked up correctly
  testUser = genRandomUser(**{
      'seed':userId, 
      'mystream':['sheets','pillows'],
      'theirstream':'phantoms',
    })

  #< old way >
  if(0):
    import os.path
    jsonUserDB = 'data.json'
    if(os.path.isfile(jsonUserDB)):
      del testUser # make sure no remnants of previous methods
      userDataJson = open(jsonUserDB).read()
      userDataDict = json.loads(userDataJson)
      if(type(userDataDict) is dict):
        testUser = User(userId)
        testUser.stream_add(userDataDict[userId]['streams_mine'])
        testUser.stream_sub(userDataDict[userId]['streams_subscribed'])
    del userDataDict
  #</old way >

  del testUser
  userDataDict = getObjectFromStorage(userId)
  if(userDataDict):
    testUser = User(userId)
    testUser.stream_add(userDataDict['streams_mine'])
    testUser.stream_sub(userDataDict['streams_subscribed'])

  return testUser
Exemplo n.º 3
0
def genRandomUser(**kwargs):
    # create random id or name
    _seed = random.randint(0, 1000000)
    paramList = [
        # "seed",
        "mystream",
        "theirstream",
    ]
    # for arg in paramList:
    #  if(arg in kwargs):
    if "seed" in kwargs:
        _seed = kwargs["seed"]
    # use the seed
    idRand = str(_seed)

    randomUser = User(idRand)

    if "mystream" in kwargs:
        randomUser.stream_add(kwargs["mystream"])
    if "theirstream" in kwargs:
        randomUser.stream_sub(kwargs["theirstream"])
    return randomUser
Exemplo n.º 4
0
def genRandomUser(**kwargs):
    # create random id or name
    _seed = random.randint(0, 1000000)
    paramList = [
        #"seed",
        "mystream",
        "theirstream",
    ]
    #for arg in paramList:
    #  if(arg in kwargs):
    if ('seed' in kwargs):
        _seed = kwargs['seed']
    # use the seed
    idRand = str(_seed)

    randomUser = User(idRand)

    if ('mystream' in kwargs):
        randomUser.stream_add(kwargs['mystream'])
    if ('theirstream' in kwargs):
        randomUser.stream_sub(kwargs['theirstream'])
    return randomUser