Ejemplo n.º 1
0
def test_update_current_user_profile(app):
  mocked_profile = {
    'id': 1,
    'user_id': 1,
    'first_name': 'Tim',
    'last_name': 'Bruin',
    'profile_picture': '',
    'gender': 'Male',
    'preferred_gender': 'Female',
    'color': '',
    'animal': '',
    'interests': {'interest1': 'value1', 'interest2': 'value2'},
    'created_at': 0,
    'updated_at': 0
  }

  with app.app_context():
    g.user_id = '1'
    service = AuthService('secret')
    old_profile = service.get_current_user_profile()._asdict()

    fields = {'first_name' : 'Tim',
              'interests': {'interest1': 'value1', 'interest2': 'value2'}}
    new_profile = service.update_current_user_profile(fields)._asdict()

    assert new_profile is not old_profile and \
           new_profile['updated_at'] > old_profile['updated_at']
    # Ignore created/updated time
    new_profile['created_at'], new_profile['updated_at'] = 0, 0
    assert new_profile == mocked_profile

  with app.app_context():
    service = AuthService('secret')
    old_profile = service.get_current_user_profile()
    assert old_profile is None

  with app.app_context():
    g.user_id = '1'
    service = AuthService('secret')
    old_profile = service.get_current_user_profile()._asdict()

    fields = {'thisisnotavalidkey' : 'thisisnotavalidvalue',
              'first_name': 'Tim',
              'interests': {'interest1': 'value1', 'interest2': 'value2'}}
    new_profile = service.update_current_user_profile(fields)._asdict()

    assert new_profile is not old_profile and \
           new_profile['updated_at'] > old_profile['updated_at']
    # Ignore created/updated time
    new_profile['created_at'], new_profile['updated_at'] = 0, 0
    assert new_profile == mocked_profile
Ejemplo n.º 2
0
def test_get_current_user_profile(app):
  with app.app_context():
    g.user_id = '1'
    service = AuthService('secret')
    profile = service.get_current_user_profile()._asdict()
    # Ignore created/updated time
    profile['created_at'], profile['updated_at'] = 0, 0

    # Profile._asdict() does not return match_history
    mocked_profile = {
      'id': 1,
      'user_id': 1,
      'first_name': 'Joe',
      'last_name': 'Bruin',
      'profile_picture': '',
      'gender': 'Male',
      'preferred_gender': 'Female',
      'color': '',
      'animal': '',
      'interests': {'interest1': 'value1'},
      'created_at': 0,
      'updated_at': 0
    }

    assert profile == mocked_profile

  with app.app_context():
    service = AuthService('secret')
    profile = service.get_current_user()
    assert profile is None