Git Product home page Git Product logo

pytest-web2py.wip's Introduction

Pytest Plugin for Web2py

This repo is a work in progress for building a pytest plugin for web2py.

State and Goal

For now, pytest works, but one shall put the conftest files in the application directory.

The goal is to produce a fully independent pytest plugin.

Usage

Installation

Install requirements (preferably in a virtualenv):

pip install -r requirements.txt

Application configuration

Equip your application with the needed interfaces:

  • a specific database setup for tests,
  • a test controller to help setup and teardown database before each test (necessary for web and ui tests, as we only have acess to the application by the http protocol),

DB setup

We may want to tweak the database setup to improve the speed of unit tests. A typical setup in models/db.py may for example looks like :

UNIT_TESTING = False
if request.TEST_APP == 'd2c84025-5e33-442d-db12-9da661250e2d':
   TESTING = True
   UNIT_TESTING = True
else:
   import os.path
   TESTING = os.path.exists("/dev/shm/web2py_test/welcome/web2py_test_indicator")
if TESTING:
   if UNIT_TESTING:
      # fast in memory SQL for unit test
      db = DAL('sqlite:memory:', lazy_tables=True
               )  #
   else:
      db = DAL('sqlite://storage.sqlite'
               , migrate_enabled=True
               , lazy_tables=True)  # sqlite for minimal persistence
else:
   db = DAL(myconf.get('db.uri'),
            pool_size=myconf.get('db.pool_size'),
            migrate_enabled=myconf.get('db.migrate'),
            check_reserved=['all'])

tests controller

A controller is needed, whose name is defined by the test_controller fixture (default to tests), and shall contains a function empty_db which may looks like:

def empty_db():
   if TESTING:
      for t in db.tables:
         db[t].truncate('CASCADE')

Running tests

  • unit tests

    py.test --w2p-app=welcome --w2p-root=tests/web2py tests/unit-tests
  • webclient tests

    py.test --w2p-app=welcome --w2p-root=tests/web2py tests/web-tests/
  • UI tests TODO

  • all tests

    py.test --w2p-app=welcome --w2p-root=tests/web2py tests/

Writing Tests

Unit Tests

TODO

Webclient Tests

TODO

UI Tests (selenium)

TODO

Thanks

Some code and inspiration taken from https://github.com/viniciusban/web2py.test

Licence

To be defined, but probably something like MIT…

TODO

See the github issues

pytest-web2py.wip's People

Stargazers

Marlysson Silva avatar David Barrat avatar githubuser89 avatar

Watchers

James Cloos avatar  avatar Carlos Cesar Caballero Díaz avatar Marlysson Silva avatar Agano oasis avatar

pytest-web2py.wip's Issues

Document how to write tests

In addition to the examples in the test directory, we should add some documentation to explain how to write tests, and the known pitfall to avoid.

Documentation may explain how to

  • write simple test,
  • do mocking (for mail sending for example),
  • use of vcrpy to be able to replay test without a distant service,

Write more tests against latest web2py `welcome` application

The objectives are twofold:

  • having a better usage base and examples
  • add some tests for the web2py plugin (which may perhaps be integrated in the default test suite in a more or less near future). It may particularly be of interest for the area not well tested on web2py (for example, testing mail interaction with authentication in web2py is not easy today, and is easier with the help of pytest-web2py and mocking).

Define a "good" API

The way the test are written (with w fixtures, and call and form_post imported from the helper module) is mainly inherited from day to day patching in order to make test work.

The API shall certainly be think about a bit more to adjust to the need express by people.

The actual state of the API shall be documented first though.

Improve code quality

The code is not in a very good state.

  • long function shall be broken,
  • we may gain by using more OO concepts (for example make call a member of the result of the w fixture),
  • all functions and fixtures shall be documented (in order to be used by sphinx to produce autonomous documentation),

Write tests for the pytest-web2py plugin

Everything is to be done.
For now the plugin is only tested by running test against a web2py instance (kind of a minimum).

Not clear to me what is the best route to go, knowing the dependency to web2py.

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.