nyu-devops-team / customers

The customers resource is a representation of the customer accounts of the eCommerce site
2 stars 1 forks source link

customers

Build Status codecov

The customers resource is a representation of the customer accounts of the eCommerce site

API Documentation

URLs

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

Customer Object

Fields Type Description
id Integer Id generated by database
first_name String Customer's first name
last_name String Customer's last_name
email String Customer's email
address String Customer's address
active Boolean Is customer's account active

Queries Supported

Filter by:

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 /vagrant

When you are done, you can exit and shut down the vm with:

    $ exit
    $ vagrant halt

Reprovisioning the VM

If you make changes to the Vagrantfile after the virtual machine (VM) is already created, you can reprovision the VM:

    $ exit
    $ vagrant reload --provision
    $ vagrant ssh

Logging into Cloud Foundry

After 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 dev

You should have created and downloaded an IBM API key and saved it to you ~/.bluemix folder:

  $ mkdir ~/.bluemix/
  $ mv ~/Downloads/apikey.json ~/.bluemix/apiKey.json

Manually Installing Requirements

Install the necessary packages by running:

    $ cd /vagrant
    $ pip install -r requirements.txt

Running the Flask app

Create 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.0

Note: 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 start

Manually Running the Tests

Run the tests using nose

    $ nosetests

Nose 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 -m

This 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=service

Try 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 -s

It'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,service

I'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