def test_all_tags(self): ''' Check if all tags are generated and otherwise produce 400. ''' logger.debug("Generating ALL tags, this might take a while...") red_verb_tag_len = len(self.red_verb_tags) * len( self.all_affopts) * len(self.all_pro_tags) blue_verb_tag_len = len(self.blue_verb_tags) * len( self.all_affopts) * len(self.all_pro_tags) purple_verb_tag_len = len(self.purple_verb_tags) * len( self.all_affopts) * len(self.valid_pro_combinations) logger.info("""There are a total of {total} possible tags, including {red} red verbs, {blue} blue verbs, and {purple} purple verbs""".format( total=str(red_verb_tag_len + blue_verb_tag_len + purple_verb_tag_len), red=str(red_verb_tag_len), blue=str(blue_verb_tag_len), purple=str(purple_verb_tag_len))) for arg in self.red_args: tag = self.return_tag(arg)[0]['fst'] try: self.assertTrue(self.valid_tag(tag)) except: self.fail("The following tag did not work: " + str(tag) + ". The args that generated it were: " + str(arg)) for arg in self.blue_args: tag = self.return_tag(arg)[0]['fst'] self.assertTrue(self.valid_tag(tag)) for arg in self.purple_args: tag = self.return_tag(arg)[0]['fst'] self.assertTrue(self.valid_tag(tag))
def test_up(self): verb = "^PP-^ke^R-^'níkhons^H^" res = self.foma_shell.up(verb) if len(res) != 1: self.fail("Expected one answer for '^PP-^ke^R-^'níkhons^H^'") else: for r in res: logger.debug(r)
def route(path): if path in ['wordmaker', 'tableviewer', 'info', 'about']: logger.debug("Path template rendered successfully") return render_template('web.html', gui_imports=ENV_CONFIG['gui_imports'], favicon=ENV_CONFIG['favicon'], title=ENV_CONFIG['title']) else: return page_not_found('404', path)
def test_down(self): tags = 'Verb+Active+AgentSg1+PatSg3Neuter+7nikhon-r+Habitual' res = self.foma_shell.down(tags) if len(res) != 1: self.fail( "Excpected a single answer for Verb+Active+AgentSg1+PatSg3Neuter+7nikhon-r+Habitual" ) elif res[0] != "^PP-^ke^R-^'níkhons^H^": self.fail('Expected "^PP-^ke^R-^\'níkhons^H^", got ' + res[0]) else: logger.debug(res[0])
def page_not_found(e, path=''): logger.debug("404 template rendered successfully") return render_template('404.html', title=ENV_CONFIG['title'], path=path), 404
def home(): logger.debug("Default template rendered successfully") return render_template('web.html', gui_imports=ENV_CONFIG['gui_imports'], favicon=ENV_CONFIG['favicon'], title=ENV_CONFIG['title'])
CSP = {} # Talisman for security if ENV_CONFIG['security']['default_google_csp']: CSP = GOOGLE_CSP_POLICY else: CSP = ENV_CONFIG['security']['custom_csp'] # Configure App Talisman( app, content_security_policy=CSP, content_security_policy_nonce_in=ENV_CONFIG['security']['csp_nonce_in']) app.config.from_object(Config) logger.debug("App configured successfully") # Add Views app.register_blueprint(affix_api, url_prefix='/api/v1') app.register_blueprint(pronoun_api, url_prefix='/api/v1') app.register_blueprint(verb_api, url_prefix='/api/v1') app.register_blueprint(conjugation_api, url_prefix='/api/v1') app.register_blueprint(conjugation_api_2, url_prefix='/api/v2') @app.route('/') def home(): logger.debug("Default template rendered successfully") return render_template('web.html', gui_imports=ENV_CONFIG['gui_imports'], favicon=ENV_CONFIG['favicon'],
def test_execute_foma_command(self): res = self.foma_shell.execute_foma_command('random_upper') for r in res: logger.debug(r)
def test_response_code_with_args(self): ''' Ensure all args return 200 ''' for ep in self.routes_only_args: if "/verb" in ep: for x in self.all_verb_tags: rt = re.sub(self.arg_match, x, ep) try: r = requests.get(self.host + rt) self.assertEqual(r.status_code, 200) except AssertionError: logger.error("Route " + self.host + rt + " returned " + str(r.status_code) + ". Is the FST running?") except: logger.error("Couldn't connect. Is flask running?") logger.info("Successfully tested " + str(len(self.all_verb_tags)) + " verb resources at route " + self.host + ep + " .") elif "/aff-option" in ep: for x in self.all_affopt_tags: rt = re.sub(self.arg_match, x, ep) try: r = requests.get(self.host + rt) self.assertEqual(r.status_code, 200) except AssertionError: logger.error("Route " + self.host + rt + " returned " + str(r.status_code) + ". Is the FST running?") except: logger.error("Couldn't connect. Is flask running?") logger.info("Successfully tested " + str(len(self.all_affopt_tags)) + " affix option resources at route " + self.host + ep + ".") elif "/affix" in ep: for x in self.all_affix_tags: rt = re.sub(self.arg_match, x, ep) try: r = requests.get(self.host + rt) self.assertEqual(r.status_code, 200) except AssertionError: logger.error("Route " + self.host + rt + " returned " + str(r.status_code) + ". Is the FST running?") except: logger.error("Couldn't connect. Is flask running?") logger.info("Successfully tested " + str(len(self.all_affix_tags)) + " affix resources at route " + self.host + ep + ".") elif "/pronoun" in ep: for x in self.all_pronoun_tags: rt = re.sub(self.arg_match, x, ep) try: r = requests.get(self.host + rt) self.assertEqual(r.status_code, 200) except AssertionError: logger.error("Route " + self.host + rt + " returned " + str(r.status_code) + ". Is the FST running?") except: logger.error("Couldn't connect. Is flask running?") logger.info("Successfully tested " + str(len(self.all_pronoun_tags)) + " pronoun resources at route " + self.host + ep + ".") elif "/conjugations": logger.debug("Passing conjugations args for other test") pass else: logger.warning("Route " + ep + " was registered, but not tested.")