def test_build_rule_bad_args(self): try: rules.build(None) except BadArgumentException: return self.fail( "rules.build_rule was supposed to throw a BadArgumentException")
def test_build_rule_bad_args(self): """ Make sure building rules with unexpected args fail. """ try: rules.build(None) except BadArgumentException: return self.fail("rules.build_rule was supposed to throw a BadArgumentException")
def test_build_rule_bad_args(self): """ Make sure building rules with unexpected args fail. """ try: rules.build(None) except BadArgumentException: return self.fail( "rules.build_rule was supposed to throw a BadArgumentException")
def get(self, id): (project, dataset, table) = Utils.parse_bqid(id) query = USER_QUERY % (dataset, table) tag = Utils.make_tag(dataset, table) params = GNIP_RULES_PARAMS params['tag'] = tag results = Utils.get_bq().jobs().query(projectId=config.PROJECT_NUMBER, body={ 'query': query }).execute() tweet_count = 0 users = [] if 'rows' in results: rules_list = [] rule = "" clause_count = 0 for row in results['rows']: for key, dict_list in row.iteritems(): user = dict_list[0]['v'] if user: user = "******" % user rule = "%s OR %s" % (user, rule) clause_count = clause_count + 1 break if clause_count >= 30 or len(rule) > 1000: rule = rule[:-4] rules_list.append(rules.build(rule, tag)) rule = "" clause_count = 0 if len(rule) > 5: rule = rule[:-4] rules_list.append(rules.build(rule, tag)) print rules_list response = rules.add_rules(rules_list, **params) print response response = {"rules": rules_list, "rule_count": len(rules_list)} self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(response))
def get(self, id): (project, dataset, table) = Utils.parse_bqid(id) query = USER_QUERY % (dataset, table) tag = Utils.make_tag(dataset, table) params = GNIP_RULES_PARAMS params['tag'] = tag results = Utils.get_bq().jobs().query(projectId=config.PROJECT_NUMBER, body={'query':query}).execute() tweet_count = 0 users = [] if 'rows' in results: rules_list = [] rule = "" clause_count = 0 for row in results['rows']: for key, dict_list in row.iteritems(): user = dict_list[0]['v'] if user: user = "******" % user rule = "%s OR %s" % (user, rule) clause_count = clause_count + 1 break if clause_count >= 30 or len(rule) > 1000: rule = rule[:-4] rules_list.append(rules.build(rule, tag)) rule = "" clause_count = 0 if len(rule) > 5: rule = rule[:-4] rules_list.append(rules.build(rule, tag)) print rules_list response = rules.add_rules(rules_list, **params) print response response = {"rules": rules_list, "rule_count": len(rules_list) } self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(response))
def get(self): response = [] dataset = self.request.get("dataset")[:-1] table = self.request.get("name") Utils.insert_table(dataset, table) TABLE_CACHE.clear() tag = Utils.make_tag(dataset, table) rule_list = self.request.get("rules") rule_list = [ rules.build(s.strip(), tag) for s in rule_list.splitlines() ] params = GNIP_RULES_PARAMS params['tag'] = tag response = rules.add_rules(rule_list, **params) TABLE_CACHE.clear() print "ApiTableAdd", response self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(response))
def get(self): response = [] dataset = self.request.get("dataset")[:-1] table = self.request.get("name") Utils.insert_table(dataset, table) TABLE_CACHE.clear() tag = Utils.make_tag(dataset, table) rule_list = self.request.get("rules") rule_list = [rules.build(s.strip(), tag) for s in rule_list.splitlines()] params = GNIP_RULES_PARAMS params['tag'] = tag response = rules.add_rules(rule_list, **params) TABLE_CACHE.clear() print "ApiTableAdd", response self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(response))
def _generate_rules_list(self): rules_list = [] rules_list.append(rules.build(self.rule_string)) rules_list.append(rules.build(self.rule_string, self.tag)) return rules_list
def test_build_rule_with_tag(self): """ Build rule with tag. """ r = rules.build(self.rule_string, tag=self.tag) self.assertEqual(r['value'], self.rule_string) self.assertEqual(r['tag'], self.tag) rules._check_rules_list([r])
def test_build_rule_without_tag(self): """ Build rule without tag. """ r = rules.build(self.rule_string) self.assertEqual(r['value'], self.rule_string) self.assertFalse("tag" in r) rules._check_rules_list([r])
def test_build_rule_with_tag(self): r = rules.build(self.rule_string, tag=self.tag) self.assertEqual(r['value'], self.rule_string) self.assertEqual(r['tag'], self.tag) rules._check_rules_list([r])
def test_build_rule_without_tag(self): r = rules.build(self.rule_string) self.assertEqual(r['value'], self.rule_string) self.assertFalse("tag" in r) rules._check_rules_list([r])
def test_build_rule_bad_args(self): try: rules.build(None) except BadArgumentException: return self.fail("rules.build_rule was supposed to throw a BadArgumentException")