-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
042cb32
commit a4f12c1
Showing
4 changed files
with
372 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
"""Mock data for testing""" | ||
|
||
INDEX_CONFIG = { | ||
'keys': [('id', -1)] | ||
} | ||
INDEX_CONFIG_USERS = { | ||
'keys': [('uid', -1)] | ||
} | ||
|
||
COLLECTION_CONFIG = { | ||
'indexes': [INDEX_CONFIG], | ||
} | ||
|
||
COLLECTION_CONFIG_USERS = { | ||
'indexes': [INDEX_CONFIG_USERS], | ||
} | ||
|
||
DB_CONFIG = { | ||
'collections': { | ||
'repositories': COLLECTION_CONFIG, | ||
'builds': COLLECTION_CONFIG, | ||
'subscriptions': COLLECTION_CONFIG, | ||
'users': COLLECTION_CONFIG_USERS | ||
}, | ||
} | ||
|
||
MONGO_CONFIG = { | ||
'host': 'mongodb', | ||
'port': 27017, | ||
'dbs': { | ||
'pubgradeStore': DB_CONFIG, | ||
}, | ||
} | ||
ENDPOINT_CONFIG = { | ||
"repository": { | ||
"id_charset": [ | ||
"string.ascii_lowercase", | ||
"string.digits", | ||
".", | ||
"-" | ||
], | ||
"id_length": 6, | ||
"retries": 3 | ||
}, | ||
"access_token": { | ||
"charset": [ | ||
"string.ascii_lowercase", | ||
"string.digits", | ||
".", | ||
"-" | ||
], | ||
"length": 32, | ||
}, | ||
"subscriptions": { | ||
"admin_user": { | ||
"name": "Akash", | ||
"uid": "9fe2c4e93f654fdbb24c02b15259716c", | ||
"user_access_token": "c42a6d44e3d0" | ||
} | ||
} | ||
} | ||
|
||
MOCK_REPOSITORY_1 = { | ||
"url": "https://github.com/akash2237778/webserver" | ||
} | ||
|
||
MOCK_REPOSITORY_2 = { | ||
"url": "https://github.com/akash2237778/Pubgrade-test", | ||
"id": "repo12", | ||
"access_token": "access_token" | ||
} | ||
|
||
MOCK_REPOSITORY_3 = { | ||
"url": "https://github.com/akash2237778/Pubgrade-test", | ||
"id": "eiic.g", | ||
"access_token": "g.i.ssstitrti.ccier.tgsactt.iosg", | ||
"build_list": ["eiic.gngdgrs", "eiic.gnabmns"], | ||
"subscription_list": ["tnglot"] | ||
} | ||
MOCK_REPOSITORIES = [ | ||
MOCK_REPOSITORY_1, | ||
MOCK_REPOSITORY_2 | ||
] | ||
MOCK_POST_REPOSITORY = { | ||
"access_token": "xxxxxxxxxxxxxx", | ||
"id": "repository_123" | ||
} | ||
|
||
MOCK_BUILD_BODY = { | ||
"images": [ | ||
{ | ||
"name": "akash7778/webserver:0.0.3", | ||
"location": "./Dockerfile" | ||
} | ||
], | ||
"head_commit": { | ||
"branch": "master" | ||
}, | ||
"dockerhub_token": "YWthc2g3Nzc4Ok1vbnR5c2FpbmlAMg==" | ||
} | ||
|
||
MOCK_BUILD_INFO = { | ||
"images": [ | ||
{"name": "akash7778/test-updater:0.0.1", "location": "./Dockerfile"}], | ||
"head_commit": {"branch": "main", | ||
"commit_sha": "8cd58eb160014c91e4f181562352" | ||
"c693d3442c52"}, | ||
"dockerhub_token": "dockerhub token", | ||
"id": "eiic.gngdgrs", "finished_at": "NULL", | ||
"started_at": "2021-08-04T17:40:58.344809", | ||
"status": "QUEUED" | ||
} | ||
MOCK_BUILD_INFO_2 = { | ||
"images": [ | ||
{"name": "akash7778/updater:0.0.1", "location": "./Dockerfile"}], | ||
"head_commit": {"tag": "0.4.2"}, | ||
"dockerhub_token": "dockerhub token", | ||
"id": "eiic.gnabmns", "finished_at": "NULL", | ||
"started_at": "2021-08-04T17:40:58.344809", | ||
"status": "QUEUED" | ||
} | ||
|
||
MOCK_BUILD_PAYLOAD = { | ||
"images": [ | ||
{ | ||
"name": "akash7778/test-updater:0.0.1", | ||
"location": "./Dockerfile" | ||
} | ||
], | ||
"head_commit": { | ||
"branch": "main", | ||
"commit_sha": "8cd58eb160014c91e4f181562352c693d3442c52" | ||
}, | ||
"dockerhub_token": "dockerhub token" | ||
} | ||
|
||
MOCK_SUBSCRIPTION = { | ||
"subscription_id": "subscription-xyz" | ||
} | ||
MOCK_SUBSCRIPTION_INFO = { | ||
"repository_id": "eiic.g", | ||
"callback_url": "https://ec2-54-203-145-132." | ||
"compute-1.amazonaws.com/update", | ||
"access_token": "xxxxxxxxxxxx", "type": "branch", | ||
"value": "main", "id": "tnglot", "state": "Inactive" | ||
} | ||
|
||
MOCK_USER_1 = { | ||
'name': 'Akash1' | ||
} | ||
|
||
MOCK_USER = { | ||
'uid': '9fe2c4e93f654fdbb24c02b15259716c', | ||
'user_access_token': 'c42a6d44e3d0', | ||
'name': 'Akash', | ||
'isVerified': True | ||
} | ||
|
||
MOCK_USER_NOT_VERIFIED = { | ||
'uid': '9fe2c4e93f65424c02b15259716c', | ||
'user_access_token': 'c42a6e3d0', | ||
'name': 'Akash', | ||
'isVerified': False | ||
} | ||
|
||
MOCK_USER_DB = { | ||
"uid": "9fe2c4e93f654fdbb24c02b15259716c", | ||
"name": "Akash", | ||
"user_access_token": "c42a6d44e3d0", | ||
'isVerified': True, | ||
"subscription_list": ["tnglot"] | ||
} | ||
SUBSCRIPTION_PAYLOAD = { | ||
"repository_id": "eiic.g", | ||
"callback_url": "https://ec2-54-203-145-132." | ||
"compute-1.amazonaws.com/update", | ||
"access_token": "xxxxxxxxxxxx", "type": "tag", | ||
"value": "dev", "id": "tnglot" | ||
} | ||
MOCK_ENDPOINT = { | ||
"repository": { | ||
"id_charset": 'A', | ||
"id_length": 1, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import json | ||
import requests | ||
|
||
from mock_data import ( | ||
MOCK_REPOSITORY_1, | ||
MOCK_BUILD_BODY | ||
) | ||
|
||
from test_repositories import test_post_repository | ||
|
||
base_url = "http://192.168.59.100:30008" | ||
headers = { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json' | ||
} | ||
|
||
repo_content = test_post_repository() | ||
build_id = "" | ||
payload_objects = json.dumps(MOCK_BUILD_BODY) | ||
|
||
def test_get_repository_builds(): | ||
"""Test `GET /repositories/{id}/builds` for fetching available builds for repository.""" | ||
global repo_content | ||
endpoint = "/repositories/"+repo_content['id']+"/builds" | ||
response = requests.request("GET", base_url + endpoint, headers=headers) | ||
assert response.status_code == 200 | ||
|
||
def test_post_build(): | ||
"""Test `POST /repositories/{id}/builds` for successfully creating new build.""" | ||
global repo_content | ||
endpoint = "/repositories/"+repo_content['id']+"/builds" | ||
headers['X-Project-Access-Token'] = repo_content['access_token'] | ||
response = requests.request("POST", base_url + endpoint, headers=headers, | ||
data=payload_objects) | ||
assert response.status_code == 200 | ||
global build_id | ||
build_id = json.loads(response.content)['id'] | ||
|
||
|
||
def test_get_build(): | ||
"""Test `GET /repositories/{id}/builds/{build_id}` for fetching repository build info.""" | ||
global repo_content | ||
global build_id | ||
endpoint = "/repositories/"+repo_content['id']+"/builds/"+build_id | ||
response = requests.request("GET", base_url + endpoint, headers=headers) | ||
assert response.status_code == 200 | ||
#print(json.loads(response.content)) | ||
assert json.loads(response.content)['images'][0]['name'] == json.loads(payload_objects)['images'][0]['name'] | ||
|
||
def test_error_400_post_build(): | ||
"""Test `POST /repositories/{id}/builds` for response 400 (Bad request)""" | ||
global repo_content | ||
endpoint = "/repositories/"+repo_content['id']+"/builds" | ||
response = requests.request("POST", base_url + endpoint, headers=headers, | ||
data={}) | ||
assert response.status_code == 400 | ||
|
||
""" | ||
def test_put_build(): | ||
#Test `PUT /repositories/{id}/builds/{build_id}` for updating build. | ||
global repo_content | ||
global build_id | ||
endpoint = "/repositories/"+repo_content['id']+"/builds/"+build_id | ||
""" | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import json | ||
import requests | ||
|
||
from mock_data import ( | ||
MOCK_REPOSITORY_1 | ||
) | ||
|
||
base_url = "http://192.168.59.100:30008" | ||
headers = { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json' | ||
} | ||
|
||
reponse_repo = "" | ||
payload_objects = json.dumps(MOCK_REPOSITORY_1) | ||
|
||
def test_error_404(): | ||
"""Test `GET /` for response 404 (Page not found)""" | ||
endpoint = "/test_endpoint" | ||
response = requests.request("GET", base_url + endpoint, headers=headers, | ||
data={}) | ||
assert response.status_code == 404 | ||
|
||
def test_get_repositories(): | ||
"""Test `GET /repositories` for fetching repositories.""" | ||
endpoint = "/repositories" | ||
response = requests.request("GET", base_url + endpoint, headers=headers) | ||
assert response.status_code == 200 | ||
|
||
def test_post_repository(): | ||
"""Test `POST /repository` for successfully creating or updating a new | ||
repository. | ||
""" | ||
endpoint = "/repositories" | ||
response = requests.request("POST", base_url + endpoint, headers=headers, | ||
data=payload_objects) | ||
global response_repo | ||
response_repo = json.loads(response.content) | ||
assert response.status_code == 200 | ||
return response_repo | ||
|
||
def test_get_repository(): | ||
"""Test `GET /repositories/{id}` for fetching repository info.""" | ||
global response_repo | ||
endpoint = "/repositories/"+response_repo['id'] | ||
response = requests.request("GET", base_url + endpoint, headers=headers) | ||
assert response.status_code == 200 | ||
response_content = json.loads(response.content) | ||
assert response_content['url'] == json.loads(payload_objects)['url'] | ||
assert response_content != response_repo | ||
|
||
def test_put_repository(): | ||
"""Test `PUT /repositories/{id}` to modify or update a repository""" | ||
global response_repo | ||
endpoint = "/repositories/"+response_repo['id'] | ||
object_put_payload = json.loads(payload_objects) | ||
object_put_payload['url'] = 'https://github.com/akash2237778/webserver-modified-url' | ||
headers['X-Project-Access-Token'] = response_repo['access_token'] | ||
response = requests.request("PUT", base_url + endpoint, headers=headers, | ||
data=json.dumps(object_put_payload)) | ||
assert response.status_code == 200 | ||
response = requests.request("GET", base_url + endpoint, headers=headers) | ||
response_content = json.loads(response.content) | ||
assert response.status_code == 200 | ||
assert response_content['url'] == object_put_payload['url'] | ||
|
||
def test_delete_repository(): | ||
"""Test `DELETE /repositories/{id}` to delete repository""" | ||
global response_repo | ||
endpoint = "/repositories/"+response_repo['id'] | ||
headers['X-Project-Access-Token'] = response_repo['access_token'] | ||
response = requests.request("DELETE", base_url + endpoint, headers=headers) | ||
assert response.status_code == 200 | ||
assert json.loads(response.content)['message'] == 'Repository deleted successfully' | ||
|
||
def test_error_400_post_repository(): | ||
"""Test `POST /repositories` for response 400 (Bad request)""" | ||
endpoint = "/repositories" | ||
response = requests.request("POST", base_url + endpoint, headers=headers, | ||
data={}) | ||
assert response.status_code == 400 | ||
|
||
def test_error_404_get_repository(): | ||
"""Test `GET /repositories/{id}` for response 404 (Resource not found)""" | ||
endpoint = "/repositories/12" | ||
response = requests.request("GET", base_url + endpoint, headers=headers) | ||
assert response.status_code == 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import json | ||
import requests | ||
|
||
from mock_data import ( | ||
MOCK_USER_1 | ||
) | ||
|
||
base_url = "http://192.168.59.100:30008" | ||
headers = { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json' | ||
} | ||
|
||
user_info = "" | ||
payload_objects = json.dumps(MOCK_USER_1) | ||
|
||
def test_post_user(): | ||
"""Test `POST /users/register` for successfully creating registering new user.""" | ||
endpoint = "/users/register" | ||
response = requests.request("POST", base_url + endpoint, headers=headers, | ||
data=payload_objects) | ||
global user_info | ||
user_info = json.loads(response.content) | ||
#print(user_info) | ||
assert response.status_code == 200 | ||
|
||
def test_error_400_post_user(): | ||
"""Test `POST /users/register` for response 400 (Bad request)""" | ||
endpoint = "/users/register" | ||
response = requests.request("POST", base_url + endpoint, headers=headers, | ||
data={}) | ||
assert response.status_code == 400 | ||
|