I wanted to test automatic testing during each push in Github. So I wrote a basic API and test cases. In the local machine where I am using ubuntu, all are working fine. I uploaded the code in a GitHub repository and and wrote the GitHub workflow like below:
name: testing
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test-code:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Set up python
uses: actions/setup-python@v2
with:
python-version: 3.8.8
- name: Caching
uses: actions/cache@v2
with:
path: $/{/{ env.pythonLocation /}/}
key: $/{/{ env.pythonLocation /}/}-$/{/{ hashFiles('setup.py') /}/}-$/{/{ hashFiles('requirements.txt') /}/}
- name: Install dependencies
run: python -m pip install -r requirements.txt
- name: Run django integratin test
run: python manage.py test
My test code is like belwo:
PREDICT_API_URL = 'http://127.0.0.1:8000/predict/'
class PredictApi(TestCase):
'''
Using postman these can be tested as well.
'''
@tag('important')
def test_predict_negative(self):
# python manage.py test predict.tests.PredictApi.test_predict_negative
data = {
"cough": [0],
"fever": [0],
"sore_throat": [0],
"shortness_of_breath": [0],
"head_ache": [0],
"age_60_and_above": [0],
"gender": [0],
"test_indication": [0]
}
response = requests.post(PREDICT_API_URL, json=data)
results = response.json()
assert results['corona'] == 0
But when I am pushing to GitHub I am getting connection error.
I am learning Github actions. It will be good if I make it run. The Github link of this is: https://github.com/bikashckarmokar/covid_prediction
