Esempio n. 1
0
  def _create_user(self):
    headers = test_utils.create_basic_auth_headers()
    headers['Content-Type'] = 'application/json'
    user_request = requests.post("http://*****:*****@test.com',
                                                  'password': '******'}))

    self.assertEqual(200, user_request.status_code)
    self.assertEqual('*****@*****.**', user_request.json()['email'])
Esempio n. 2
0
  def test_create_user_fails_if_not_json(self):
    # Setup.
    headers = test_utils.create_basic_auth_headers()

    user_data = json.dumps({'email': '*****@*****.**'})

    # Exercise.
    response = self.app.post('/api/user/',
                             data=user_data,
                             headers=headers)

    # Verify
    self.assertEqual(400, response.status_code)
    self.assertFalse(user_models.User.find_by_email('*****@*****.**'))
Esempio n. 3
0
  def test_delete_user_deletes_if_exists(self):
    # Setup.
    user = user_models.User.create('*****@*****.**', 'qwerty')
    user.put()
    test_utils.mock_get_user_id(self, user.key.id())

    headers = test_utils.create_basic_auth_headers()
    headers['Content-Type'] = 'application/json'

    # Exercise.
    response = self.app.delete('/api/user/', headers=headers)

    # Verify
    self.assertEqual(200, response.status_code)
    found_user = user_models.User.find_by_email('*****@*****.**')
    self.assertFalse(found_user)
Esempio n. 4
0
  def test_get_access_token_returns_correct_token(self):
    # Setup.
    grant_request_data = {'grant_type': 'password',
                          'username': '******',
                          'password': '******',
                          'client_id': constants.CLIENT_ID}

    # Execute.
    token_request = requests.post("http://localhost:8080/oauth/token",
                                  data=grant_request_data,
                                  headers=test_utils.create_basic_auth_headers())

    token_data = token_request.json()

    # Verify.
    self.assertTrue(token_data)
    self.assertTrue(token_data['access_token'])
Esempio n. 5
0
  def _get_authorization_headers(self, email, password):
    grant_request_data = {'grant_type': 'password',
                          'username': email,
                          'password': password,
                          'client_id': constants.CLIENT_ID}

    token_response = requests.post("http://localhost:8080/oauth/token",
                                   data=grant_request_data,
                                   headers=test_utils.create_basic_auth_headers())

    if token_response.status_code == 200:
      access_token = token_response.json()['access_token']

      # Need to wait before using the token to make sure it is saved in cache.
      _wait_caching()

      return {'Authorization': 'Bearer {}'.format(access_token)}
    else:
      return None
Esempio n. 6
0
  def test_token_handler_creates_token(self):
    # Setup.
    headers = test_utils.create_basic_auth_headers()
    user = user_models.User.create('*****@*****.**', 'qwerty')
    user.put()

    grant_request_data = {'grant_type': 'password',
                          'username': '******',
                          'password': '******',
                          'client_id': constants.CLIENT_ID}

    # Exercise.
    response = self.app.post('/oauth/token',
                             data=grant_request_data,
                             headers=headers)

    # Verify
    self.assertEqual(200, response.status_code)
    token_data = json.loads(response.data)
    self.assertTrue(token_data['access_token'])
Esempio n. 7
0
  def test_create_user_finds_if_exists(self):
    # Setup.
    user = user_models.User(email='*****@*****.**')
    user.put()

    headers = test_utils.create_basic_auth_headers()
    headers['Content-Type'] = 'application/json'

    user_data = json.dumps({'email': '*****@*****.**', 'password': '******'})

    # Exercise.
    response = self.app.post('/api/user/',
                             data=user_data,
                             headers=headers)

    # Verify
    self.assertEqual(200, response.status_code)
    user_json = json.loads(response.data)
    self.assertEqual('*****@*****.**', user_json['email'])
    self.assertEqual(user.key.id(), user_json['user_id'])
Esempio n. 8
0
  def test_create_user_creates_if_not_exists(self):
    # Setup.
    headers = test_utils.create_basic_auth_headers()
    headers['Content-Type'] = 'application/json'

    user_data = json.dumps({'email': '*****@*****.**',
                            'password': '******'})

    # Exercise.
    response = self.app.post('/api/user/',
                             data=user_data,
                             headers=headers)

    # Verify
    self.assertEqual(200, response.status_code)
    user_json = json.loads(response.data)
    self.assertEqual('*****@*****.**', user_json['email'])
    found_user = user_models.User.find_by_email('*****@*****.**')
    self.assertTrue(found_user)
    self.assertTrue(found_user.check_password('qwerty'))
Esempio n. 9
0
 def _create_client(self):
   client_request = requests.get("http://localhost:8080/api/client/create",
                                 headers=test_utils.create_basic_auth_headers())
   self.assertEqual(200, client_request.status_code)
   self.assertEqual(constants.CLIENT_ID, client_request.json()['client_id'])