django-rest-framework - 使用 Github 操作的自动 Django API 测试失败
问题描述
我想在 Github 的每次推送期间测试自动测试。所以我写了一个基本的 API 和测试用例。在我使用 ubuntu 的本地机器上,一切正常。我将代码上传到 GitHub 存储库,并编写了 GitHub 工作流程,如下所示:
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
我的测试代码就像下面这样:
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
但是当我推送到 GitHub 时,我遇到了连接错误。
我正在学习 Github 操作。如果我让它运行会很好。这个的 Github 链接是:https ://github.com/bikashckarmokar/covid_prediction
解决方案
推荐阅读
- kotlin - Kotlin - 使用集合中的键获取最大值
- sql - 在 SQL Server 表查询中查找不同的用户
- wpf - 如何在 C# 中逐行阅读单词段落?
- c# - C# - 我无法连接到网络服务
- c# - MS-Graph 请求:权限不足
- swift - 在 Moya 14 中记录响应和请求
- android - 当我在移动设备上运行我的 android 应用程序时,它给了我这个错误,请指导我这个错误
- c# - 如何使用 Ninject 注入我的服务以获取 GetVaryByCustomString
- class - Kotlin 类的工作不如预期
- docker - Spotify Docker 构建主机网络