Exemplo n.º 1
0
 def test_fake_bot_generation(self):
     # Generate fake bots
     MyBot.generate_fake(5)
     self.assertEqual(MyBot.objects.count(), 5)
     bot = MyBot.objects.first()
     self.assertTrue(bot.test_bot)
     self.assertEqual(len(bot.token), 64)
Exemplo n.º 2
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.º 3
0
 def test_delete_all_bots(self):
     MyBot.generate_fake(10)
     response = self.client.delete(url_for('botapi.delete_all_bots'),
                                   headers=self.get_api_headers())
     self.assertEqual(response.status_code, 200)
     json_response = json.loads(response.data.decode('utf-8'))
     self.assertEqual(json_response['status'], 'success')
     count = MyBot.objects.count()
     self.assertEqual(count, 0)
     self.assertTrue(str(10) in json_response['message'])
Exemplo n.º 4
0
    def test_filter_messages_using_botid(self):
        # Add some dummy messages
        MyBot.generate_fake(1)
        Message.generate_fake(5)
        bot = MyBot(bot_id=11111, token='dummy-token', test_bot=True).save()
        self.assertIsNotNone(bot)
        for _ in range(3):
            Message(bot_id=bot.bot_id).save()
        self.assertEqual(Message.objects.count(), 5 + 3)

        # Get filtered messages
        response = self.client.get(url_for('botapi.filter_messages',
                                           botid=bot.bot_id,
                                           time_off=0,
                                           text='#',
                                           username='******',
                                           name='#'),
                                   headers=self.get_api_headers())
        self.assertEqual(response.status_code, 200)
        json_response = json.loads(response.data.decode('utf-8'))
        self.assertEqual(json_response['result'], 'success')
        self.assertEqual(len(json_response['messages']), 3)
Exemplo n.º 5
0
 def test_generate_fake_message(self):
     MyBot.generate_fake(1)  # Generate a fake bot to associate messages.
     Message.generate_fake(10)
     msgs = Message.objects.all()
     self.assertEqual(len(msgs), 10)