Ejemplo n.º 1
0
    def setUp(self):
        self.access_token = "a"
        self.account_id = "b"
        self.alert_id = "c"
        self.mention_id = "d"

        self.client = mention.CurateAMentionAPI(self.access_token,
                                                self.account_id, self.alert_id,
                                                self.mention_id)
Ejemplo n.º 2
0
    def test_query_mention_id_error(self, mock_requests_get):
        # assert mention 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.CurateAMentionAPI(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())
Ejemplo n.º 3
0
    def test_query_account_id_error(self, mock_requests_get):
        # assert account ID error response
        unsuccessful_response = {
            'code': 403,
            'message': 'You are not allowed to access this account'
        }

        with open("api_keys.json", "r") as read_file:
            self.access_token = json.load(read_file)["access_token"]
            self.client = mention.CurateAMentionAPI(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())
Ejemplo n.º 4
0
    def test_query_success(self, mock_requests_get):
        # assert successful response
        with open("testcuratemention.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.CurateAMentionAPI(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["mention"]["description"],
                         self.client.query()["mention"]["description"])