105 lines
3.6 KiB
Python
105 lines
3.6 KiB
Python
import json
|
|
import os
|
|
import zipfile
|
|
|
|
import pytest
|
|
from webtest import TestApp
|
|
|
|
from django.conf import settings
|
|
|
|
from combo.data.models import Page, CellBase, TextCell, LinkCell, FeedCell
|
|
from combo.apps.momo.management.commands.update_momo_manifest import Command as UpdateCommand
|
|
|
|
from .test_manager import login, admin_user
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
class MomoEnabled(object):
|
|
def __enter__(self):
|
|
settings.ENABLE_MOMO = True
|
|
|
|
def __exit__(self, *args, **kwargs):
|
|
settings.ENABLE_MOMO = False
|
|
|
|
|
|
@pytest.fixture
|
|
def assets_base():
|
|
assets_base_path = os.path.join(settings.MEDIA_ROOT, 'assets-base.zip')
|
|
if not os.path.exists(assets_base_path):
|
|
fd = open(assets_base_path, 'w')
|
|
z = zipfile.ZipFile(fd, 'w')
|
|
z.close()
|
|
|
|
|
|
def test_no_menu_if_not_enabled(app, admin_user):
|
|
app = login(app)
|
|
resp = app.get('/manage/', status=200)
|
|
assert not 'Mobile Application' in resp.body
|
|
|
|
|
|
def test_menu_if_enabled(app, admin_user):
|
|
with MomoEnabled():
|
|
app = login(app)
|
|
resp = app.get('/manage/', status=200)
|
|
assert 'Mobile Application' in resp.body
|
|
|
|
def test_options(app, admin_user):
|
|
with MomoEnabled():
|
|
app = login(app)
|
|
resp = app.get('/manage/', status=200)
|
|
resp = resp.click('Mobile Application')
|
|
resp = resp.click('Options')
|
|
resp.form['title'] = 'Momo Test'
|
|
resp.form['contact_email'] = 'foobar@localhost'
|
|
resp = resp.form.submit()
|
|
resp = resp.follow()
|
|
resp = resp.click('Options')
|
|
assert resp.form['title'].value == 'Momo Test'
|
|
|
|
def test_generate_no_assets_base(app, admin_user):
|
|
with MomoEnabled():
|
|
app = login(app)
|
|
resp = app.get('/manage/', status=200)
|
|
resp = resp.click('Mobile Application')
|
|
resp = resp.click('Generate Content Update')
|
|
assert not os.path.exists(os.path.join(settings.MEDIA_ROOT, 'index.json'))
|
|
|
|
def test_generate_no_homepage(app, admin_user, assets_base):
|
|
with MomoEnabled():
|
|
app = login(app)
|
|
resp = app.get('/manage/', status=200)
|
|
resp = resp.click('Mobile Application')
|
|
resp = resp.click('Generate Content Update')
|
|
assert not os.path.exists(os.path.join(settings.MEDIA_ROOT, 'index.json'))
|
|
|
|
def test_generate_simple(app, admin_user, assets_base):
|
|
Page.objects.all().delete()
|
|
page1 = Page(title='My Mobile App', slug='index', template_name='standard')
|
|
page1.save()
|
|
page2 = Page(title='Two', slug='two', template_name='standard')
|
|
page2.save()
|
|
page3 = Page(title='Three', slug='three', parent=page1, template_name='standard')
|
|
page3.save()
|
|
|
|
cell = TextCell(page=page2, placeholder='content', text='Lorem ipsum', order=0)
|
|
cell.save()
|
|
|
|
cell = TextCell(page=page1, placeholder='footer', text='This is the footer', order=0)
|
|
cell.save()
|
|
|
|
with MomoEnabled():
|
|
app = login(app)
|
|
resp = app.get('/manage/', status=200)
|
|
resp = resp.click('Mobile Application')
|
|
resp = resp.click('Generate Content Update')
|
|
assert os.path.exists(os.path.join(settings.MEDIA_ROOT, 'index.json'))
|
|
assert os.path.exists(os.path.join(settings.MEDIA_ROOT, 'assets.zip'))
|
|
content = json.load(open(os.path.join(settings.MEDIA_ROOT, 'index.json')))
|
|
assert content['meta']['title'] == 'My Mobile App'
|
|
assert 'This is the footer' in content['footer']
|
|
assert len(content['pages']) == 1
|
|
assert content['pages'][0]['title'] == 'Two'
|
|
assert 'Lorem ipsum' in content['pages'][0]['content']
|
|
assert 'menu-three-%s' % page3.id in content['menu']
|