- Add order (decorator to check vip and remaining stocks)
- Delete order (decorator to check remaining stocks)
- Show top 3 popular products
- Save csv file at 00:00
- Use Docker
- Deploy project
- Unit test
test
├── csv_dump.py # Store csv file
├── data.csv # csv file: Number of orders, sales figures, Total sales
├── manage.py
├── mysite
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── new_app
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── decorator.py # decorator function
│ ├── migrations
│ ├── models.py
│ ├── static
│ │ ├── css
│ │ │ └── style.css
│ │ ├── img
│ │ │ ├── cart.ico
│ │ │ ├── minus.png
│ │ │ └── plus.png
│ │ └── js
│ │ └── top3-button.js # javascript(ajax)
│ ├── templates
│ │ └── page.html
│ ├── tests.py # Unit test
│ ├── urls.py
│ └── views.py
└── script
├── create-app
├── insert_data.py
├── insert_data_script # insert stocks into sqlite
└── start-server # do migrations, unit test, and run app
See repository Django-docker-test and follow the instructions to install docker and create docker image.
Use Sqlite
TODO: Secure private data
# start container
cd <DOCKER_REPO_DIR>/docker
./project-start-container
# enter container
./project-enter-container-shell
# run app
cd <DJANGO_PROJECT_DIR>/script
./start-server
driver = webdriver.Firefox(options=options) # Use Selenium.webdriver
...
driver.find_element_by_id('image-btn').click() # Click Plus buttonself.assertEqual(queried_order.product_id, product[0])
# Test assertions
self.assertEqual(queried_order.qty, product[1])
self.assertEqual(queried_order.price, product[2])
self.assertEqual(queried_order.shop_id, product[3])
self.assertEqual(queried_order.customer_id, 'ABC')...
...
self.assertIn('你不是vip', driver.page_source) # Test assertion
# Buy more than stock (stock_pcs+1)
driver.find_element_by_id('product_number').send_keys(str(product[1]+1))
...
self.assertIn('貨源不足', driver.page_source) # Test assertion
# Test assertion
self.assertEqual(len(Order.objects.all()), 0)
self.assertIn('商品到貨', driver.page_source)