def test_webhook_already_exists(self, m):
        m.get(
            "https://api.ciscospark.com/v1/webhooks",
            json=MockTeamsAPI.list_webhooks_exist(),
        )
        m.post(
            "https://api.ciscospark.com/v1/webhooks",
            json=MockTeamsAPI.create_webhook(),
        )

        bot_email = "*****@*****.**"
        teams_token = "somefaketoken"
        bot_url = "http://fakebot.com"
        bot_app_name = "testbot"
        # Create a new bot
        bot = TeamsBot(
            bot_app_name,
            teams_bot_token=teams_token,
            teams_bot_url=bot_url,
            teams_bot_email=bot_email,
            debug=True,
        )

        # Add new command
        bot.add_command("/dosomething", "help for do something",
                        self.do_something)
        bot.testing = True
        self.app = bot.test_client()
    def test_bad_config_raises_valueerror(self, m):
        with self.assertRaises(ValueError):
            m.get(
                "https://api.ciscospark.com/v1/webhooks",
                json=MockTeamsAPI.list_webhooks_exist(),
            )
            m.post(
                "https://api.ciscospark.com/v1/webhooks",
                json=MockTeamsAPI.create_webhook(),
            )

            bot_email = None
            teams_token = "somefaketoken"
            bot_url = "http://fakebot.com"
            bot_app_name = "testbot"
            # Create a new bot
            bot = TeamsBot(
                bot_app_name,
                teams_bot_token=teams_token,
                teams_bot_url=bot_url,
                teams_bot_email=bot_email,
                debug=True,
            )

            # Add new command
            bot.add_command("/dosomething", "help for do something",
                            self.do_something)
            bot.testing = True
            self.app = bot.test_client()
    def test_process_incoming_membership_check_sender_pass(self, m):
        m.get('https://api.ciscospark.com/v1/webhooks',
              json=MockTeamsAPI.list_webhooks())
        m.post('https://api.ciscospark.com/v1/webhooks',
               json=MockTeamsAPI.create_webhook())
        m.post('//api.ciscospark.com/v1/messages', json={})
        bot_email = "*****@*****.**"
        teams_token = "somefaketoken"
        bot_url = "http://fakebot.com"
        bot_app_name = "testbot"
        # Create a new bot
        bot = TeamsBot(bot_app_name,
                       teams_bot_token=teams_token,
                       teams_bot_url=bot_url,
                       teams_bot_email=bot_email,
                       debug=True,
                       webhook_resource="memberships",
                       webhook_event="all")

        # Add new command
        bot.add_command('memberships', '*', self.check_membership)
        bot.testing = True
        self.app = bot.test_client()

        resp = self.app.post('/',
                             data=MockTeamsAPI.incoming_membership_pass(),
                             content_type="application/json")
        self.assertEqual(resp.status_code, 200)
        print(resp.data)
        self.assertIn(b"success", resp.data)