@app.route("/email/", methods=['POST']) def email(): emailHandler = EmailRequestHandler(config) response = emailHandler.process(request) return response # For Dev purpose only @app.route("/test/", methods=['GET']) def test(): if app.config["ENV"] == "dev": f = open('./test/test.html', 'r') content = f.read() return Response(content, status=200, mimetype="text/html") else: return Response("{\"message\": \"Page not allowed to access\"}", status=404) # Main Service if __name__ == "__main__": config = ConfigLoader() if config.isLoaded(): # get environment app.config["ENV"] = config.getEnv() print "Environment: "+ app.config["ENV"].upper() if app.config["ENV"].lower() == "prod": app.run(host= '0.0.0.0') elif app.config["ENV"].lower() == "dev": app.run(debug=True) else: print "Failed to load the config. Can't start the Service."
class EmailServiceTestCase(unittest.TestCase): def setUp(self): emailService.app.config['TESTING'] = True self.app = emailService.app.test_client() self.config = ConfigLoader() emailService.app.config['ENV'] = self.config.getEnv() def tearDown(self): # nothing to do yet pass ''' configLoader.py testing ''' def test_configLoader_getPayloadValidationVersion(self): assert self.config.getPayloadValidationVersion() def test_configLoader_getPayloadValidationConfig(self): assert self.config.getPayloadValidationConfig() def test_configLoader_getEmailServiceVersion(self): assert self.config.getEmailServiceVersion() def test_configLoader_getSplunkLogPath(self): assert self.config.getSplunkLogPath() def test_configLoader_getLogPath(self): assert self.config.getLogPath() def test_configLoader_isLoaded(self): assert self.config.isLoaded() is True def test_configLoader_getEnv(self): assert self.config.getEnv() in ('prod', 'dev') ''' emailService.py testing ''' def test_root(self): rv = self.app.get('/') assert "{\"message\": \"Please check API documentation\"}" in rv.data rv = self.app.post('/') assert "405 Method Not Allowed" in rv.data rv = self.app.put('/') assert "405 Method Not Allowed" in rv.data rv = self.app.delete('/') assert "405 Method Not Allowed" in rv.data def test_test(self): emailService.app.config['ENV'] = "prod" if emailService.app.config['ENV'] is "prod": rv = self.app.get('/test/') assert "{\"message\": \"Page not allowed to access\"}" in rv.data rv = self.app.post('/test/') assert "405 Method Not Allowed" in rv.data rv = self.app.put('/test/') assert "405 Method Not Allowed" in rv.data rv = self.app.delete('/test/') assert "405 Method Not Allowed" in rv.data emailService.app.config['ENV'] = "dev" if emailService.app.config['ENV'] is "dev": rv = self.app.get('/test/') assert "<p>Just for testing</p>" in rv.data rv = self.app.post('/test/') assert "405 Method Not Allowed" in rv.data rv = self.app.put('/test/') assert "405 Method Not Allowed" in rv.data rv = self.app.delete('/test/') assert "405 Method Not Allowed" in rv.data def test_email(self): pass ''' emailRequestHandler.py testing ''' def test_email_request_handler(self): pass ''' payloadValidationHelper.py testing ''' def test_payload_validation_helper(self): pass ''' providerRequestHandler.py testing ''' def test_provider_request_handler(self): pass