def test_env_returns_bool(self): os.environ["bool"] = "True" self.assertTrue(env('bool')) os.environ["bool"] = "true" self.assertTrue(env('bool')) os.environ["bool"] = "False" self.assertFalse(env('bool')) os.environ["bool"] = "false" self.assertFalse(env('bool'))
def test_send_mail_sends_with_queue(self): if env('RUN_MAIL'): self.app.bind('MailSmtpDriver', MailDriver) self.assertEqual( MailManager(self.app).driver('smtp').to( '*****@*****.**').queue().send('hi'), None)
def test_send_mail_sends(self): if env('RUN_MAIL'): self.app.bind('MailSmtpDriver', MailDriver) self.assertTrue( MailManager(self.app).driver('smtp').to( '*****@*****.**').send('hi'))
def test_mail_sends_with_queue_and_without_queue(self): if env('RUN_MAIL'): self.assertEqual( MailManager(self.app).driver('mailgun').to( '*****@*****.**').send('test queue'), None) self.assertEqual( MailManager(self.app).driver('mailgun').queue().to( '*****@*****.**').send('test queue'), None)
def test_env_returns_false_on_blank_string(self): os.environ["test"] = "" self.assertEqual(env('test', 'default'), 'default')
def test_env_returns_default(self): os.environ["test"] = "1" self.assertEqual(env('na', 'default'), 'default')
def test_env_returns_numeric_with_default(self): os.environ["numeric"] = "1" self.assertEqual(env('na', '1'), 1)
def test_env_returns_numeric(self): os.environ["numeric"] = "1" self.assertEqual(env('numeric'), 1)
"""Application Settings.""" import os from src.masonite import env """Application Name This value is the name of your application. This value is used when the framework needs to place the application's name in a notification or any other location as required by the application or its packages. """ NAME = env('APP_NAME', 'Masonite 2.1') """Application Debug Mode When your application is in debug mode, detailed error messages with stack traces will be shown on every error that occurs within your application. If disabled, a simple generic error page is shown """ DEBUG = env('APP_DEBUG', True) """Secret Key This key is used to encrypt and decrypt various values. Out of the box Masonite uses this key to encrypt or decrypt cookies so you can use it to encrypt and decrypt various values using the Masonite Sign class. Read the documentation on Encryption to find out how. """ KEY = env('KEY', 'mQhQtBZP-WmaJl5FpW2dC0vpnYs2ms1u5AIVqDM8s6w=')
"""Queue Settings.""" from src.masonite import env """Queue Driver Queues are an excellent way to send intensive and time consuming tasks into the background to improve performance of your application. Supported: 'async', 'amqp' """ DRIVER = env('QUEUE_DRIVER', 'async') """Queue Drivers Put any configuration settings for your drivers in this configuration setting. """ DRIVERS = { 'async': { 'mode': 'threading' }, 'amqp': { 'username': env('QUEUE_USERNAME', 'guest'), 'vhost': env('QUEUE_VHOST', ''), 'password': env('QUEUE_PASSWORD', 'guest'), 'host': env('QUEUE_HOST', 'localhost'), 'port': env('QUEUE_PORT', '5672'), 'channel': env('QUEUE_CHANNEL', 'default'), } }
"""Cache Settings.""" from src.masonite import env """Cache Driver Caching is a great way to gain an instant speed boost to your application. Very often templates will not change and you can utilize caching to the best by caching your templates forever, monthly or every few seconds Supported: 'disk' """ DRIVER = env('CACHE_DRIVER', 'disk') """Cache Drivers Place all your caching coniguration as a dictionary here. The keys here should correspond to the driver types supported above. Supported: 'disk' """ DRIVERS = {'disk': {'location': 'bootstrap/cache'}}
"""Session Settings.""" from src.masonite import env """Session Driver Sessions are able to be linked to an individual user and carry data from request to request. The memory driver will store all the session data inside memory which will delete when the server stops running. Supported: 'memory', 'cookie' """ DRIVER = env('SESSION_DRIVER', 'cookie')
"""Storage Settings.""" from src.masonite import env """Storage Driver The default driver you will like to use for storing uploads. You may add additional drivers as you need or pip install additional drivers. Supported: 'disk', 's3', 'rackspace', 'googlecloud', 'azure' """ DRIVER = env('STORAGE_DRIVER', 'disk') """Storage Drivers Different drivers you can use for storing file uploads. """ DRIVERS = { 'disk': { 'location': { 'uploading': 'uploads/' } }, 's3': { 'client': env('S3_CLIENT', 'AxJz...'), 'secret': env('S3_SECRET', 'HkZj...'), 'bucket': env('S3_BUCKET', 's3bucket'), 'location': 'http://s3.amazon.com/bucket', 'test_locations': { 'test': 'value' }
from src.masonite.testing import TestCase from config.database import Model from src.masonite import env class User(Model): pass if env('RUN_DATABASE'): class TestDatabase(TestCase): def setUp(self): super().setUp() self.make(User, self.users_factory, 20) def users_factory(self, faker): return { 'name': faker.name(), 'email': faker.email(), 'password': '******', # == 'secret' } def test_has_records(self): self.assertGreater(User.all().count(), 0)
def test_env_returns_casted_value_on_blank_string(self): os.environ["test"] = "" self.assertEqual(env('test', '1234'), 1234)
def test_env_works_with_none(self): self.assertIsNone(env('na', None))
"""Broadcast Settings.""" from src.masonite import env """Broadcast Driver Realtime support is critical for any modern web application. Broadcast drivers allow you to push data from your server to all your clients to show data updates to your clients in real time without having to constantly refresh the page or send constant ajax requests Supported: 'pusher', 'ably' """ DRIVER = env('BROADCAST_DRIVER', 'pusher') """Broadcast Drivers Below is a dictionary of all your driver configurations. Each key in the dictionary should be the name of a driver. """ DRIVERS = { 'pusher': { 'app_id': env('PUSHER_APP_ID', '29382xx..'), 'client': env('PUSHER_CLIENT', 'shS8dxx..'), 'secret': env('PUSHER_SECRET', 'HDGdjss..'), }, 'ably': { 'secret': env('ABLY_SECRET', 'api:key') } }
"""Mail Settings.""" from src.masonite import env """From Address This value will be used for the default address when sending emails from your application. """ FROM = { 'address': env('MAIL_FROM_ADDRESS', '*****@*****.**'), 'name': env('MAIL_FROM_NAME', 'Masonite') } """Mail Driver The default driver you will like to use for sending emails. You may add additional drivers as you need or pip install additional drivers. Supported: 'smtp', 'mailgun' """ DRIVER = env('MAIL_DRIVER', 'smtp') """Mail Drivers Different drivers you can use for sending email. """ DRIVERS = { 'smtp': { 'host': env('MAIL_HOST', 'smtp.mailtrap.io'), 'port': env('MAIL_PORT', '465'),
Loads in the environment variables when this page is imported. """ LoadEnvironment() """Database Settings Set connection database settings here as a dictionary. Follow the format below to create additional connection settings. Each key is a connection, not a driver. You may have as many connections as you need. Supported Drivers: 'sqlite', 'mysql', 'postgres' """ DATABASES = { 'default': env('DB_CONNECTION', 'sqlite'), 'sqlite': { 'driver': 'sqlite', 'database': env('SQLITE_DB_DATABASE', 'masonite.db'), 'log_queries': env('DB_LOG'), 'prefix': '' }, 'mysql': { 'driver': 'mysql', 'host': env('DB_HOST'), 'database': env('DB_DATABASE'), 'port': env('DB_PORT'), 'user': env('DB_USERNAME'), 'password': env('DB_PASSWORD'), 'log_queries': env('DB_LOG'), },