1
0
mirror of https://github.com/linkedin/oncall.git synced 2025-11-29 23:38:17 +02:00
Files
oncall/e2e/test_users.py
Diego Cepeda af327b4e4a Py3 (#290)
* Py3 migration

* Update to Python 3 for CircleCI

* Fix auth bugs for python 3

Also fix notifier bug to check for active users

* Update notifier exception handling

Ignore role:target lookup failures from Iris, since these don't represent
problems with the underlying system, just that people have inactive users
on-call in the future.

* Add get_id param option (#246)

* add get_id param option

* removed superfluous select and simplified logic

* Flake8 typo (#247)

* Hide confusing team settings in an advanced dropdown

* Fix test fixtures

* Add "allow duplicate" scheduler in UI

Already in backend, so enable in FE too

* Add Dockerfile to run oncall in a container

* Move deps into a virtualenv.
Run app not as super user.
Mimick prod setup by using uwsgi

* Fix issue with Dockerfile not having MANIFEST.in and wrong passwords in (#257)

config

* Update to ubuntu:18.04 and python3 packages and executables

* Open config file as utf8

The default configuration file has utf8 characters, and python3
attempts to open the file as ASCII unless an alternate encoding
is specified

* Switch to the python3 uwsgi plugin

* Update print and os.execv statements for python3

Python3 throws an exception when the first argument to os.execv is empty:
ValueError: execv() arg 2 first element cannot be empty

The module documentation suggests that the first element should be the
name of the executed program:
https://docs.python.org/3.7/library/os.html#os.execv

* Map config.docker.yaml in to the container as a volume

./ops/entrypoint.py has the start of environment variable support
to specify a configuration file, but it is incomplete until we
update ./ops/daemons/uwsgi-docker.yaml or add environment support
to oncall-notifier and oncall-scheduler.

This commit allows users to map a specific configuration file in
to their container and have it used by all oncall programs.

* Convert line endings to match the rest of the project.

* Add mysql port to docker configuration

* Assume localhost mysql for default config.yaml

* Update python-dev package and MySQL root password

* Use password when configuring mysql

The project has started using a password on the mysql instance.
Once password auth is consistently working we can consider extracting
the hardcoded password into an env file that is optionally randomly
generated on initial startup.

* Fix preview for round-robin (#269)

* #275 fix for Python3 and Gunicorn load config

* Fixed E303 flake8

* Change encoding & collation + test  unicode name

Co-authored-by: Daniel Wang <dwang159@gmail.com>
Co-authored-by: ahm3djafri <42748963+ahm3djafri@users.noreply.github.com>
Co-authored-by: TK <tkahnoski+github@gmail.com>
Co-authored-by: Tim Freund <tim@freunds.net>
Co-authored-by: Rafał Zawadzki <bluszcz@bluszcz.net>
2020-01-15 15:38:25 -08:00

80 lines
2.5 KiB
Python

# Copyright (c) LinkedIn Corporation. All rights reserved. Licensed under the BSD-2 Clause license.
# See LICENSE in the project root for license information.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import requests
import json
from testutils import prefix, api_v0
def test_api_v0_users():
user_name = 'test_v0_users_user'
def clean_up():
requests.delete(api_v0('users/'+user_name))
clean_up()
# test adding user
re = requests.post(api_v0('users'), json={'name': user_name})
assert re.status_code == 201
re = requests.get(api_v0('users/'+user_name))
assert re.status_code == 200
response = json.loads(re.text)
assert 'contacts' in response
assert response['full_name'] != 'Juan Doş'
# test updating user
re = requests.put(api_v0('users/'+user_name), json={'full_name': 'Juan Doş', 'time_zone': 'PDT'})
assert re.status_code == 204
# test updating user contacts
re = requests.put(api_v0('users/'+user_name), json={'full_name': 'Juan Doş', 'contacts': {'call': '+1 333-333-3339'}})
assert re.status_code == 204
# make sure update has gone through, test get
re = requests.get(api_v0('users/'+user_name))
assert re.status_code == 200
response = re.json()
assert response['full_name'] == 'Juan Doş'
user_id = response['id']
re = requests.get(api_v0('users?id=%s' % user_id))
assert re.status_code == 200
response = re.json()
assert response[0]['full_name'] == 'Juan Doş'
re = requests.get(api_v0('users'), params={'name': user_name, 'fields': ['full_name', 'time_zone', 'contacts']})
assert re.status_code == 200
response = json.loads(re.text)
assert response[0]['full_name'] == 'Juan Doş'
assert response[0]['time_zone'] == 'PDT'
assert response[0]['contacts']['call'] == '+1 333-333-3339'
clean_up()
@prefix('test_v0_user_teams')
def test_api_v0_user_teams(team, user):
team_name = team.create()
user_name = user.create()
# should get an empty team list
re = requests.get(api_v0('users/%s/teams' % user_name))
assert re.status_code == 200
assert re.json() == []
# should not get an empty team list
re = requests.post(api_v0('teams/%s/users' % team_name), json={'name': user_name})
assert re.status_code == 201
re = requests.get(api_v0('users/%s/teams' % user_name))
assert re.status_code == 200
assert team_name in re.json()
# should get 404 on invalid user
re = requests.get(api_v0('users/invalid_user_foobar-123/teams'))
assert re.status_code == 404