Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Test Pull Request
on:
pull_request:
branches:
- 'dev'
- 'staging'
- 'master'
workflow_dispatch:
jobs:
test-pr:
uses: ./.github/workflows/run_tests.yml
secrets: inherit
67 changes: 67 additions & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Run tests
on:
workflow_dispatch:
workflow_call:
jobs:
test:
runs-on: ubuntu-latest
env:
ELASTIC_PASSWORD: "changeme"
ELASTIC7_HOST: "localhost"
ELASTIC7_PORT: "9200"
DB_HOST: 127.0.0.1
AWS_REGION: ${{ secrets.AWS_REGION }}
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
LAUNCH_DARKLY_KEY: ${{ secrets.LAUNCH_DARKLY_KEY_DEV }}
TEST_DATA_DUMP_FILE: ${{ vars.TEST_DATA_DUMP_FILE }}
services:
elasticsearch7:
image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
env:
discovery.type: single-node
ES_JAVA_OPTS: -Xms512m -Xmx512m
ELASTIC_PASSWORD: changeme
xpack.security.enabled: "false"
http.cors.enabled: "true"
http.cors.allow-origin: "*"
ports:
- 9200:9200
db:
image: mysql:8.0
env:
MYSQL_DATABASE: "rorapi"
MYSQL_USER: "ror_user"
MYSQL_PASSWORD: "password"
MYSQL_ROOT_PASSWORD: "password"
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Checkout ror-api code
uses: actions/checkout@v2
with:
path: ror-api
- name: Set up Python environment
uses: actions/setup-python@v6
with:
python-version: "3.8"
cache: "pip"
- name: Install requirements
working-directory: ./ror-api
run: |
# python -m pip install --upgrade pip
pip install -r requirements.txt
pip install yapf

python manage.py collectstatic --noinput
- name: Load test data
working-directory: ./ror-api
run: |
python manage.py setup ${{ env.TEST_DATA_DUMP_FILE }} -t
- name: Run Tests
working-directory: ./ror-api
run: |
python manage.py test rorapi.tests.tests_unit
# TODO fix these tests running in GitHub Action
# python manage.py test rorapi.tests.tests_integration
# python manage.py test rorapi.tests.tests_functional
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
interval: 10s
timeout: 1s
volumes:
- ./esdata:/usr/share/elasticsearch/data
- esdata:/usr/share/elasticsearch/data
db:
image: mysql:8.0
volumes:
Expand Down Expand Up @@ -46,3 +46,5 @@ services:
- db
volumes:
mysql_data:
esdata:
driver: local
15 changes: 10 additions & 5 deletions rorapi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,19 @@
'BULK_SIZE': 500
}

# use AWS4Auth for AWS Elasticsearch unless running locally via docker
if os.environ.get('ELASTIC7_HOST', 'elasticsearch7') != 'elasticsearch7':
http_auth = AWS4Auth(os.environ.get('AWS_ACCESS_KEY_ID'),
os.environ.get('AWS_SECRET_ACCESS_KEY'),
os.environ.get('AWS_REGION'), 'es')
# use AWS4Auth for AWS Elasticsearch unless running locally via docker or localhost
if os.environ.get('ELASTIC7_HOST', 'elasticsearch7') not in ['elasticsearch7', 'localhost']:
aws_access_key = os.environ.get('AWS_ACCESS_KEY_ID')
aws_secret_key = os.environ.get('AWS_SECRET_ACCESS_KEY')
aws_region = os.environ.get('AWS_REGION')
if aws_access_key and aws_secret_key and aws_region:
http_auth = AWS4Auth(aws_access_key, aws_secret_key, aws_region, 'es')
else:
http_auth = ('elastic', os.environ.get('ELASTIC_PASSWORD', 'changeme'))
else:
http_auth = ('elastic', os.environ.get('ELASTIC_PASSWORD', 'changeme'))


ES7 = Elasticsearch([{
'host': os.environ.get('ELASTIC7_HOST', 'elasticsearch7'),
'port': int(os.environ.get('ELASTIC7_PORT', '9200'))
Expand Down
Loading