Exemplo n.º 1
0
    def setUpClass(cls):
        # Suppress logging to keep unittest output clean
        import logging
        logger = logging.getLogger('werkzeug')
        logger.setLevel(logging.ERROR)

        # start Firefox
        try:
            cls.client = webdriver.Firefox()
        except Exception as e:
            print e
            logging.critical(
                'Could not start Firefox browser for running '
                'selenium tests. Error{error}'.format(error=e.message))

        # skip the tests if browser is not launched
        if cls.client:
            # Create application
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            # Empty any data if present
            MyBot.objects.delete()
            Message.objects.delete()

            MyBot.drop_collection()
            Message.drop_collection()

            # Populate database
            MyBot.generate_fake(5)
            Message.generate_fake(100)

            # start flask server in another thread.
            threading.Thread(target=cls.app.run).start()
Exemplo n.º 2
0
    def tearDownClass(cls):
        if cls.client:
            # Stop the flask server and close the browser
            cls.client.get('http://localhost:5000/web/shutdown')
            cls.client.close()
            # Remove all data
            MyBot.objects.delete()
            Message.objects.delete()

            MyBot.drop_collection()
            Message.drop_collection()
            # Remove application context
            cls.app_context.pop()
Exemplo n.º 3
0
 def tearDown(self):
     # Drop all collections
     MyBot.drop_collection()
     Message.drop_collection()
     self.app_context.pop()