Skip to content

Commit

Permalink
Merge pull request #120 from NYU-DevOps-Spring2018-Orders/please-behave
Browse files Browse the repository at this point in the history
Please behave
  • Loading branch information
andyd0 authored May 2, 2018
2 parents 6fda024 + 21d574a commit ad14ae0
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 18 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Our team handled the order process of a retail website. Functions are built to

## Structure

- Two classes Order and Item. An Item object represents an item from an associated order.
- Two classes Order and Item. An Item object represents an item from an associated order.
- Order: id (auto generated), customer_id, status, date
- Item: id (auto generated), product_id, order_id, name, quantity, price
- Status has 3 states - processing (initial state), cancelled, shipped
Expand Down Expand Up @@ -46,7 +46,8 @@ After the required software is installed, you can start up the orders service by
vagrant up
vagrant ssh
cd /vagrant

export DATABASE_URI='mysql+pymysql://root:passw0rd@localhost:3306/test'

Then run the following command while running the VM...

python server.py
Expand All @@ -59,21 +60,21 @@ Note there is a test json with the expected fields for the service...

## REST API Functions

- CREATE - takes the JSON and creates the order and item details for their respective tables
- `POST http://localhost:5000/orders`
- GET - Gets the details of a specific order
- CREATE - takes the JSON and creates the order and item details for their respective tables
- `POST http://localhost:5000/orders`
- GET - Gets the details of a specific order
- `GET http://localhost:5000/orders/{id}`
- GET - Get details of a specific item:
- GET - Get details of a specific item:
- `GET http://localhost:5000/items/{id}`
- LIST - All orders in the system:
- LIST - All orders in the system:
- `GET http://localhost:5000/orders`
- LIST - All items in the system:
- LIST - All items in the system:
- `GET http://localhost:5000/items`
- LIST - Items from a specified order:
- LIST - Items from a specified order:
- `GET http://localhost:5000/orders/{id}/items`
- DELETE - deletes an order and its items:
- DELETE - deletes an order and its items:
- `DELETE http://localhost:5000/orders/{id}`
- DELETE - deletes an item from an order:
- DELETE - deletes an item from an order:
- `DELETE http://localhost:5000/orders/{id}/items/{id}`
- ACTION - cancel an order:
- `PUT http://localhost:5000/orders/{id}/cancel`
Expand All @@ -90,4 +91,3 @@ Note there is a test json with the expected fields for the service...
## Testing

`nosetests` can be used after starting the VM and switching to the Vagrant directory. This checks coverage on both `models.py` and `server.py`. No argument needed regardless of Windows or MacOS

