コード例 #1
0
    def test_initial_search(self):
        gnip_search_client = GnipSearchClient()

        from_date = gnip_search_client.create_start_time()
        to_date = gnip_search_client.move_date_forward_by(from_date, 01, 01, 01)

        from_date = gnip_search_client.convert_date_to_gnip_format(from_date)
        to_date = gnip_search_client.convert_date_to_gnip_format(to_date)

        # open context to patch
        with HTTMock(self.gnip_mock):
            gnip_search_client.initial_search('Fake_Query', 10, from_date, to_date, 2)

        saved_json_blob_1 = gnip_search_client.load_json_blob(0)
        saved_json_blob_2 = gnip_search_client.load_json_blob(1)
        expected_json_blob_1 = json.loads('{"results": [{"id": 123}],"next": "fake_next_token"}')
        expected_json_blob_2 = json.loads('{"results": [{"id": 123}],"next": "fake_next_token"}')
        self.assertEqual(saved_json_blob_1, expected_json_blob_1)
        self.assertEqual(saved_json_blob_2, expected_json_blob_2)

        file_to_remove_1 = os.getcwd() + '/Gnip_Client/Gnip_Search_0.json'
        file_to_remove_2 = os.getcwd() + '/Gnip_Client/Gnip_Search_1.json'
        os.remove(file_to_remove_1)
        os.remove(file_to_remove_2)

        with HTTMock(self.gnip_mock_no_next):
            gnip_search_client.initial_search('Fake_Query', 10, from_date, to_date, 1)

        saved_json_blob_1 = gnip_search_client.load_json_blob(2)
        expected_json_blob_1 = json.loads('{"results": [{"id": 123}]}')
        self.assertEqual(saved_json_blob_1, expected_json_blob_1)

        file_to_remove_3 = os.getcwd() + '/Gnip_Client/Gnip_Search_2.json'
        os.remove(file_to_remove_3)
コード例 #2
0
 def test_create_start_time(self):
     gnip_search_client = GnipSearchClient()
     expected = datetime(2016, 04, 14, 02, 30)
     self.assertEqual(expected, gnip_search_client.create_start_time())