public function testIngest() { $response = array('response_code' => 200, 'data' => array('accepted' => 1, 'total_message_bytes' => 1788), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $data_set = '[{"id": "234", "body": "yo"}]'; $source_id = '1f1be6565a1d4ef38f9f4aeec9554440'; $ingest = new DataSift_ODP($this->user, $source_id); $response = $ingest->ingest($data_set); $this->assertEquals($response['accepted'], 1, 'Not accepted'); }
/** * @dataProvider deleteLimitProvider * @covers Datasift_Account_Identity_Limit::delete */ public function testDeleteLimit($identityId, $service, $apiResult, $expectedResult) { $identityLimit = new DataSift_Account_Identity_Limit($this->_user); DataSift_MockApiClient::setResponse($apiResult); }
public function testSample() { $response = array('response_code' => 200, 'data' => array('interactions' => array('interaction' => array('subtype' => 'reshare', 'content' => 'baz the map could'), 'fb' => array('media_type' => 'post', 'content' => 'baz the map could, ', 'language' => 'en', 'topics_ids' => 565634324))), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $pylon = new DataSift_Pylon($this->user, array('id' => '1a4268c9b924d2c48ed1946d6a7e6272')); $filter = '(fb.content any "coffee" OR fb.hashtags in "tea") AND fb.language in "en"'; $start = 1445209200; $end = 1445274000; $count = 10; $sample = $pylon->sample($filter, $start, $end, $count); $this->assertEquals($sample['interactions']['fb']['content'], 'baz the map could, ', 'Interaction content didnt match'); }
public function testAddRemoveResource() { $source = $this->createSource(); $new_resource = array('parameters' => array('url' => 'http://www.facebook.com/thesun', 'title' => 'The Sun', 'id' => 10513536389)); $response = array('response_code' => 200, 'data' => array('resources' => array(array('resource_id' => '30bc448896de44b88604ac223cb7f26f', 'status' => 'valid', 'parameters' => array('url' => 'http://www.facebook.com/theguardian', 'title' => 'The Guardian', 'id' => 10513336322)), $new_resource)), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $source->addResource($new_resource); $resources = $source->getResources(); $this->assertCount(2, $source->getResources(), 'Expecting 2 auth objects to be returned'); $this->assertArrayHasKey('id', $resources[0]['parameters'], 'First auth had no ID'); $this->assertArrayHasKey('id', $resources[1]['parameters'], 'Second auth had no ID'); //Now remove the original auth $response = array('response_code' => 200, 'data' => array('resources' => array($new_resource)), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $resources = $source->getResources(); $source->removeResource(array('30bc448896de44b88604ac223cb7f26f')); $this->assertCount(1, $source->getResources(), 'Expecting 1 auth object to be returned'); $this->assertArrayHasKey('id', $resources[0]['parameters'], 'First auth had no ID'); }
public function testStart() { $historic = $this->user->createHistoric(testdata('definition_hash'), testdata('historic_start_date'), testdata('historic_end_date'), testdata('historic_sources'), testdata('historic_name')); $response = array('response_code' => 200, 'data' => array('dpus' => testdata('historic_dpus'), 'id' => testdata('historic_playback_id'), 'availability' => testdata('historic_availability')), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $historic->prepare(); $this->set204Response(); $historic->start(); }
public function testGetDPUBreakdownOnInvalidDefinition() { $def = new DataSift_Definition($this->user, testdata('invalid_definition')); $this->assertEquals($def->get(), testdata('invalid_definition')); $response = array('response_code' => 400, 'data' => array('error' => 'The target interactin.content does not exist'), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); try { $def->getDPUBreakdown(); $this->fail('CompileFailed exception expected, but not thrown'); } catch (DataSift_Exception_InvalidData $e) { // Check the error message $this->assertEquals($e->getMessage(), $response['data']['error']); } catch (DataSift_Exception_APIError $e) { $this->fail('APIError: ' . $e->getMessage() . ' (' . $e->getCode() . ')'); } catch (Exception $e) { $this->fail('Unhandled exception: ' . $e->getMessage() . ' (' . $e->getCode() . ')'); } }
public function testGetUsageApiErrors() { // Bad request from user supplied data try { $response = array('response_code' => 400, 'data' => array('error' => 'Bad request from user supplied data'), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $usage = $this->user->getUsage(); // Should have had an exception $this->fail('Expected DataSift_Exception_InvalidData exception did not get thrown'); } catch (DataSift_Exception_InvalidData $e) { $this->assertEquals($response['data']['error'], $e->getMessage(), 'Bad request from user supplied data'); } // Unauthorised or banned try { $response = array('response_code' => 401, 'data' => array('error' => 'User banned because they are a very bad person'), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $usage = $this->user->getUsage(); // Should have had an exception $this->fail('Expected ApiError exception did not get thrown'); } catch (DataSift_Exception_AccessDenied $e) { $this->assertEquals($response['data']['error'], $e->getMessage(), '401 exception message is not as expected'); } // Endpoint or data not found try { $response = array('response_code' => 404, 'data' => array('error' => 'Endpoint or data not found'), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $usage = $this->user->getUsage(); // Should have had an exception $this->fail('Expected ApiError exception did not get thrown'); } catch (DataSift_Exception_ApiError $e) { $this->assertEquals($response['data']['error'], $e->getMessage(), '404 exception message is not as expected'); } // Problem with an internal service try { $response = array('response_code' => 500, 'data' => array('error' => 'Problem with an internal service'), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $usage = $this->user->getUsage(); // Should have had an exception $this->fail('Expected ApiError exception did not get thrown'); } catch (DataSift_Exception_ApiError $e) { $this->assertEquals($response['data']['error'], $e->getMessage(), '500 exception message is not as expected'); } }
public function testSubscribeHistoric() { $historic = $this->user->createHistoric(testdata('definition_hash'), testdata('historic_start_date'), testdata('historic_end_date'), testdata('historic_sources'), testdata('historic_name')); $this->assertInstanceOf('DataSift_Historic', $historic, 'DataSift_Historic construction failed'); $this->assertEquals($historic->getStreamHash(), testdata('definition_hash'), 'Definition hash is incorrect'); $this->assertEquals($historic->getStartDate(), testdata('historic_start_date'), 'The start date is incorrect'); $this->assertEquals($historic->getEndDate(), testdata('historic_end_date'), 'The end date is incorrect'); $this->assertEquals($historic->getSources(), testdata('historic_sources'), 'The sources are incorrect'); $this->assertEquals($historic->getName(), testdata('historic_name'), 'The name is incorrect'); $this->assertEquals($historic->getSample(), 100, 'The default sample rate is incorrect'); $response = array('response_code' => 200, 'data' => array('dpus' => testdata('historic_dpus'), 'id' => testdata('historic_playback_id'), 'availability' => testdata('historic_availability')), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $historic->prepare(); $this->assertEquals($historic->getHash(), testdata('historic_playback_id'), 'The playback ID is incorrect'); $this->assertEquals($historic->getDPUs(), testdata('historic_dpus'), 'The DPU cost is incorrect'); $this->assertEquals($historic->getAvailability(), testdata('historic_availability'), 'The availability data is incorrect'); $this->configurePushDefinition(); $this->setResponseToASubscription(); $subscription = $this->pd->subscribeHistoric($historic, testdata('push_name')); $this->checkSubscription($subscription); }
public function testGetUsage() { $response = array('response_code' => 200, 'data' => array('start' => date('Y-m-d H:i:s', time()), 'end' => date('Y-m-d H:i:s', time()), 'streams' => array('stream1', 'stream2')), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $usage = $this->user->getUsage(); $this->assertTrue(isset($usage['start']), 'Usage data does not contain a start date'); $this->assertTrue(isset($usage['end']), 'Usage data does not contain a start date'); $this->assertInternalType('array', $usage['streams'], 'Usage data does not contain a valid stream array'); }
/** * Set the response object * * @param object $r Response * * @return void */ public static function setResponse($r) { self::$_response = $r; }