9 changes: 9 additions & 0 deletions app/static/js/rest_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ $(function () {
order = res[i];
var row = "<tr><td>"+order.id+"</td><td>"+order.customer_id+"</td><td>"+order.date+"</td><td>"+order.status+"</td></tr>";
$("#order_results").append(row);

if(i == 0) {
update_form_data(res[i]);
}
}

$("#order_results").append('</table>');
Expand Down Expand Up @@ -489,6 +493,11 @@ $(function () {
item = res[i];
var row = "<tr><td>"+item.id+"</td><td>"+item.order_id+"</td><td>"+item.product_id+"</td><td>"+item.name+"</td><"+"</td><td>"+item.quantity+"</td><td>"+"</td><td>"+item.price+"</td></tr>";
$("#item_results").append(row);

if(i == 0) {
update_item_form_data(res[i]);
$("#item_id").val(res[i].id);
}
}

$("#item_results").append('</table>');
Expand Down
100 changes: 99 additions & 1 deletion features/orders.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,102 @@ Scenario: Query an item
And I set the "item_name" to "laptop"
And I press the "search" item button
Then I should see the message "Success"
And I should see "72" in the item results
And I should see "72" in the item results

Scenario: Read an order
When I visit the "Home Page"
And I set the "order_customer_id" to "11"
And I press the "search" order Button
And I press the "retrieve" order Button
Then I should see "11" in the "order_customer_id" field
Then I should see "2018-01-25T09:30" in the "order_date" field
Then I should see "processing" in the "order_status" field
Then I should see the message "Success"

Scenario: Read an item
When I visit the "Home Page"
And I set the "item_name" to "laptop"
And I press the "search" item button
And I press the "retrieve" item Button
Then I should see "72" in the "item_product_id" field
Then I should see "laptop" in the "item_name" field
Then I should see "1" in the "item_quantity" field
Then I should see "999.32" in the "item_price" field
Then I should see the message "Success"

Scenario: Delete an item
When I visit the "Home Page"
And I set the "item_name" to "laptop"
And I press the "search" item button
And I press the "retrieve" item button
And I press the "delete" item button
Then I should see the message "Item has been Deleted!"

Scenario: Delete an order
When I visit the "Home Page"
And I set the "order_customer_id" to "11"
And I press the "search" order Button
And I press the "delete" order button
Then I should see the message "Order has been Deleted!"

Scenario: Update an item
When I visit the "Home Page"
And I set the "item_name" to "laptop"
And I press the "search" item button
And I press the "Retrieve" item button
Then I should see "1" in the "item_quantity" field
When I change "item_quantity" to "3"
And I press the "Update" item button
Then I should see the message "Success"
When I press the "Clear" item button
And I set the "item_name" to "laptop"
And I press the "search" item button
And I press the "Retrieve" item button
Then I should see "3" in the "item_quantity" field

Scenario: Update an order
When I visit the "Home Page"
And I set the "order_customer_id" to "11"
And I press the "search" order Button
And I press the "Retrieve" order button
Then I should see "processing" in the "order_status" field
When I change "order_status" to "shipped"
And I press the "Update" order button
Then I should see the message "Success"
When I press the "Clear" order button
And I set the "order_customer_id" to "11"
And I press the "search" order Button
And I press the "Retrieve" order button
Then I should see "shipped" in the "order_status" field

Scenario: Create a order
When I visit the "Home Page"
And I set the "item_product_id" to "214"
And I set the "item_name" to "banana"
And I set the "item_quantity" to "10"
And I set the "item_price" to "20.34"
When I press the "Create" item button
And I set the "item_product_id" to "78"
And I set the "item_name" to "laptop"
And I set the "item_quantity" to "1"
And I set the "item_price" to "642.34"
When I press the "Create" item button
And I set the "item_product_id" to "28"
And I set the "item_name" to "apple"
And I set the "item_quantity" to "100"
And I set the "item_price" to "60.24"
When I press the "Create" item button
And I set the "order_customer_id" to "123"
And I set the time "order_date" to "2018-02-27T19:35"
And I set the "order_status" to "processing"
When I press the "Create" order button
Then I should see the message "Success"
And I should not see "404 Not Found"

Scenario: Cancel a order
When I visit the "Home Page"
And I set the "order_customer_id" to "11"
And I press the "search" order Button
And I press the "Cancel" order button
Then I should see "cancelled" in the "order_status" field
And I should see the message "Order has been Canceled!"
4 changes: 2 additions & 2 deletions features/steps/order_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def step_impl(context, message):
def step_impl(context, element_name, text_string):
element_id = element_name.lower()
element = context.driver.find_element_by_id(element_id)
element.clear()
# element.clear()
element.send_keys(text_string)

@when(u'I set the time "{element_name}" to "{text_string}"')
Expand Down Expand Up @@ -155,5 +155,5 @@ def step_impl(context, element_name, text_string):
element = WebDriverWait(context.driver, WAIT_SECONDS).until(
expected_conditions.presence_of_element_located((By.ID, element_id))
)
element.clear()
# element.clear()
element.send_keys(text_string)
2 changes: 1 addition & 1 deletion tests/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def test_find_by_price(self):
self.assertEqual(items[0].name, "hammer")
self.assertEqual(items[0].quantity, 2)
self.assertEqual(items[0].price, 11)

def test_non_dict_raises_error(self):
""" Pass invalid data structure deserialize """
data = [1,2,3]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_get_an_order(self):

date_converted = str(date.year) + "-" + str(date.month) + "-" + str(date.day) + "T" + \
str(date.hour) + ":" + str(date.minute)

date_converted = datetime.strptime(date_converted, "%Y-%m-%dT%H:%M")

order = Order(customer_id=1, date=date_converted, status = 'processing')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def setUp(self):
date = datetime.now()


order = Order(customer_id=1, date=date, status = 'processing').save()
order = Order(customer_id=1, date=date, status = 'processing').save()
order = Order(customer_id=2, date=date, status = 'processing').save()

order1 = Order()
Expand Down

0 comments on commit ad14ae0

Please sign in to comment.