Beispiel #1
0
    def setUp(self):
        self.access_token = "a"
        self.account_id = "b"
        self.alert_id = "c"
        self.mention_id = "d"

        self.client = mention.FetchMentionChildrenAPI(self.access_token,
                                                      self.account_id,
                                                      self.alert_id,
                                                      self.mention_id)
Beispiel #2
0
    def test_query_mention_id_error(self, mock_requests_get):
        # assert alert ID error response
        unsuccessful_response = {'code': 404, 'message': 'no such mention'}

        with open("api_keys.json", "r") as read_file:
            jsonfile = json.load(read_file)
            self.access_token = jsonfile["access_token"]
            self.account_id = jsonfile["account_id"]
            self.alert_id = jsonfile["alert_id"]
            self.client = mention.FetchMentionChildrenAPI(
                self.access_token, self.account_id, self.alert_id,
                self.mention_id)

        response = type('response', (object, ),
                        {'text': json.dumps(unsuccessful_response)})

        mock_requests_get.return_value = response
        self.assertEqual(unsuccessful_response, self.client.query())
Beispiel #3
0
    def test_query_success(self, mock_requests_get):
        # assert successful response
        with open("testfetchmentionchildren.json", "r") as read_file:
            successful_response = json.load(read_file)

        with open("api_keys.json", "r") as read_file:
            jsonfile = json.load(read_file)
            self.access_token = jsonfile["access_token"]
            self.account_id = jsonfile["account_id"]
            self.alert_id = jsonfile["alert_id"]
            self.mention_id = jsonfile["mention_id"]
            self.client = mention.FetchMentionChildrenAPI(
                self.access_token, self.account_id, self.alert_id,
                self.mention_id)

        mock_requests_get.return_value = Mock(ok=True)
        mock_requests_get.return_value.json.return_value = successful_response

        response = type('response', (object, ),
                        {'text': json.dumps(successful_response)})

        self.assertEqual(successful_response, self.client.query())