Giter VIP home page Giter VIP logo

test.helper.gae's Introduction

Class for autotests GoogleAppEngine Standard Environment Python2.7 apps

GitHub Workflow Status Codacy Badge Codacy Badge

Install

pip install tester-gae

Usage in tests

from google.appengine.ext import ndb
from google.appengine.api.taskqueue import Queue, Task

from tester_gae import TestGae


class TestTable(ndb.Model):
    """
    GAE datatsore table
    """
    date = ndb.DateTimeProperty(auto_now_add=True)


class TestGaeApp(TestGae):
    """
    test GAE app
    """
    def setUp(self):
        TestGae.setUp(self, "path/to/you/gae/app/dir")  # where app.yaml located
        self.queue = Queue('default')
        self.queue.add(Task('xxx', url='/'))

    def test_check_db_tables(self):
        """
        check db table items count
        """
        self.check_db_tables([
          (TestTable, 0),
        ])

        item = TestTable()
        item.put()

        self.check_db_tables([
          (TestTable, 1),
        ])

    def test_queue(self):
        """
        check for number of tasks in queue
        """
        self.assert_tasks_num(1)
        tasks = self.gae_tasks(queue_name='default', flush_queue=False)

        self.assertEqual(len(tasks), 1)
        self.assert_tasks_num(1)

        tasks = self.gae_tasks(queue_name='default', flush_queue=True)
        self.assertEqual(len(tasks), 1)
        self.assert_tasks_num(0)

    def test_flask_execute(self):
        """
        execute queue in fask app context
        """
        from flask import Flask
        app = Flask(__name__)
        app.config['TESTING'] = True

        @app.route('/', methods=['POST'])
        def root_page():
            """
            flask view
            """
            return 'OK'

        client = app.test_client()

        data = self.gae_tasks_dict()
        assert len(data) == 1
        task = data[data.keys()[0]]

        self.gae_task_flask_execute(task, client, is_delete=False, is_debug_print=True)
        data = self.gae_tasks_dict()
        assert len(data) == 1

        self.gae_task_flask_execute(task, client, is_debug_print=True)
        data = self.gae_tasks_dict()
        assert not data

        self.queue.add(Task('xxx', url='/'))

        self.gae_queue_flask_execute(client)
        data = self.gae_tasks_dict()
        assert not data

    def test_dict(self):
        """
        get queue content as dict
        """
        data = self.gae_tasks_dict()
        assert len(data) == 1
        assert 'task1' in data

    def test_dump(self):
        """
        dump queue content
        """
        self.gae_queue_dump()
        self.gae_queue_dump(fields=['name', 'url'])

test.helper.gae's People

Contributors

vb64 avatar

Watchers

 avatar  avatar  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.