Skip to content

Commit

Permalink
Added method for changing run class, fix for method edit lumisections…
Browse files Browse the repository at this point in the history
…, update tests. (#3)

* Adapted advanced rr usage tests, added extra function

* Added a method for changing the run class

* Update CI, cleanup test

* Fix for edit_rr_lumisections, cleanup, readme

* Verbose tests

* Added a test for edit_rr_lumisections

* Cleanup instruction
  • Loading branch information
nothingface0 authored May 14, 2024
1 parent 87ab4d2 commit e673fc2
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 160 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/test_package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -30,9 +29,9 @@ jobs:
# # default set of ruff rules with GitHub Annotations
# ruff --format=github --target-version=py37 .
- name: Test with pytest
env:
env:
SSO_CLIENT_ID: ${{ secrets.SSO_CLIENT_ID }}
SSO_CLIENT_SECRET: ${{ secrets.SSO_CLIENT_SECRET }}
ENVIRONMENT: ${{ vars.ENVIRONMENT }}
run: |
pytest tests
pytest tests -s
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/certs


# Created by https://www.gitignore.io/api/python,pycharm+all
# Edit at https://www.gitignore.io/?templates=python,pycharm+all

Expand Down Expand Up @@ -86,7 +85,7 @@ modules.xml
*.ipr

# Sonarlint plugin
.idea/sonarlint
.idea/sonarlint

### Python ###
# Byte-compiled / optimized / DLL files
Expand Down Expand Up @@ -209,4 +208,6 @@ dmypy.json
### Python Patch ###
.venv/

# End of https://www.gitignore.io/api/python,pycharm+all
# End of https://www.gitignore.io/api/python,pycharm+all

.env*
102 changes: 38 additions & 64 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,66 +1,40 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File (Integrated Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"debugStdLib": true,
"env": {
"ENVIRONMENT": "staging"
}
},
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
]
},
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "enter-your-module-name-here",
"console": "integratedTerminal"
},
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"console": "integratedTerminal",
"args": ["runserver", "--noreload", "--nothreading"],
"django": true
},
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "app.py"
},
"args": ["run", "--no-debugger", "--no-reload"],
"jinja": true
},
{
"name": "Python: Current File (External Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "externalTerminal"
}
]
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File (Integrated Terminal)",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false,
"env": {
"ENVIRONMENT": "staging"
}
},
{
"name": "Python: Module",
"type": "debugpy",
"request": "launch",
"module": "enter-your-module-name-here",
"console": "integratedTerminal"
},
{
"name": "Python: Current File (External Terminal)",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "externalTerminal"
},
{
"name": "Python: Update runs",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/update_specific_runs.py",
"args": ["319528"]
}
]
}
29 changes: 13 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Python version>=3.6 is required for this package.
A virtual environment is also required, if you are in lxplus you should run the following commands:

```bash
virtualenv -p `which python3` venv
virtualenv -p $(which python3) venv
source venv/bin/activate
```

Expand All @@ -32,27 +32,27 @@ pip install runregistry
## Authentication Prerequisites

> **Warning**
> Grid certificates have been deprecated by CERN. As of version `1.0.0`, the `runregistry`
> client only works with a client ID and a secret.
> Grid certificates have been deprecated by CERN. As of version `1.0.0`, the `runregistry`
> client only works with a client ID and a secret.
You will need to create an SSO registration for your application which is going to be using the runregistry API client.
You will need to create an SSO registration for your application which is going to be using the runregistry API client.

Instructions on how to do it can be found on the [`cernrequests`](https://github.com/CMSTrackerDPG/cernrequests) GitHub page.

Once you have a client ID and a secret, you will need to store them in a file named `.env`. A [sample file](.env_sample) is provided so that you can edit it and rename it to `.env`.
Once you have a client ID and a secret, you will need to store them in a file named `.env`. A [sample file](.env_sample) is provided so that you can edit it and rename it to `.env`.

Alternatively, you can run `export SSO_CLIENT_ID=...` and `export SSO_CLIENT_SECRET=...` on the same terminal that you will be running your python script in.

## Usage

### Get a single run (get_run):
### Get a single run (get_run)

```python
import runregistry
run = runregistry.get_run(run_number=328762)
```

### Query several runs (get_runs):
### Query several runs (get_runs)

```python
import runregistry
Expand Down Expand Up @@ -396,7 +396,7 @@ You can also manipulate runs via API:
```python
runregistry.reset_RR_attributes_and_refresh_runs(run=362761)
```
3. Move runs from one state to another:
3. Move runs from one state to another:
```python
runregistry.move_runs("OPEN", "SIGNOFF", run=362761)
```
Expand All @@ -416,20 +416,17 @@ python3 -m twine upload --skip-existing --repository pypi dist/*
```
Instructions from [here](https://packaging.python.org/en/latest/tutorials/packaging-projects/).

## Testing
## Running the tests

### Locally

> **TODO**
> Remove the qa environment after migration.
You will be needing a file named `.env` with the following variables:

You will be needing a file named `.env` with the following variables
```bash
SSO_CLIENT_ID=<change>
SSO_CLIENT_SECRET=<change>
ENVIRONMENT=qa
ENVIRONMENT=development
```
While most of the tests work on the development deployment, some fail and need the production one. This is the reason we are setting `ENVIRONMENT=qa`.

```bash
python3 -m venv venv
Expand Down Expand Up @@ -458,8 +455,8 @@ No*.

Our recommendation is to query Run Registry only for data that RR is responsible for.

<small>*It's not that you can't, it's just that this puts extra burden on the application, making it slow for everyone.</small>
<small>*It's not that you can't, it's just that this puts extra burden on the application, making it slow for everyone.</small>

### Is the token stored somewhere and reused?

No, almost every function call gets a new token. This is not ideal, and it may be improved in the future.
No, almost every function call gets a new token. This is not ideal, and it may be improved in the future.
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
log_level = INFO
log_format = %(asctime)s %(levelname)s %(message)s
log_date_format = %Y-%m-%d %H:%M:%S
2 changes: 1 addition & 1 deletion runregistry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# To update:
# pip install wheel && pip install twine && python setup.py bdist_wheel && twine upload --skip-existing dist/*
__version__ = "1.0.0"
__version__ = "1.1.0"
Loading

0 comments on commit e673fc2

Please sign in to comment.