Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub ActionsによるServerの自動動作確認 #26

Merged
merged 31 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
228a763
add: auto-test.yml
hyouhyan Aug 19, 2024
ccfac7e
wip: os、実行タイミングを指定
hyouhyan Aug 19, 2024
93d2ddc
feat: auto-testにgit checkout追加
hyouhyan Aug 19, 2024
3f5c77e
style: インデントを揃えた
hyouhyan Aug 19, 2024
6bcf96f
test: auth ランダムなメールアドレスでテストするように変更
k22036 Aug 19, 2024
bec0b21
test: pairing ランダムなメールアドレスでテストするように変更
k22036 Aug 19, 2024
5b52859
test: authのテストコードでmongoClientをcloseするように修正
k22036 Aug 19, 2024
baa19e0
style: ymlのインデントを2にした
hyouhyan Aug 19, 2024
122e1f5
feat: python, pip, mongodb, pytestを追加
hyouhyan Aug 19, 2024
3606459
feat: デバッグ用にactionsを手動実行できるようにした
hyouhyan Aug 19, 2024
0e102fb
actionsにタイトルつけた
hyouhyan Aug 19, 2024
96068f0
fix: cd serverの位置を変更
hyouhyan Aug 19, 2024
9078d50
fix: cd serverの位置変更
hyouhyan Aug 19, 2024
96ae2c3
fix: プルリクエストとワークフローのディスパッチをトリガーにするように変更
hyouhyan Aug 19, 2024
cfec0b6
mongodbバージョンを8.0に変更
hyouhyan Aug 19, 2024
eb4a8e6
Server Startのステップを追加
hyouhyan Aug 19, 2024
e8d682b
mongodb-github-actionsのバージョン変更
hyouhyan Aug 19, 2024
834a3b7
mongodb-replica-setをreplsetからtest-rsに変更
hyouhyan Aug 19, 2024
cb4196e
MongoDBバージョンを6.0に変更
hyouhyan Aug 19, 2024
079f557
サーバーのディレクトリ内でmain.pyを実行するように変更
hyouhyan Aug 19, 2024
1fd4c47
make使うように変更
hyouhyan Aug 19, 2024
cb1e7de
サーバーの起動時に環境変数を設定
hyouhyan Aug 19, 2024
af4ee24
ファイル出力の修正
hyouhyan Aug 19, 2024
2fd13c6
バッククオーテーションつけた
hyouhyan Aug 19, 2024
2842233
feat: jsonを別のセクションで作成するようにした
hyouhyan Aug 19, 2024
cf5a790
init envを作成
hyouhyan Aug 19, 2024
eb2471a
原点回帰
hyouhyan Aug 19, 2024
7774daa
serverをscreenで実行するようにした
hyouhyan Aug 19, 2024
d855e18
インデント修正
hyouhyan Aug 19, 2024
a6f8141
create-jsonをバージョンアップ
hyouhyan Aug 19, 2024
57ff239
サーバースタート後に3秒スリープ
hyouhyan Aug 20, 2024
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
56 changes: 56 additions & 0 deletions .github/workflows/auto-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Auto Test nanoRelation Server

on: [pull_request, workflow_dispatch]

jobs:
auto_test:
name: Auto Test nanoRelation Server
runs-on: ubuntu-latest

steps:
- name: Git checkout
uses: actions/checkout@v4

- name: install screen
run: sudo apt-get install -y screen

- name: setup python
uses: actions/[email protected]
with:
python-version: '3.11.5'

- name: Install dependencies
run: |
cd server
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: '6.0'
mongodb-replica-set: test-rs

- name: create json
id: create-json
uses: jsdaniell/[email protected]
with:
name: "nanorelation-firebase-adminsdk.json"
json: ${{ secrets.FIREBASE_ADMINSDK }}
dir: "server/"

- name: Init env
run: echo "${{ secrets.DOT_ENV }}" > server/.env

- name: Start Server
run: |
screen -d -m -S server bash -c "make server-start"; sleep 3
- name: Run tests
run: |
cd server
make run-test
- name: Stop Server
run: |
screen -S server -X quit
34 changes: 27 additions & 7 deletions server/tests/test_auth.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import random
import string
import requests
from pymongo import MongoClient

token = ''
email = ''.join(random.choices(string.ascii_lowercase +
string.digits, k=20))+'@test.org'


def test_signup_success(baseurl):
global token
global email
url = baseurl+'/auth/signup'
res = requests.post(url, json={
'name': 'test',
'email': '[email protected]',
'email': email,
'password': 'password'
})
assert res.status_code == 200
Expand All @@ -17,10 +23,11 @@ def test_signup_success(baseurl):


def test_signup_missing_name(baseurl):
global email
url = baseurl+'/auth/signup'
res = requests.post(url, json={
'name': '',
'email': '[email protected]',
'email': email,
'password': 'password'
})
assert res.status_code == 400
Expand All @@ -39,21 +46,23 @@ def test_signup_missing_email(baseurl):


def test_signup_missing_password(baseurl):
global email
url = baseurl+'/auth/signup'
res = requests.post(url, json={
'name': 'test',
'email': '[email protected]',
'email': email,
'password': ''
})
assert res.status_code == 400
assert res.json()['error'] == 'Missing password'


def test_signup_already_exist(baseurl):
global email
url = baseurl+'/auth/signup'
res = requests.post(url, json={
'name': 'test',
'email': '[email protected]',
'email': email,
'password': 'password'
})
assert res.status_code == 400
Expand Down Expand Up @@ -91,9 +100,10 @@ def test_signout_success(baseurl):

def test_signin_success(baseurl):
global token
global email
url = baseurl+'/auth/signin'
res = requests.post(url, json={
'email': '[email protected]',
'email': email,
'password': 'password'
})
assert res.status_code == 200
Expand All @@ -112,9 +122,10 @@ def test_signin_missing_email(baseurl):


def test_signin_missing_password(baseurl):
global email
url = baseurl+'/auth/signin'
res = requests.post(url, json={
'email': '[email protected]',
'email': email,
'password': ''
})
assert res.status_code == 400
Expand All @@ -133,9 +144,10 @@ def test_signin_wrong_email(baseurl):


def test_signin_wrong_password(baseurl):
global email
url = baseurl+'/auth/signin'
res = requests.post(url, json={
'email': '[email protected]',
'email': email,
'password': 'wrongPassword'
})
assert res.status_code == 400
Expand Down Expand Up @@ -224,3 +236,11 @@ def test_delete_account_success(baseurl):
})
assert res.status_code == 200
assert res.json()['done'] == 'success'

client = MongoClient('localhost', 27017)
db = client['db']
users = db['users']
assert not users.find_one({'token': token})
assert not users.find_one({'email': email})

client.close()
8 changes: 7 additions & 1 deletion server/tests/test_pairing.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import random
import string
import requests
from pymongo import MongoClient

private_key = ''
public_key = ''
token = ''
email = ''.join(random.choices(string.ascii_lowercase +
string.digits, k=20))+'@test.org'


def test_generate_device_key_success(baseurl):
Expand Down Expand Up @@ -39,10 +43,11 @@ def test_generate_device_key_already_exists(baseurl):


def get_token(baseurl):
global email
url = baseurl+'/auth/signup'
res = requests.post(url, json={
'name': 'test',
'email': '[email protected]',
'email': email,
'password': 'password'
})
token = res.json()['token']
Expand Down Expand Up @@ -230,5 +235,6 @@ def test_done(baseurl):
})
users.delete_many({'token': token})
assert not users.find_one({'token': token})
assert not users.find_one({'email': email})

client.close()