diff --git a/README.md b/README.md index 139ccb3..7f8c015 100644 --- a/README.md +++ b/README.md @@ -91,4 +91,57 @@ In a new terminal window use the command ~~~ bash behave .\features\restapp.feature -~~~ \ No newline at end of file +~~~ + +### Example Tests + +#### Unit + +There are unit tests included with this project, we are testing the item builder for the object that it returns. + +```python +def test_item_builder_data(self): + expected = {'name': 'Tool', 'description': 'Hammer', 'price': 10.5, '_id': 99} + self.assertEqual(item_builder("Tool", "Hammer", 10.50, 99), expected) +``` + +If we test the builder and input a name of "Tool", a description of "Hammer", a price of "10.5" and an _id of "99" we can expect and object to be created that matches this format. + +#### Integration + +An example integration test is included in the project. + +For integration tests we can test the RESTful endpoints. + +```python + def test_create_post_request_status(self): + response = requests.post(BASE_URL + '/create', json = {'name': 'Tool', 'description': 'Hammer', 'price': 10.5}) + self.assertEqual(response.status_code, status.HTTP_201_CREATED) +``` + +If we test the **Create** endpoint by sending a request with a method of `POST` and a path of `/create` we should expect the response to be... +Status code: 201, Status text: Created + +#### User Acceptance Testing + +This is similar to a 'black-box' system test as we are testing the front-end with no knowledge of the back-end. + +An example user acceptance test is included with this project. + +```gherkin +Scenario Outline: User adding a new item successfully + Given That a user is on the url "http://localhost:8080/index.html" + When The user enters the item name "", description "", and price "" into the CREATE section + And The user clicks the POST button + Then The READ ALL section will populate with JSON containing _id "<_id>", name "", description "", and price "" + Examples: + | name | description | price | _id | + | Test Name | Test Description | 9.99 | 1 | +``` + +A user story has been used to create a behaviour driven test for the system. + +**Given** that a user can access the front-end of the application +**When** they input correct details for an item +**And** they submit those details +**Then** the item is created and added to the database \ No newline at end of file diff --git a/documentation/README.md b/documentation/README.md new file mode 100644 index 0000000..4686c4b --- /dev/null +++ b/documentation/README.md @@ -0,0 +1,3 @@ +# DOCUMENTATION FOR SPRINT 1 + +This is our documentation. \ No newline at end of file diff --git a/features/environment.py b/features/environment.py index 9b5cf82..926864f 100644 --- a/features/environment.py +++ b/features/environment.py @@ -1,7 +1,7 @@ from selenium import webdriver def before_all(context): - context.browser = webdriver.Chrome(r"C:\Users\Admin\Desktop\lbg\webdrivers\chromedriver.exe") + context.browser = webdriver.Chrome(r"C:\Users\Admin\LBG-Python-API\webdrivers\chromedriver.exe") context.browser.maximize_window() def after_all(context): diff --git a/features/restapp.feature b/features/restapp.feature index 2e45e67..5678c33 100644 --- a/features/restapp.feature +++ b/features/restapp.feature @@ -8,3 +8,34 @@ Feature: Testing the REST application Examples: | name | description | price | _id | | Test Name | Test Description | 9.99 | 1 | + + Scenario Outline: User reading one item successfully + Given That a user is on the url "http://localhost:8080/index.html" + When The user enters the item _id "<_id>" into the GET ONE section + And The user clicks the GET One button + Then The READ ONE section will populate with JSON containing _id "<_id>", name "", description "", and price "" + Examples: + | name | description | price | _id | + | Test Name | Test Description | 9.99 | 1 | + + Scenario Outline: User updating one item successfully + Given That a user is on the url "http://localhost:8080/index.html" + When The user enters the item _id "<_id>", name "", description "", and price "" into the UPDATE section + And The user clicks the PUT button + And The user enters the item _id "<_id>" into the GET ONE section + And The user clicks the GET One button + Then The READ ONE section will populate with JSON containing _id "<_id>", name "", description "", and price "" + Examples: + | name | description | price | _id | + | Updated Name | Updated Description | 99.99 | 1 | + + Scenario Outline: User deleting one item successfully + Given That a user is on the url "http://localhost:8080/index.html" + When The user enters the item _id "<_id>" into the DELETE section + And The user clicks the DELETE button + And The user enters the item _id "<_id>" into the GET ONE section + And The user clicks the GET One button + Then The READ ONE section will be empty + Examples: + | _id | + | 1 |