-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(provider): add more e2e assertion and define postman collections…
… tests (#10)
- Loading branch information
Showing
3 changed files
with
333 additions
and
5 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
297 changes: 297 additions & 0 deletions
297
postman_collections/Tech Assessment.postman_collection.json
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,297 @@ | ||
{ | ||
"info": { | ||
"_postman_id": "65ed8e43-f9d9-47be-9e29-d718099373f7", | ||
"name": "Tech Assessment", | ||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", | ||
"_exporter_id": "18952256" | ||
}, | ||
"item": [ | ||
{ | ||
"name": "Password Generator", | ||
"item": [ | ||
{ | ||
"name": "password has specific length", | ||
"event": [ | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"exec": [ | ||
"var jsonReq = JSON.parse(pm.request.body.raw);", | ||
"", | ||
"pm.test(`Password has length equal to ${jsonReq.password_length}`, function () {", | ||
" var jsonData = pm.response.json();", | ||
" pm.expect(jsonData.password.length).to.eql(jsonReq.password_length);", | ||
"});" | ||
], | ||
"type": "text/javascript" | ||
} | ||
} | ||
], | ||
"request": { | ||
"method": "POST", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\n \"password_length\": 15\n}", | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "localhost:9001/api/v1/passwords/generate/", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "9001", | ||
"path": [ | ||
"api", | ||
"v1", | ||
"passwords", | ||
"generate", | ||
"" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "password contains only numbers", | ||
"event": [ | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"exec": [ | ||
"var jsonReq = JSON.parse(pm.request.body.raw);", | ||
"", | ||
"pm.test(`Password has only numbers`, function () {", | ||
" var jsonData = pm.response.json();", | ||
" pm.expect(jsonData.password).to.match(/^\\d+$/);", | ||
"});" | ||
], | ||
"type": "text/javascript" | ||
} | ||
} | ||
], | ||
"request": { | ||
"method": "POST", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\n \"password_length\": 20,\n \"has_numbers\": true,\n \"has_lowercase_chars\": false,\n \"has_uppercase_chars\": false,\n \"has_special_chars\": false\n}", | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "localhost:9001/api/v1/passwords/generate/", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "9001", | ||
"path": [ | ||
"api", | ||
"v1", | ||
"passwords", | ||
"generate", | ||
"" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "password contains only lowercase letters", | ||
"event": [ | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"exec": [ | ||
"var jsonReq = JSON.parse(pm.request.body.raw);", | ||
"", | ||
"pm.test(`Password has only lowercase letters`, function () {", | ||
" var jsonData = pm.response.json();", | ||
" pm.expect(jsonData.password).to.match(/^[a-z]+$/);", | ||
"});" | ||
], | ||
"type": "text/javascript" | ||
} | ||
} | ||
], | ||
"request": { | ||
"method": "POST", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\n \"password_length\": 20,\n \"has_numbers\": false,\n \"has_lowercase_chars\": true,\n \"has_uppercase_chars\": false,\n \"has_special_chars\": false\n}", | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "localhost:9001/api/v1/passwords/generate/", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "9001", | ||
"path": [ | ||
"api", | ||
"v1", | ||
"passwords", | ||
"generate", | ||
"" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "password contains only uppercase letters", | ||
"event": [ | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"exec": [ | ||
"var jsonReq = JSON.parse(pm.request.body.raw);", | ||
"", | ||
"pm.test(`Password has only uppercase letters`, function () {", | ||
" var jsonData = pm.response.json();", | ||
" pm.expect(jsonData.password).to.match(/^[A-Z]+$/);", | ||
"});" | ||
], | ||
"type": "text/javascript" | ||
} | ||
} | ||
], | ||
"request": { | ||
"method": "POST", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\n \"password_length\": 20,\n \"has_numbers\": false,\n \"has_lowercase_chars\": false,\n \"has_uppercase_chars\": true,\n \"has_special_chars\": false\n}", | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "localhost:9001/api/v1/passwords/generate/", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "9001", | ||
"path": [ | ||
"api", | ||
"v1", | ||
"passwords", | ||
"generate", | ||
"" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "password contains only special chars", | ||
"event": [ | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"exec": [ | ||
"var jsonReq = JSON.parse(pm.request.body.raw);", | ||
"", | ||
"pm.test(`Password has only special chars`, function () {", | ||
" var jsonData = pm.response.json();", | ||
" pm.expect(jsonData.password).to.match(/^[!\"#$%&\\'()*+,-./:;<=>?@\\[\\\\\\]^_`{|}~]+$/);", | ||
"});" | ||
], | ||
"type": "text/javascript" | ||
} | ||
} | ||
], | ||
"request": { | ||
"method": "POST", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\n \"password_length\": 20,\n \"has_numbers\": false,\n \"has_lowercase_chars\": false,\n \"has_uppercase_chars\": false,\n \"has_special_chars\": true\n}", | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "localhost:9001/api/v1/passwords/generate/", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "9001", | ||
"path": [ | ||
"api", | ||
"v1", | ||
"passwords", | ||
"generate", | ||
"" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "password can contains any chars", | ||
"event": [ | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"exec": [ | ||
"var jsonReq = JSON.parse(pm.request.body.raw);", | ||
"", | ||
"pm.test(`Password has only special chars`, function () {", | ||
" var jsonData = pm.response.json();", | ||
" pm.expect(jsonData.password).to.match(/^[a-zA-Z0-9!\"#$%&\\'()*+,-./:;<=>?@\\[\\\\\\]^_`{|}~]+$/);", | ||
"});" | ||
], | ||
"type": "text/javascript" | ||
} | ||
} | ||
], | ||
"request": { | ||
"method": "POST", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "{\n \"password_length\": 20,\n \"has_numbers\": true,\n \"has_lowercase_chars\": true,\n \"has_uppercase_chars\": true,\n \"has_special_chars\": true\n}", | ||
"options": { | ||
"raw": { | ||
"language": "json" | ||
} | ||
} | ||
}, | ||
"url": { | ||
"raw": "localhost:9001/api/v1/passwords/generate/", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "9001", | ||
"path": [ | ||
"api", | ||
"v1", | ||
"passwords", | ||
"generate", | ||
"" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
} | ||
] | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -1,17 +1,48 @@ | ||
import re | ||
|
||
import pytest | ||
from httpx import AsyncClient | ||
|
||
|
||
@pytest.mark.parametrize( | ||
[ | ||
'password_length', | ||
'has_numbers', | ||
'has_lowercase_chars', | ||
'has_uppercase_chars', | ||
'has_special_chars', | ||
'expected_match' | ||
], | ||
[ | ||
(20, True, False, False, False, r'^\d+$'), | ||
(20, False, True, False, False, r'^[a-z]+$'), | ||
(25, False, False, True, False, r'^[A-Z]+$'), | ||
(1, False, False, False, True, r'^[!"#$%&\'()*+,-./:;<=>?@\[\\\]^_`{|}~]+$'), | ||
(15, True, True, True, True, r'^[a-zA-Z0-9!"#$%&\'()*+,-./:;<=>?@\[\\\]^_`{|}~]+$'), | ||
], | ||
) | ||
@pytest.mark.asyncio | ||
async def test_e2e_generate_password(mocked_client: AsyncClient): | ||
expected_length = 20 | ||
async def test_e2e_generate_password( | ||
mocked_client: AsyncClient, | ||
password_length: int, | ||
has_numbers: bool, | ||
has_lowercase_chars: bool, | ||
has_uppercase_chars: bool, | ||
has_special_chars: bool, | ||
expected_match: str | ||
): | ||
|
||
async with mocked_client as client: | ||
response = await client.post("/api/v1/passwords/generate/", json={ | ||
"password_length": expected_length, | ||
"password_length": password_length, | ||
"has_numbers": has_numbers, | ||
"has_lowercase_chars": has_lowercase_chars, | ||
"has_uppercase_chars": has_uppercase_chars, | ||
"has_special_chars": has_special_chars, | ||
}) | ||
|
||
assert response.status_code == 200 | ||
body = response.json() | ||
assert body['password'] is not None | ||
assert len(body['password']) == expected_length | ||
assert len(body['password']) == password_length | ||
assert re.match(pattern=expected_match, string=body['password']) |