Exemple #1
0
    def test_not_on_platform_returns_correctly(self):

        config = Config()
        self.assertFalse(config.is_valid_platform())
Exemple #2
0
    def test_on_platform_returns_correctly_in_runtime(self):

        config = Config(self.mockEnvironmentDeploy)
        self.assertTrue(config.is_valid_platform())
Exemple #3
0
    def test_custom_prefix_works(self):

        config = Config({'FAKE_APPLICATION_NAME': 'test-application'}, 'FAKE_')

        self.assertTrue(config.is_valid_platform())
Exemple #4
0
    def test_formatted_credentials_throws_when_no_formatter_defined(self):

        config = Config(self.mockEnvironmentDeploy)

        with self.assertRaises(NoCredentialFormatterFoundException):
            config.formatted_credentials('database', 'not-defined')
Exemple #5
0
    def test_get_non_existent_route_throws_exception(self):

        config = Config(self.mockEnvironmentDeploy)

        with self.assertRaises(KeyError):
            config.get_route('missing')
Exemple #6
0
    def test_get_route_by_id_works(self):

        config = Config(self.mockEnvironmentDeploy)
        route = config.get_route('main')

        self.assertEqual('https://www.{default}/', route['original_url'])
Exemple #7
0
USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

WAGTAIL_SITE_NAME = 'Platform.sh Wagtail Demo'

# Import some Platform.sh settings from the environment.

config = Config()

if config.appDir:
    STATIC_ROOT = os.path.join(config.appDir, 'static')
if config.projectEntropy:
    SECRET_KEY = config.projectEntropy

routes = os.getenv('PLATFORM_ROUTES')
if routes:
    routes = json.loads(base64.b64decode(routes).decode('utf-8'))
    app_name = os.getenv('PLATFORM_APPLICATION_NAME')
    for url, route in routes.items():
        host = urlparse(url).netloc
        if (host not in ALLOWED_HOSTS and route['type'] == 'upstream'
                and route['upstream'] == app_name):
            ALLOWED_HOSTS.append(host)
def usage_example():

    # Create a new Config object to ease reading the Platform.sh environment variables.
    # You can alternatively use os.environ yourself.
    config = Config()

    # The 'database' relationship is generally the name of primary SQL database of an application.
    # That's not required, but much of our default automation code assumes it.'
    credentials = config.credentials('mysql')

    try:
        # Connect to the database using PDO. If using some other abstraction layer you would inject the values
        # from `database` into whatever your abstraction layer asks for.

        conn = pymysql.connect(host=credentials['host'],
                               port=credentials['port'],
                               database=credentials['path'],
                               user=credentials['username'],
                               password=credentials['password'])

        sql = '''
                CREATE TABLE People (
                id SERIAL PRIMARY KEY,
                name VARCHAR(30) NOT NULL,
                city VARCHAR(30) NOT NULL
                )
                '''

        cur = conn.cursor()
        cur.execute(sql)

        sql = '''
                INSERT INTO People (name, city) VALUES
                ('Neil Armstrong', 'Moon'),
                ('Buzz Aldrin', 'Glen Ridge'),
                ('Sally Ride', 'La Jolla');
                '''

        cur.execute(sql)

        # Show table.
        sql = '''SELECT * FROM People'''
        cur.execute(sql)
        result = cur.fetchall()

        table = '''<table>
<thead>
<tr><th>Name</th><th>City</th></tr>
</thead>
<tbody>'''

        if result:
            for record in result:
                table += '''<tr><td>{0}</td><td>{1}</td><tr>\n'''.format(
                    record[1], record[2])
            table += '''</tbody>\n</table>\n'''

        # Drop table
        sql = '''DROP TABLE People'''
        cur.execute(sql)

        # Close communication with the database
        cur.close()
        conn.close()

        return table

    except Exception as e:
        return e
import json
import yaml
import hashlib
from platformshconfig import Config

config = Config()

if config.is_valid_platform():
    template_data = "config/templates.yaml"
    docs_data = "config/index.json"
else:
    template_data = "../docs/data/templates.yaml"
    docs_data = "../docs/public/index.json"

final_templates_location = "output/templates.json"
final_docs_location = "output/docs.json"

with open(template_data, 'r') as stream:
    try:
        data = yaml.safe_load(stream)

        indexData = []

        for language in data:
            for template in data[language]:
                temp = {}
                temp["site"] = "templates"
                temp["section"] = "<b>Templates | </b><code>{}</code>".format(
                    language)
                temp["rank"] = 2
                temp["title"] = template['name']