Coder Social home page Coder Social logo

dggjsc / lab-flask-bdd Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nyu-devops/lab-flask-bdd

0.0 0.0 0.0 376 KB

NYU DevOps lab on Behavior Driven Development with Flask and Behave

License: Apache License 2.0

Shell 0.05% JavaScript 8.62% Python 78.93% Makefile 1.08% HTML 5.93% Dockerfile 1.22% Gherkin 4.07% Procfile 0.09%

lab-flask-bdd's Introduction

Lab: Python Flask Behavior Driven Development

Build Status Build Status Open in Remote - Containers

This repository is a lab from the NYU DevOps and Agile Methodologies graduate course CSCI-GA.2820-001 on Behavior Driven Development with Flask and Behave

The sample code is using Flask microframework and is intended to test the Python support on IBM Cloud environment which is based on Cloud Foundry. It also uses PostgreSQL as a database.

Introduction

One of my favorite quotes is:

โ€œIf it's worth building, it's worth testing. If it's not worth testing, why are you wasting your time working on it?โ€

As Software Engineers we need to have the discipline to ensure that our code works as expected and continues to do so regardless of any changes, refactoring, or the introduction of new functionality.

This lab introduces Test Driven Development using PyUnit and nose. It also explores the use of using RSpec syntax with Python through the introduction of the compare library that introduces the expects statement to make test cases more readable.

It also introduces Behavior Driven Development using Behave as a way to define Acceptance Tests that customer can understand and developers can execute!

Prerequisite Software Installation

This lab uses Docker and Visual Studio Code with the Remote Containers extension to provide a consistent repeatable disposable development environment for all of the labs in this course.

You will need the following software installed:

All of these can be installed manually by clicking on the links above or you can use a package manager like Homebrew on Mac of Chocolatey on Windows.

Alternately, you can use Vagrant and VirtualBox to create a consistent development environment in a virtual machine (VM).

You can read more about creating these environments in my article: Creating Reproducable Development Environments

Bring up the development environment

To bring up the development environment you should clone this repo, change into the repo directory:

$ git clone https://github.com/nyu-devops/lab-flask-bdd.git
$ cd lab-flask-bdd

Depending on which development environment you created, pick from the following:

Start developing with Visual Studio Code and Docker

Open Visual Studio Code using the code . command. VS Code will prompt you to reopen in a container and you should say yes. This will take a while as it builds the Docker image and creates a container from it to develop in.

$ code .

Note that there is a period . after the code command. This tells Visual Studio Code to open the editor and load the current folder of files.

Once the environment is loaded you should be placed at a bash prompt in the /app folder inside of the development container. This folder is mounted to the current working directory of your repository on your computer. This means that any file you edit while inside of the /app folder in the container is actually being edited on your computer. You can then commit your changes to git from either inside or outside of the container.

Manually running the Tests

This repository has both unit tests and integration tests. You can now run nosetests and behave to run the TDD and BDD tests respectively.

Test Driven Development (TDD)

This repo also has unit tests that you can run nose

nosetests

Nose is configured 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.

Behavior Driven Development (BDD)

These tests require the service to be running becasue unlike the the TDD unit tests that test the code locally, these BDD intagration tests are using Selenium to manipulate a web page on a running server.

Run the tests using behave

Start the server in a separate bash shell:

honcho start

Then start behave in your original bash shell:

behave

What's featured in the project?

./service/routes.py -- the main Service using Python Flask
./service/models.py -- the data models for persistence
./service/utils -- a collection of status, error handlers and logging setup
./tests/test_routes.py -- unit test cases for the server
./tests/test_models.py -- unit test cases for the model
./features/pets.feature -- Behave feature file
./features/steps/web_steps.py -- Behave step definitions

License

Copyright (c) John Rofrano. All rights reserved.

Licensed under the Apache License. See LICENSE

This repository is part of the NYU graduate class CSCI-GA.2810-001: DevOps and Agile Methodologies taught by John Rofrano, Adjunct Instructor, NYU Courant Institute, Graduate Division, Computer Science.

lab-flask-bdd's People

Contributors

rofrano avatar shcai97 avatar snyk-bot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.