def test_can_be_added_in_the_dashboard(self):
        fancy_page = factories.FancyPageFactory(node__name='Sample Page')
        self.assertEquals(fancy_page.image, None)

        im = Image.new("RGB", (320, 240), "red")
        __, filename = tempfile.mkstemp(suffix='.jpg', dir=TEMP_IMAGE_DIR)
        im.save(filename, "JPEG")

        page = self.get(
            reverse('fp-dashboard:page-update', args=(fancy_page.id,)))

        settings_form = page.form
        settings_form['image'] = Upload(filename)
        list_page = settings_form.submit()

        self.assertRedirects(list_page, reverse('fp-dashboard:page-list'))

        # This bit is required because when using Oscar, the upload directory
        # is defined by the category's image field and differs from the one on
        # the PageNode.
        upload_url = None
        for field in get_node_model()._meta.fields:
            if field.name == 'image':
                upload_url = field.upload_to
                break

        pages_path = os.path.join(settings.MEDIA_ROOT, upload_url)
        fancy_page = FancyPage.objects.get(id=fancy_page.id)
        self.assertEquals(
            fancy_page.image.path,
            os.path.join(pages_path, filename.rsplit('/')[-1]))
    def test_can_be_added_in_the_dashboard(self):
        fancy_page = factories.FancyPageFactory(node__name='Sample Page')
        self.assertEquals(fancy_page.image, None)

        im = Image.new("RGB", (320, 240), "red")
        __, filename = tempfile.mkstemp(suffix='.jpg', dir=TEMP_IMAGE_DIR)
        im.save(filename, "JPEG")

        page = self.get(
            reverse('fp-dashboard:page-update', args=(fancy_page.id,)))

        settings_form = page.form
        settings_form['image'] = Upload(filename)
        list_page = settings_form.submit()

        self.assertRedirects(list_page, reverse('fp-dashboard:page-list'))

        # This bit is required because when using Oscar, the upload directory
        # is defined by the category's image field and differs from the one on
        # the PageNode.
        upload_url = None
        for field in get_node_model()._meta.fields:
            if field.name == 'image':
                upload_url = field.upload_to
                break

        pages_path = os.path.join(settings.MEDIA_ROOT, upload_url)
        fancy_page = FancyPage.objects.get(id=fancy_page.id)
        self.assertEquals(
            fancy_page.image.path,
            os.path.join(pages_path, filename.rsplit('/')[-1]))
Esempio n. 3
0
class PageNodeFactory(DjangoModelFactory):
    FACTORY_FOR = get_node_model()

    name = factory.Sequence(lambda n: "Node {}".format(n))
    depth = 1

    @classmethod
    def _generate(cls, create, attrs):
        if create:
            node = cls.FACTORY_FOR.add_root(**attrs)
        else:
            node = cls.FACTORY_FOR(**attrs)
        return node
    def handle_noargs(self, **options):
        # this makes the management command work nicely with the South
        # frozen ORM
        if 'orm' in options:
            orm = options['orm']
            try:
                Category = orm[FP_NODE_MODEL]
            except KeyError:
                CommandError(
                    "could not find model 'Category'. Aborting command.")
            try:
                FancyPage = orm[FP_PAGE_MODEL]
            except KeyError:
                CommandError(
                    "could not find model 'FancyPage'. Aborting command.")
        else:
            Category = get_node_model()
            FancyPage = get_page_model()

        for category in Category.objects.filter(page=None):
            # there seems to be no FP for this category so let's create one.
            FancyPage.objects.create(node=category)
    def handle_noargs(self, **options):
        # this makes the management command work nicely with the South
        # frozen ORM
        if 'orm' in options:
            orm = options['orm']
            try:
                Category = orm[FP_NODE_MODEL]
            except KeyError:
                CommandError(
                    "could not find model 'Category'. Aborting command.")
            try:
                FancyPage = orm[FP_PAGE_MODEL]
            except KeyError:
                CommandError(
                    "could not find model 'FancyPage'. Aborting command.")
        else:
            Category = get_node_model()
            FancyPage = get_page_model()

        for category in Category.objects.filter(page=None):
            # there seems to be no FP for this category so let's create one.
            FancyPage.objects.create(node=category)
Esempio n. 6
0
from django.db.models import get_model
from django.utils import simplejson as json
from django.core.urlresolvers import reverse

from fancypages.test import factories
from fancypages.test import testcases
from fancypages.utils import get_node_model, get_page_model

PageType = get_model('fancypages', 'PageType')
PageNode = get_node_model()
FancyPage = get_page_model()
Container = get_model('fancypages', 'Container')
TextBlock = get_model('fancypages', 'TextBlock')
TabBlock = get_model('fancypages', 'TabBlock')
ContentBlock = get_model('fancypages', 'ContentBlock')


class TestTheBlockTypeApi(testcases.FancyPagesWebTest):
    is_staff = True

    def setUp(self):
        super(TestTheBlockTypeApi, self).setUp()
        self.container = Container.objects.create(name="test")

    def test_is_not_available_to_anonymous_users(self):
        self.app.get(reverse('fp-api:block-type-list'), status=403)

    def test_returns_a_block_type_form_for_container(self):
        page = self.get(
            reverse('fp-api:block-type-list'),
            params={'container': self.container.uuid})
Esempio n. 7
0
 class Meta:
     model = get_node_model()