Skip to content
55 changes: 54 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,57 @@ In a new terminal window use the command

~~~ bash
behave .\features\restapp.feature
~~~
~~~

### 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 "<name>", description "<description>", and price "<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 "<name>", description "<description>", and price "<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
3 changes: 3 additions & 0 deletions documentation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# DOCUMENTATION FOR SPRINT 1

This is our documentation.
2 changes: 1 addition & 1 deletion features/environment.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
31 changes: 31 additions & 0 deletions features/restapp.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<name>", description "<description>", and price "<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 "<name>", description "<description>", and price "<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 "<name>", description "<description>", and price "<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 |