Exemplo n.º 1
0
    def test_create_default_lanes(self):
        library = self._default_library
        library.setting(
            Configuration.LARGE_COLLECTION_LANGUAGES
        ).value = json.dumps(
            ['eng']
        )

        library.setting(
            Configuration.SMALL_COLLECTION_LANGUAGES
        ).value = json.dumps(
            ['spa', 'chi']
        )

        library.setting(
            Configuration.TINY_COLLECTION_LANGUAGES
        ).value = json.dumps(
            ['ger','fre','ita']
        )

        create_default_lanes(self._db, self._default_library)
        lanes = self._db.query(Lane).filter(Lane.library==library).filter(Lane.parent_id==None).all()

        # We have five top-level lanes for the large collection,
        # a top-level lane for each small collection, and a lane
        # for everything left over.
        eq_(set(['Fiction', "Nonfiction", "Young Adult Fiction", "Young Adult Nonfiction",
                 "Children and Middle Grade", u'World Languages']),
            set([x.display_name for x in lanes])
        )

        [english_fiction_lane] = [x for x in lanes if x.display_name == 'Fiction']
        eq_(0, english_fiction_lane.priority)
        [world] = [x for x in lanes if x.display_name == 'World Languages']
        eq_(5, world.priority)
Exemplo n.º 2
0
    def test_create_default_lanes(self):
        library = self._default_library
        library.setting(
            Configuration.LARGE_COLLECTION_LANGUAGES
        ).value = json.dumps(
            ['eng']
        )

        library.setting(
            Configuration.SMALL_COLLECTION_LANGUAGES
        ).value = json.dumps(
            ['spa', 'chi']
        )

        library.setting(
            Configuration.TINY_COLLECTION_LANGUAGES
        ).value = json.dumps(
            ['ger','fre','ita']
        )

        create_default_lanes(self._db, self._default_library)
        lanes = self._db.query(Lane).filter(Lane.library==library).filter(Lane.parent_id==None).all()

        # We have five top-level lanes for the large collection,
        # a top-level lane for each small collection, and a lane
        # for everything left over.
        eq_(set(['Fiction', "Nonfiction", "Young Adult Fiction", "Young Adult Nonfiction",
                 "Children and Middle Grade", u'World Languages']),
            set([x.display_name for x in lanes])
        )

        [english_fiction_lane] = [x for x in lanes if x.display_name == 'Fiction']
        eq_(0, english_fiction_lane.priority)
        [world] = [x for x in lanes if x.display_name == 'World Languages']
        eq_(5, world.priority)
Exemplo n.º 3
0
    def process_post(self, validators_by_type=None):
        self.require_system_admin()

        library = None
        is_new = False
        if validators_by_type is None:
            validators_by_type = dict()
            validators_by_type['geographic'] = GeographicValidator()
            validators_by_type['announcements'] = AnnouncementListValidator()

        library_uuid = flask.request.form.get("uuid")
        library = self.get_library_from_uuid(library_uuid)
        if isinstance(library, ProblemDetail):
            return library

        short_name = flask.request.form.get("short_name")
        short_name_not_unique = self.check_short_name_unique(
            library, short_name)
        if short_name_not_unique:
            return short_name_not_unique

        error = self.validate_form_fields()
        if error:
            return error

        if not library:
            (library, is_new) = self.create_library(short_name, library_uuid)
        else:
            self.require_library_manager(library)

        name = flask.request.form.get("name")
        if name:
            library.name = name
        if short_name:
            library.short_name = short_name

        configuration_settings = self.library_configuration_settings(
            library, validators_by_type)
        if isinstance(configuration_settings, ProblemDetail):
            return configuration_settings

        if is_new:
            # Now that the configuration settings are in place, create
            # a default set of lanes.
            create_default_lanes(self._db, library)
            return Response(unicode(library.uuid), 201)
        else:
            return Response(unicode(library.uuid), 200)
Exemplo n.º 4
0
    def test_create_default_lanes(self):
        library = self._default_library
        library.setting(Configuration.LARGE_COLLECTION_LANGUAGES).value = json.dumps(
            ["eng"]
        )

        library.setting(Configuration.SMALL_COLLECTION_LANGUAGES).value = json.dumps(
            ["spa", "chi"]
        )

        library.setting(Configuration.TINY_COLLECTION_LANGUAGES).value = json.dumps(
            ["ger", "fre", "ita"]
        )

        create_default_lanes(self._db, self._default_library)
        lanes = (
            self._db.query(Lane)
            .filter(Lane.library == library)
            .filter(Lane.parent_id == None)
            .all()
        )

        # We have five top-level lanes for the large collection,
        # a top-level lane for each small collection, and a lane
        # for everything left over.
        assert (
            set(
                [
                    "Fiction",
                    "Nonfiction",
                    "Young Adult Fiction",
                    "Young Adult Nonfiction",
                    "Children and Middle Grade",
                    "World Languages",
                ]
            )
            == set([x.display_name for x in lanes])
        )

        [english_fiction_lane] = [x for x in lanes if x.display_name == "Fiction"]
        assert 0 == english_fiction_lane.priority
        [world] = [x for x in lanes if x.display_name == "World Languages"]
        assert 5 == world.priority
    def process_post(self, validator=None):
        self.require_system_admin()

        library = None
        is_new = False
        validator = validator or GeographicValidator()

        library_uuid = flask.request.form.get("uuid")
        library = self.get_library_from_uuid(library_uuid)
        if isinstance(library, ProblemDetail):
            return library

        short_name = flask.request.form.get("short_name")
        short_name_not_unique = self.check_short_name_unique(library, short_name)
        if short_name_not_unique:
            return short_name_not_unique

        error = self.validate_form_fields()
        if error:
            return error

        if not library:
            (library, is_new) = self.create_library(short_name, library_uuid)
        else:
            self.require_library_manager(library)

        name = flask.request.form.get("name")
        if name:
            library.name = name
        if short_name:
            library.short_name = short_name

        configuration_settings = self.library_configuration_settings(library, validator)
        if isinstance(configuration_settings, ProblemDetail):
            return configuration_settings

        if is_new:
            # Now that the configuration settings are in place, create
            # a default set of lanes.
            create_default_lanes(self._db, library)
            return Response(unicode(library.uuid), 201)
        else:
            return Response(unicode(library.uuid), 200)
Exemplo n.º 6
0
 def process_library(self, library):
     create_default_lanes(self._db, library)
Exemplo n.º 7
0
"""Make sure every library has some lanes."""
import os
import sys
import logging
from nose.tools import set_trace

bin_dir = os.path.split(__file__)[0]
package_dir = os.path.join(bin_dir, "..")
sys.path.append(os.path.abspath(package_dir))

from core.model import (
    Library,
    production_session,
)
from api.lanes import create_default_lanes

_db = production_session()
for library in _db.query(Library):
    num_lanes = len(library.lanes)
    if num_lanes:
        logging.info("%s has %d lanes, not doing anything.", library.name,
                     num_lanes)
    else:
        logging.warn("%s has no lanes, creating some.", library.name)
        try:
            create_default_lanes(_db, library)
        except Exception, e:
            logging.error(
                "Could not create default lanes; suggest you try resetting them manually.",
                exc_info=e)