def setUp(self): UICase.setUp(self) self.login() self.created_at = now() self.created_on_str = format_date(self.created_at) self.one_day_after_str = format_date(self.created_at + timedelta(days=1)) self.one_day_before_str = format_date(self.created_at - timedelta(days=1)) self.one_week_after_str = format_date(self.created_at + timedelta(days=7)) self.one_week_before_str = format_date(self.created_at - timedelta(days=7)) self.contents = ( 'I need a bike. I like Honda.', # needs, likes 'Can somebody recommend a sturdy laptop?', # consideration 'I need an affordabl laptop. And a laptop bag', # needs 'Whatever you buy, let it be an Apple laptop', # recommendation 'I would like to have a thin and lightweight laptop.', # needs 'Thank you very much!', # gratitude 'You\'re gonna end up with a broken laptop' # problem ) self.setup_posts()
def get_trends(self, **kw): created_at = now() one_day_after_str = format_date(created_at + timedelta(days=1)) one_day_before_str = format_date(created_at - timedelta(days=1)) params = { 'channel_id': str(self.inbound.id), 'from': one_day_before_str, 'to': one_day_after_str, 'level': 'hour', 'topics': [{ 'topic': 'laptop', 'topic_type': 'node' }], 'intentions': ['needs'] or kw['intentions'], } params.update(kw) trends = self._fetch('/trends/json', **params) return trends
def test_matching_sentiments(self): params = { 'channel_id': self.channel_id, 'from': format_date(self.post.created), 'level': 'day', 'parent_topic': 'bag', 'sentiments': ['negative'] } results = self.make_request(params) self.assertEqual(len(results), 1) self.assertEqual(results[0]['topic'], 'laptop bag')
def test_matching_intentions(self): params = { 'channel_id': self.channel_id, 'from': format_date(self.post.created), 'level': 'day', 'parent_topic': 'bag', 'intentions': ['problem', 'asks'] } results = self.make_request(params) self.assertEqual(len(results), 1) self.assertEqual(results[0]['topic'], 'laptop bag')
def test_nonmatching_intentions(self): params = { 'channel_id': self.channel_id, 'from': format_date(self.post.created), 'level': 'day', 'parent_topic': 'bag', 'intentions': ['apology', 'gratitude'], 'plot_type': 'sentiment', } results = self.make_request(params) self.assertFalse(results)
def test_leaves(self): params = { 'channel_id': self.channel_id, 'from': format_date(self.post.created), 'level': 'day', 'parent_topic': 'bag', 'intentions': [] # empty-list implies ALL_INTENTION } results = self.make_request(params) self.assertEqual(len(results), 1) self.assertEqual(results[0]['topic'], 'laptop bag')
def test_nonmatching_sentiments(self): params = { 'channel_id': self.channel_id, 'from': format_date(self.post.created), 'level': 'day', 'parent_topic': 'bag', 'sentiments': ['positive', 'neutral'], 'plot_type': 'sentiment', } results = self.make_request(params) self.assertFalse(results)
def test_nodes(self): def check_endpoint(params): results = self.make_request(params) self.assertEqual(len(results), 1) topic_set = set(x['topic'] for x in results) self.assertEqual(topic_set, set(['bag'])) params = { 'channel_id': self.channel_id, 'from': format_date(self.post.created), 'level': 'month', #'intentions' : [] # no explicit value implies ALL_INTENTION } check_endpoint(params) params['parent_topic'] = None check_endpoint(params) params['agents'] = [] check_endpoint(params) params['level'] = 'day' params['from'] = format_date(self.post.created - timedelta(days=3)) params['to'] = format_date(self.post.created + timedelta(days=3)) check_endpoint(params)
def test_matching_language(self): params = { 'channel_id': self.channel_id, 'from': format_date(self.post.created), 'level': 'day', 'parent_topic': 'bag', 'languages': ['English'] } results = self.make_request(params) self.assertEqual(len(results), 1) self.assertEqual(results[0]['topic'], 'laptop bag') params['languages'] = ['Spanish'] results = self.make_request(params) self.assertFalse(results)
def test_topic_cloud(self): self._create_db_post('I do not like laptop bag', demand_matchables=True) self._create_db_post('I do not like laptop bag', demand_matchables=True, _created=self.post.created_at - timedelta(days=1, minutes=1)) params = { 'channel_id': self.channel_id, 'from': format_date(self.post.created_at), 'level': 'day', 'parent_topic': None, 'cloud_type': 'delta' } results = self.make_request(params) self.assertEqual(results, [{ "topic": "bag", "topic_count": 0, "term_count": 1 }]) params['parent_topic'] = 'bag' results = self.make_request(params) self.assertEqual(results, [{ "topic": "laptop bag", "topic_count": 1, "term_count": 1 }]) params['cloud_type'] = 'percent' results = self.make_request(params) self.assertEqual(results, [{ "topic": "laptop bag", "topic_count": 100.0, "term_count": 100.0 }])