-
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.
Merge pull request #5 from taptorestart/add_bdd
TST: Add bdd test
- Loading branch information
Showing
9 changed files
with
340 additions
and
2 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[pytest] | ||
DJANGO_SETTINGS_MODULE = config.settings.api | ||
python_files = test_*.py | ||
python_files = test_*.py *_test.py | ||
testpaths = 'tests' | ||
addopts = --reuse-db --nomigrations -ra -q -p no:warnings |
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,3 +1,4 @@ | ||
pytest==7.3.1 | ||
pytest-django==4.5.2 | ||
factory-boy==3.2.1 | ||
pytest-bdd==7.0.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
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
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,31 @@ | ||
@django_db | ||
Feature: Form Create Test | ||
Background: | ||
Given The data to be sent is as follows. | ||
""" | ||
{ | ||
"slug": "test", | ||
"title": "test", | ||
"start_date": "2023-12-01", | ||
"end_date": "2023-12-31" | ||
} | ||
""" | ||
|
||
Scenario Outline: Form Create Permission Test | ||
Given I am a/an <user_type> user. | ||
And I am logging in. | ||
When I am making a request to the server with data using the POST and /v1/forms/. | ||
Then The response status code is <status_code>. | ||
Examples: | ||
| user_type | status_code | | ||
| anonymous | 403 | | ||
| general | 403 | | ||
| staff | 201 | | ||
|
||
Scenario: Form Create Test | ||
Given I am a/an staff user. | ||
And I am logging in. | ||
When I am making a request to the server with data using the POST and /v1/forms/. | ||
Then The response status code is 201. | ||
And The slug data in the response JSON is the same as test. | ||
And The title data in the response JSON is of type str and the same as test. |
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,31 @@ | ||
@django_db | ||
Feature: Form Delete Test | ||
Background: | ||
Given I will save the following data using backend.tests.apis.factories's FormFactory. | ||
""" | ||
{ | ||
"id": 1, | ||
"slug": "test", | ||
"title": "test", | ||
"start_date": "2023-12-01", | ||
"end_date": "2023-12-31" | ||
} | ||
""" | ||
|
||
Scenario Outline: Form Delete Permission Test | ||
Given I am a/an <user_type> user. | ||
And I am logging in. | ||
When I am making a request to the server using the DELETE and /v1/forms/test/. | ||
Then The response status code is <status_code>. | ||
Examples: | ||
| user_type | status_code | | ||
| anonymous | 403 | | ||
| general | 403 | | ||
| staff | 204 | | ||
|
||
Scenario: Form Delete Test | ||
Given I am a/an staff user. | ||
And I am logging in. | ||
When I am making a request to the server using the DELETE and /v1/forms/test/. | ||
Then The response status code is 204. | ||
And The existence of data with an ID of 1 in the Form model from apps.forms.models is False. |
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 @@ | ||
@django_db | ||
Feature: Form List Test | ||
Background: | ||
Given I will save the following data using backend.tests.apis.factories's FormFactory. | ||
""" | ||
{ | ||
"id": 1, | ||
"slug": "test", | ||
"title": "test", | ||
"start_date": "2023-12-01", | ||
"end_date": "2023-12-31" | ||
} | ||
""" | ||
|
||
Scenario Outline: Form List Permission Test | ||
Given I am a/an <user_type> user. | ||
And I am logging in. | ||
When I am making a request to the server using the GET and /v1/forms/. | ||
Then The response status code is <status_code>. | ||
Examples: | ||
| user_type | status_code | | ||
| anonymous | 200 | | ||
| general | 200 | | ||
| staff | 200 | | ||
|
||
Scenario: Form List Test | ||
Given I am a/an general user. | ||
And I am logging in. | ||
When I am making a request to the server using the GET and /v1/forms/. | ||
Then The response status code is 200. | ||
And The number of result in the response JSON is 1. | ||
And The slug data in the 1st/nd/rd/th entry of the response JSON list is the same as test. | ||
And The title data in the 1st/nd/rd/th entry of the response JSON list is of type str and the same as test. |
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,41 @@ | ||
from pytest_bdd import scenario | ||
|
||
|
||
@scenario("form_list.feature", "Form List Permission Test") | ||
def test_form_list_permission_test(): | ||
pass | ||
|
||
|
||
@scenario("form_list.feature", "Form List Test") | ||
def test_form_list_test(): | ||
pass | ||
|
||
|
||
@scenario("form_create.feature", "Form Create Permission Test") | ||
def test_form_create_permission_test(): | ||
pass | ||
|
||
|
||
@scenario("form_create.feature", "Form Create Test") | ||
def test_form_create_test(): | ||
pass | ||
|
||
|
||
@scenario("form_update.feature", "Form Partial Update Permission Test") | ||
def test_form_partial_update_permission_test(): | ||
pass | ||
|
||
|
||
@scenario("form_update.feature", "Form Partial Update Test") | ||
def test_form_partial_update_test(): | ||
pass | ||
|
||
|
||
@scenario("form_delete.feature", "Form Delete Permission Test") | ||
def test_form_delete_permission_test(): | ||
pass | ||
|
||
|
||
@scenario("form_delete.feature", "Form Delete Test") | ||
def test_form_delete_test(): | ||
pass |
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,41 @@ | ||
@django_db | ||
Feature: Form Update Test | ||
Background: | ||
Given I will save the following data using backend.tests.apis.factories's FormFactory. | ||
""" | ||
{ | ||
"id": 1, | ||
"slug": "test", | ||
"title": "test", | ||
"start_date": "2023-12-01", | ||
"end_date": "2023-12-31" | ||
} | ||
""" | ||
And The data to be sent is as follows. | ||
""" | ||
{ | ||
"title": "test1" | ||
} | ||
""" | ||
|
||
Scenario Outline: Form Partial Update Permission Test | ||
Given I am a/an <user_type> user. | ||
And I am logging in. | ||
When I am making a request to the server with data using the PATCH and /v1/forms/test/. | ||
Then The response status code is <status_code>. | ||
Examples: | ||
| user_type | status_code | | ||
| anonymous | 403 | | ||
| general | 403 | | ||
| staff | 200 | | ||
|
||
|
||
Scenario: Form Partial Update Test | ||
Given I am a/an staff user. | ||
And I am logging in. | ||
When I am making a request to the server with data using the PATCH and /v1/forms/test/. | ||
Then The response status code is 200. | ||
And The id data in the response JSON is the same as 1. | ||
And The title data in the response JSON is the same as test1. | ||
And The existence of data with an ID of 1 in the Form model from apps.forms.models is True. | ||
And The title data of the Form model from apps.forms.models with an ID of 1 is of type str and the same as test1. |