Skip to content

Commit

Permalink
Update requirements.txt and test-requirements.txt
Browse files Browse the repository at this point in the history
Versions in requirements.txt are fixed to be similar to the production.
The issue is that we don't update the version when a package is updated
on production.

This patch remove the fixed version in the test-requirements.txt and use the
latest version in the package. Those packages are not used in the
production server, only in the test.

We will discuss in the future to see if we need to remove the fixed
version in the requirements.txt. But in the mean time, we update the
version to match the one we have on the production server.

Change-Id: Idf3522284ad3fc039f60c8e6e07def343dd9d7ab
  • Loading branch information
rh-gvincent committed Apr 7, 2021
1 parent 7b6ee61 commit f1616d9
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"""

# revision identifiers, used by Alembic.
revision = '32fdbb3715e7'
down_revision = '3eccf653cd30'
revision = "32fdbb3715e7"
down_revision = "3eccf653cd30"
branch_labels = None
depends_on = None

Expand All @@ -37,28 +37,24 @@ def upgrade():
db_conn = op.get_bind()

# get the Red Hat team
query = sql.select([models.TEAMS]).where(
models.TEAMS.c.name == 'Red Hat'
)
query = sql.select([models.TEAMS]).where(models.TEAMS.c.name == "Red Hat")
team_redhat = db_conn.execute(query).fetchone()
if team_redhat is None:
return

# get all the read only users
_JUTR = models.JOIN_USERS_TEAMS_ROLES
query = sql.select([_JUTR]).where(
sql.and_(
_JUTR.c.team_id == None, # noqa
_JUTR.c.role == 'READ_ONLY_USER'
))
sql.and_(_JUTR.c.team_id == None, _JUTR.c.role == "READ_ONLY_USER") # noqa
)
users_teams_roles = db_conn.execute(query).fetchall()

# add the users to the Red Hat team
for utr in users_teams_roles:
try:
q = _JUTR.insert().values(team_id=team_redhat.id,
user_id=utr.user_id,
role='READ_ONLY_USER')
q = _JUTR.insert().values(
team_id=team_redhat.id, user_id=utr.user_id, role="READ_ONLY_USER"
)
db_conn.execute(q)
except sa_exc.IntegrityError:
# if the user already exist, just ignore the statement
Expand Down
6 changes: 3 additions & 3 deletions dci/api/v1/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ def _verify_component_and_topic_access(user, component):


def _verify_component_access_and_role(user, component):
component_team_id = component['team_id']
component_team_id = component["team_id"]
if component_team_id is not None:
if user.is_not_in_team(component_team_id):
dci_exc.Unauthorized()
elif user.is_not_super_admin() and user.is_not_feeder() and user.is_not_epm(): # noqa
raise dci_exc.Unauthorized()
elif user.is_not_super_admin() and user.is_not_feeder() and user.is_not_epm():
raise dci_exc.Unauthorized()


@api.route('/components', methods=['POST'])
Expand Down
26 changes: 13 additions & 13 deletions dci/api/v1/sso.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@


def get_latest_public_key(self):
sso_url = dci_config.CONFIG.get('SSO_URL')
realm = dci_config.CONFIG.get('SSO_REALM')
sso_url = dci_config.CONFIG.get("SSO_URL")
realm = dci_config.CONFIG.get("SSO_REALM")
url = "%s/auth/realms/%s/.well-known/openid-configuration" % (sso_url, realm)
jwks_uri = requests.get(url).json()["jwks_uri"]
jwks = requests.get(jwks_uri).json()["keys"]
Expand All @@ -46,19 +46,19 @@ def decode_token_with_latest_public_key(token):
try:
latest_public_key = get_latest_public_key()
except Exception as e:
raise dci_exc.DCIException('Unable to get last SSO public key: %s' % str(e), # noqa
status_code=401)
raise dci_exc.DCIException(
"Unable to get last SSO public key: %s" % str(e), status_code=401
)
# SSO server didn't update its public key
if conf['SSO_PUBLIC_KEY'] == latest_public_key:
raise dci_exc.DCIException('Invalid JWT token.', status_code=401) # noqa
if conf["SSO_PUBLIC_KEY"] == latest_public_key:
raise dci_exc.DCIException("Invalid JWT token.", status_code=401)
try:
decoded_token = auth.decode_jwt(token,
latest_public_key,
conf['SSO_CLIENT_ID'])
conf['SSO_PUBLIC_KEY'] = latest_public_key
decoded_token = auth.decode_jwt(token, latest_public_key, conf["SSO_CLIENT_ID"])
conf["SSO_PUBLIC_KEY"] = latest_public_key
return decoded_token
except (jwt_exc.DecodeError, TypeError):
raise dci_exc.DCIException('Invalid JWT token.', status_code=401) # noqa
raise dci_exc.DCIException("Invalid JWT token.", status_code=401)
except jwt_exc.ExpiredSignatureError:
raise dci_exc.DCIException('JWT token expired, please refresh.', # noqa
status_code=401)
raise dci_exc.DCIException(
"JWT token expired, please refresh.", status_code=401
)
14 changes: 10 additions & 4 deletions dci/api/v1/topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,16 @@ def get_topic_by_id(user, topic_id):
def get_all_topics(user):
def _get_user_product_ids():
_JPT = models.JOIN_PRODUCTS_TEAMS
query = v1_utils.QueryBuilder(models.PRODUCTS, {}, {},
root_join_table=_JPT,
root_join_condition=sql.and_(_JPT.c.product_id == models.PRODUCTS.c.id, # noqa
_JPT.c.team_id.in_(user.teams_ids))) # noqa
query = v1_utils.QueryBuilder(
models.PRODUCTS,
{},
{},
root_join_table=_JPT,
root_join_condition=sql.and_(
_JPT.c.product_id == models.PRODUCTS.c.id,
_JPT.c.team_id.in_(user.teams_ids),
),
)
user_products = query.execute(fetchall=True)
return [up['products_id'] for up in user_products]

Expand Down
36 changes: 18 additions & 18 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
psycopg2==2.7.5 # ignore: use latest version of psycopg2 to avoid building it during pip install
pyopenssl # ignore: openssl 1.0.2k doesn't exist on pypi
cryptography # ignore: use latest version of cryptography to avoid building it during pip install
alembic==0.8.3 # ignore: use the epel version instead of the centos version
six==1.9.0 # python-six
SQLAlchemy==0.9.8 # python-sqlalchemy
requests==2.6.0 # python-requests
pytz==2016.10 # pytz
pyjwt==1.5.3 # python-jwt
flask==0.10.1 # python-flask
passlib==1.6.5 # python-passlib
dciauth==2.1.7 # python-dciauth
dci-umb==0.3.0 # python-dciumb
SQLAlchemy-Utils==0.31.3 # python-sqlalchemy-utils
pyzmq==14.3.1 # python-zmq
python-keystoneclient==3.17.0 # python2-keystoneclient
python-swiftclient==3.6.0 # python2-swiftclient
jsonschema==2.5.1 # python2-jsonschema
psycopg2-binary # ignore: use latest version of psycopg2 to avoid building it during pip install (python-psycopg2-2.5.1-4.el7.x86_64)
pyopenssl # ignore: openssl 1.0.2k doesn't exist on pypi (openssl-1.0.2k-21.el7_9.x86_64)
cryptography # ignore: use latest version of cryptography to avoid building it during pip install (python2-cryptography-2.1.4-2.el7.x86_64)
alembic==0.9.7 # python2-alembic-0.9.7-1.el7.noarch
six==1.11.0 # python2-six-1.11.0-4.el7.noarch
SQLAlchemy==1.2.7 # python2-sqlalchemy-1.2.7-1.el7.x86_64
requests==2.19.1 # python2-requests-2.19.1-4.el7.noarch
pytz==2016.10 # pytz-2016.10-2.el7.noarch
pyjwt==1.6.1 # python2-jwt-1.6.1-1.el7.noarch
flask==1.0.2 # python2-flask-1.0.2-1.el7.noarch
passlib==1.7.1 # python2-passlib-1.7.1-1.el7.noarch
dciauth # ignore: package from dci use the latest version
dci-umb # ignore: package from dci use the latest version
SQLAlchemy-Utils==0.31.3 # python-sqlalchemy-utils-0.31.3-2.el7.centos.noarch
pyzmq==14.3.1 # python2-zmq-14.7.0-11.el7.x86_64
python-keystoneclient==3.17.0 # python2-keystoneclient-3.17.0-1.el7.noarch
python-swiftclient==3.6.1 # python2-swiftclient-3.6.1-1.el7.noarch
jsonschema==2.6.0 # python2-jsonschema-2.6.0-2.el7.noarch
12 changes: 6 additions & 6 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mock # ignore: mock 1.2.17 doesn't exist on pypi
pytest>=2.7.0 # pytest
dciclient==0.5.1 # python-dciclient
flake8==2.0 # python-flake8
tox==1.4.2 # python-tox
pytest-cov==2.5.1 # python-pytest-cov
mock
pytest
dciclient
flake8
tox
pytest-cov
22 changes: 12 additions & 10 deletions tests/api/v1/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,22 +345,24 @@ def test_success_update_job_status(admin, job_user_id):


def test_job_duration(admin, job_user_id, engine):
job = admin.get('/api/v1/jobs/%s' % job_user_id)
job = job.data['job']
assert job['status'] == 'new'
job = admin.get("/api/v1/jobs/%s" % job_user_id)
job = job.data["job"]
assert job["status"] == "new"
# update the job with a created_at 5 seconds in the past
with engine.begin() as conn:
q = (models.JOBS.update()
.where(models.JOBS.c.id == job_user_id)
.values(created_at=datetime.datetime.utcnow() - datetime.timedelta(0, 5))) # noqa
q = (
models.JOBS.update()
.where(models.JOBS.c.id == job_user_id)
.values(created_at=datetime.datetime.utcnow() - datetime.timedelta(0, 5))
)
conn.execute(q)

data = {'job_id': job_user_id, 'status': 'running'}
js = admin.post('/api/v1/jobstates', data=data)
data = {"job_id": job_user_id, "status": "running"}
js = admin.post("/api/v1/jobstates", data=data)
assert js.status_code == 201
job = admin.get('/api/v1/jobs/%s' % job_user_id)
job = admin.get("/api/v1/jobs/%s" % job_user_id)
# check those 5 seconds
assert job.data['job']['duration'] == 5
assert job.data["job"]["duration"] == 5


def test_first_job_duration(admin, job_user_id, topic, remoteci_context):
Expand Down

0 comments on commit f1616d9

Please sign in to comment.