The customers resource is a representation of the customer accounts of the eCommerce site
- The app (dev): https://nyu-customer-service-f20.us-south.cf.appdomain.cloud
- Swagger docs: https://nyu-customer-service-f20.us-south.cf.appdomain.cloud/apidocs
- The app (prod): https://nyu-customer-service-f20-prod.us-south.cf.appdomain.cloud/
- Swagger docs: https://nyu-customer-service-f20-prod.us-south.cf.appdomain.cloud/apidocs
| HTTP Method | URL | Description | Return |
|---|---|---|---|
GET |
/customers/{id} |
Get customer by ID | Customer Object |
GET |
/customers |
Returns a list of all the Customers | Customer Object |
POST |
/customers |
Creates a new Customer record in the database | Customer Object |
PUT |
/customers/{id} |
Updates a Customer record in the database | Customer Object |
PUT |
/customers/{id}/suspend |
Suspend the Customer with the given id number | Customer Object |
DELETE |
/customers/{id} |
Delete the Customer with the given id number | 204 Status Code |
| Fields | Type | Description |
|---|---|---|
| id | Integer | Id generated by database |
| first_name | String | Customer's first name |
| last_name | String | Customer's last_name |
| String | Customer's email | |
| address | String | Customer's address |
| active | Boolean | Is customer's account active |
Filter by:
- First Name
- Last Name
- Address
- Active Status
The easiest way to setup the environment is with Vagrant and VirtualBox. if you don't have this software the first step is down download and install it.
Download VirtualBox
Download Vagrant
Then all you have to do is clone this repo and invoke vagrant:
git clone https://github.com/nyu-devops-team/customers.git
cd customers
vagrant up
vagrant ssh
cd /vagrantWhen you are done, you can exit and shut down the vm with:
$ exit
$ vagrant haltIf you make changes to the Vagrantfile after the virtual machine (VM) is already created, you can reprovision the VM:
$ exit
$ vagrant reload --provision
$ vagrant sshAfter launching the virtual machine through vagrant, you can log into IBM Cloud Foundry:
$ ibmcloud login -a https://cloud.ibm.com --apikey @~/.bluemix/apiKey.json -r us-south -o <username>@nyu.edu -s devYou should have created and downloaded an IBM API key and saved it to you ~/.bluemix folder:
$ mkdir ~/.bluemix/
$ mv ~/Downloads/apikey.json ~/.bluemix/apiKey.jsonInstall the necessary packages by running:
$ cd /vagrant
$ pip install -r requirements.txtCreate a .env file in the directory and add the content from: https://github.com/nyu-devops-team/customers/blob/data-model/dot-env-example
Then you can run the Flask app:
$ flask run --host=0.0.0.0Note: since you are running the service inside a virtual machine, you have to set the host to a public server so that the service can be accessible outside of the VM.
If the Procfile is set up, you do not need to create the .env file in order to run the apply. You just run using:
$ honcho startRun the tests using nose
$ nosetestsNose is configured via the included setup.cfg file to automatically include the flags --with-spec --spec-color so that red-green-refactor is meaningful. If you are in a command shell that supports colors, passing tests will be green while failing tests will be red.
Nose is also configured to automatically run the coverage tool and you should see a percentage of coverage report at the end of your tests. If you want to see what lines of code were not tested use:
$ coverage report -mThis is particularly useful because it reports the line numbers for the code that is not covered so that you can write more test cases to get higher code coverage.
You can also manually run nosetests with coverage (but setup.cfg does this already)
$ nosetests --with-coverage --cover-package=serviceTry and get as close to 100% coverage as you can.
You can also manually run nosetests with the s flag to spit out debug print statements even when all test cases pass
$ nosetests -sIt's also a good idea to make sure that your Python code follows the PEP8 standard. flake8 has been included in the requirements.txt file so that you can check if your code is compliant like this:
$ flake8 --count --max-complexity=10 --statistics model,serviceI've also include pylint in the requirements. If you use a programmer's editor like Atom.io you can install plug-ins that will use pylint while you are editing. This catches a lot of errors while you code that would normally be caught at runtime. It's a good idea to always code with pylint active.
$ pylint service
$ pylint tests