Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ lipsum==0.1.2
Markdown==3.0.1
MarkupSafe==1.0
mlalchemy==0.2.2
mock
pathtools==0.1.2
pystache==0.5.4
python-dateutil==2.7.3
Expand Down
3 changes: 3 additions & 0 deletions statik/context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-

from __future__ import unicode_literals

import os
from copy import deepcopy, copy

from future.utils import iteritems
Expand Down Expand Up @@ -67,6 +69,7 @@ def build(self, db=None, safe_mode=False, for_each_inst=None, extra=None):
"""Builds a dictionary that can be used as context for template rendering."""
result = copy(self.initial)
result.update(self.static)
result.update(os.environ)
if self.dynamic:
result.update(self.build_dynamic(db, extra=extra, safe_mode=safe_mode))
if self.for_each and for_each_inst:
Expand Down
10 changes: 10 additions & 0 deletions tests/modular/test_context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding:utf-8 -*-
import unittest

import mock

from statik.context import StatikContext
from statik.database import StatikDatabase

Expand All @@ -14,3 +16,11 @@ def test_build_context(self):

result = context.build(db=StatikDatabase(models={}, data_path=''), extra={'my_var': 5})
assert result.get('render_elm') is False

def test_env_var_in_context(self):
with mock.patch.dict('statik.context.os.environ',
{'HOME': 'HOME!!'}):
context = StatikContext()

result = context.build(db=StatikDatabase(models={}, data_path=''))
self.assertEqual(result.get('HOME'), 'HOME!!')