Ejemplo n.º 1
0
def populate_groups():
    from django.contrib.auth.models import Permission, Group
    # add few groups
    def readd_group(group_name, perms=[], direct_add=False):
        """
        Add permission from perms to group_name group.
        If group doesn't exist, new one is created.
        If direct_add is True, then perms is assumed to be Permission's instance. Otherwise it should be a string.
        """
        g = None
        try:
            # delete group if exist
            Group.objects.get(name=group_name).delete()
        except Group.DoesNotExist:
            pass
        # create a new one
        g = Group(name=group_name)
        g.save()
        for perm in perms:
            if direct_add or isinstance(perm, Permission):
                p = perm
            else:
                p = Permission.objects.get(codename=perm)
            assert isinstance(p, Permission)
            g.permissions.add(p)
        g.save()
    
    print "Adding app specific groups"
    from dbfiller_perms import readers_perms, admins_perms, librarians_perms
    readd_group('Readers',    perms=readers_perms, direct_add=True)
    readd_group('Librarians', perms=librarians_perms, direct_add=True)
    readd_group('Admins',     perms=admins_perms,  direct_add=True)
    
    
    # fill configuration
    print "Adding config pairs"
    from dbconfigfiller import fill_config
    config = fill_config()      # requires Group model to be filled in (because of config options validation)
    
    
    # add users to default groups
    print "Adding default user to some groups"
    from baseapp.config import Config
    config=Config()

    if len(User.objects.all()) < 1:
        add_users()
    u = User.objects.get(username='******')
    for group_name in config.get_list('user_after_registration_groups'):
        u.groups.add(Group.objects.get(name=group_name))
        u.groups.add(Group.objects.get(name="Admins"))
    
    u = User.objects.get(username='******')
    for group_name in config.get_list('user_after_registration_groups'):
        u.groups.add(Group.objects.get(name=group_name))
    
    u = User.objects.get(username='******')
    for group_name in config.get_list('user_after_registration_groups'):
        u.groups.add(Group.objects.get(name=group_name))
        u.groups.add(Group.objects.get(name="Librarians"))
Ejemplo n.º 2
0
def populate_groups():
    from django.contrib.auth.models import Permission, Group

    # add few groups
    def readd_group(group_name, perms=[], direct_add=False):
        """
        Add permission from perms to group_name group.
        If group doesn't exist, new one is created.
        If direct_add is True, then perms is assumed to be Permission's instance. Otherwise it should be a string.
        """
        g = None
        try:
            # delete group if exist
            Group.objects.get(name=group_name).delete()
        except Group.DoesNotExist:
            pass
        # create a new one
        g = Group(name=group_name)
        g.save()
        for perm in perms:
            if direct_add or isinstance(perm, Permission):
                p = perm
            else:
                p = Permission.objects.get(codename=perm)
            assert isinstance(p, Permission)
            g.permissions.add(p)
        g.save()

    print "Adding app specific groups"
    from dbfiller_perms import readers_perms, admins_perms, librarians_perms
    readd_group('Readers', perms=readers_perms, direct_add=True)
    readd_group('Librarians', perms=librarians_perms, direct_add=True)
    readd_group('Admins', perms=admins_perms, direct_add=True)

    # fill configuration
    print "Adding config pairs"
    from dbconfigfiller import fill_config
    config = fill_config(
    )  # requires Group model to be filled in (because of config options validation)

    # add users to default groups
    print "Adding default user to some groups"
    from baseapp.config import Config
    config = Config()

    if len(User.objects.all()) < 1:
        add_users()
    u = User.objects.get(username='******')
    for group_name in config.get_list('user_after_registration_groups'):
        u.groups.add(Group.objects.get(name=group_name))
        u.groups.add(Group.objects.get(name="Admins"))

    u = User.objects.get(username='******')
    for group_name in config.get_list('user_after_registration_groups'):
        u.groups.add(Group.objects.get(name=group_name))

    u = User.objects.get(username='******')
    for group_name in config.get_list('user_after_registration_groups'):
        u.groups.add(Group.objects.get(name=group_name))
        u.groups.add(Group.objects.get(name="Librarians"))
Ejemplo n.º 3
0
    def setUp(self):
        typenames = ['int', 'bool', 'list_groupnames', 'unicode']
        for typename in typenames:
            ConfigurationValueType(name=typename).save()
        t_int = ConfigurationValueType.objects.get(name='int')
        t_bool = ConfigurationValueType.objects.get(name='bool')
        t_unicode = ConfigurationValueType.objects.get(name='unicode')
        #        t_list_groupnames = ConfigurationValueType.objects.get(name='list_groupnames')

        user = User.objects.get(pk=1)
        self.c = Config(user)

        data = [
            ('mickey_mouse_creator', 'Disney', t_unicode),
            ('random_text', 'p2835ybnas12da', t_unicode),
            ('most_funny_number', '8', t_int),
            ('some_true_value', 'true', t_bool),
            ('some_false_value', 'false', t_bool),
            ('some_bool_value', 'false', t_bool),
            #            ('simple_int_list', '[1, 2, 7]'),
            #            ('empty_list', '[]'),
        ]
        for k, v, t in data:
            ConfigModel(key=k, value=v, type=t).save()
Ejemplo n.º 4
0
    def setUp(self):
        typenames = ['int', 'bool', 'list_groupnames', 'unicode']
        for typename in typenames:
            ConfigurationValueType(name=typename).save()
        t_int = ConfigurationValueType.objects.get(name='int')
        t_bool = ConfigurationValueType.objects.get(name='bool')
        t_unicode = ConfigurationValueType.objects.get(name='unicode')
#        t_list_groupnames = ConfigurationValueType.objects.get(name='list_groupnames')

        user = User.objects.get(pk=1)
        self.c = Config(user)
        
        data = [
            ('mickey_mouse_creator', 'Disney', t_unicode),
            ('random_text', 'p2835ybnas12da', t_unicode),
            ('most_funny_number', '8', t_int),
            ('some_true_value', 'true', t_bool),
            ('some_false_value', 'false', t_bool),
            ('some_bool_value', 'false', t_bool),
#            ('simple_int_list', '[1, 2, 7]'),
#            ('empty_list', '[]'),
            ]
        for k, v, t in data:
            ConfigModel(key=k, value=v, type=t).save()
Ejemplo n.º 5
0
def fill_config():
    from baseapp.config import Config
    config = Config()
    config.clear(truncate_config=True)
    fill_types()

    t_int = ConfigurationValueType.objects.get(name='int')
    t_bool = ConfigurationValueType.objects.get(name='bool')
    t_unicode = ConfigurationValueType.objects.get(name='unicode')
    t_list_groupnames = ConfigurationValueType.objects.get(
        name='list_groupnames')
    # t_list_any  = ConfigurationValueType.objects.get(name='list_any')
    # t_list_str  = ConfigurationValueType.objects.get(name='list_str')
    # t_list_int  = ConfigurationValueType.objects.get(name='list_int')
    # t_list_bool = ConfigurationValueType.objects.get(name='list_bool')

    # registration
    _svd(config, t_list_groupnames, False, 'user_after_registration_groups',
         ['Readers'], "User joins these groups right after he is registered")

    # emails
    _svd(config, t_bool, False, 'send_emails', True,
         "True iff app will send emails.")
    _svd(
        config, t_bool, False, 'log_send_emails', True,
        "True iff send emails will be stored in db. Logging doesn't care about send_emails value"
    )
    _svd(config, t_unicode, False, 'default_email_sender',
         u'NSN library <*****@*****.**>',
         "From what address user receives emails")
    _svd(config, t_unicode, False, 'default_email_subject',
         u'NSN library notification',
         "With what subjects user receives emails")

    # reservation/rental
    _svd(config, t_int, False, 'rental_duration', 30,
         "For how long you rent a book")
    _svd(config, t_int, False, 'reservation_duration', 30,
         "For how long you can reserve a book")
    _svd(config, t_int, False, 'reservation_rush', 4,
         "How quick you need to rent reserved book when it becomes available")
    _svd(
        config, t_unicode, False, 'message_book_reserved',
        u'Reservation active since %s till %s',
        "Message to show right after user reserves a book. Has to contain exactly two `%s` which will be filled with reservation start and end date"
    )
    _svd(
        config, t_unicode, False, 'message_book_rented',
        u'Rental made untill %s.',
        "Message to show right after user rents a book. Has to contain exactly one `%s` which will be filled with rental end date"
    )
    _svd(
        config, t_int, False, 'due_remind_time', 3,
        "How many days before due date (reservation end date) user will be reminded to return book"
    )

    # book request
    _svd(config, t_int, False, 'book_request_info_min_len', 10,
         "Minimal length of book request information")
    _svd(
        config, t_unicode, False, 'book_request_bookinfo_template',
        u'Title:\n\n\nAuthors:\n\n\nNumber of copies:\n\n\nSuggested locations:\n\n\nAdditional info:\n\n',
        "Template which is displayed to help in filling request book form")
    _svd(
        config, t_unicode, False, 'book_request_copyinfo_template',
        u'Number of copies:\n\n\nSuggested locations:\n\n\nAdditional info:\n\n',
        "Template which is displayed to help in filling request book form")

    # searching
    _svd(
        config, t_int, True, 'copies_location_select_size', 5,
        "Number of location elements to display in select list when filtering copies of a book"
    )
    _svd(
        config, t_int, True, 'categories_select_size', 6,
        "Number of categories displayed in select list while filtering books")
    _svd(
        config, t_bool, True, 'list_only_existing_categories_in_search', True,
        "True iff in booklist (book search, not book copy search) only those categories will be listed, that exist a book (in database) with such category."
    )
    _svd(
        config, t_bool, True, 'cut_categories_list_to_found_books', False,
        "True iff in booklist (book search, not book copy search) only those categories will be listed, that exist a book (in results) with such category."
    )
    _svd(
        config, t_int, False, 'when_reserved_period', 90,
        "When listing book copies, it says for how many days forward user will be shown when a copy is reserved."
    )
    _svd(config, t_bool, True, 'list_all_books_as_default', False,
         "If true then in searching all books will be listed as default")
    _svd(
        config, t_bool, True, 'show_nr_of_available_copies', False,
        "When listing books (not copies) this shows number of currently available copies of each book. Warning: this is much slower than normal listing books."
    )

    # time bar
    _svd(config, t_bool, False, 'enable_time_bar', True,
         "True iff time bar is displayed.")
    _svd(
        config, t_int, False, 'tb_max_days_in_date_range', 365,
        "Time bar. Max number of days date range can describe. If wider then the range will be shortened."
    )
    _svd(
        config, t_int, False, 'tb_max_days_to_display_days', 10,
        "Time bar. Max number of days in date range, for which scale unit will be one day."
    )
    _svd(
        config, t_int, False, 'tb_max_days_to_display_weeks', 40,
        "Time bar. Max number of days in date range, for which scale unit will be one week (or one day, see tb_max_days_to_display_days)."
    )

    # global
    _svd(config, t_unicode, False, 'application_url',
         'http://glonull1.mobile.fp.nsn-rdnet.net:8080',
         "URL under which app is running.")

    # misc
    _svd(
        config, t_bool, False, 'is_cost_center_visible_to_anyone', False,
        "True iff copy's cost center info is visible to anyone (= no perms required)"
    )
    _svd(config, t_bool, True, 'display_tips', True,
         "True iff tips are visible")
    _svd(config, t_bool, False, 'display_only_editable_config_options', True,
         "True iff user see only editable options.")
    _svd(config, t_unicode, False, 'default_go_back_link_name', u'Back',
         "Name of link displayed when filtering books/copies/...")
    return config
Ejemplo n.º 6
0
                                              to_date=to_date)
            context['tb_code'] = code
        return context

    def get_codes_for_copies(self, copies):
        """
        Return html for given copy.
        
        Args:  
            copies -- list of copies (BookCopy objects), for which time bar will be generated.
            
        Returns:
            dict { copy.id : time-bar-html-code }
        """
        request_values = self.handle_request()
        from_date, to_date = request_values['date_range']

        codes = {}
        for copy in copies:
            codes[copy.id] = get_time_bar_code_for_copy(self.config,
                                                        copy,
                                                        from_date=from_date,
                                                        to_date=to_date)
        return codes


if __name__ == '__main__':
    config = Config()
    t = TimeBar(config)
    t.run(False)
Ejemplo n.º 7
0
 def setUp(self):
     self.user = User.objects.get(pk=1)
     self.config = Config(self.user)
     # self.config = fill_config()
     self.form = ProfileEditForm(self.user) 
Ejemplo n.º 8
0
 def setUp(self):
     self.user = User.objects.get(pk=1)
     self.config = Config(self.user)
Ejemplo n.º 9
0
 def setUp(self):
     self.t = TimeBar(Config(), one=1)
Ejemplo n.º 10
0
 def setUp(self):
     # self.config = fill_config()
     self.config = Config()
Ejemplo n.º 11
0
def fill_config():
    from baseapp.config import Config
    config = Config()
    config.clear(truncate_config=True)
    fill_types()
    
    t_int       = ConfigurationValueType.objects.get(name='int')
    t_bool      = ConfigurationValueType.objects.get(name='bool')
    t_unicode   = ConfigurationValueType.objects.get(name='unicode')
    t_list_groupnames= ConfigurationValueType.objects.get(name='list_groupnames')
    # t_list_any  = ConfigurationValueType.objects.get(name='list_any')
    # t_list_str  = ConfigurationValueType.objects.get(name='list_str')
    # t_list_int  = ConfigurationValueType.objects.get(name='list_int')
    # t_list_bool = ConfigurationValueType.objects.get(name='list_bool')

    # registration
    _svd(config, t_list_groupnames, False, 'user_after_registration_groups', ['Readers'],      "User joins these groups right after he is registered")

    # emails
    _svd(config, t_bool, False, 'send_emails',                             True,                           "True iff app will send emails.")
    _svd(config, t_bool, False, 'log_send_emails',                         True,                           "True iff send emails will be stored in db. Logging doesn't care about send_emails value")
    _svd(config, t_unicode, False, 'default_email_sender',  u'NSN library <*****@*****.**>', "From what address user receives emails")
    _svd(config, t_unicode, False, 'default_email_subject', u'NSN library notification',                   "With what subjects user receives emails")

    # reservation/rental
    _svd(config, t_int, False, 'rental_duration',                            30,                       "For how long you rent a book")
    _svd(config, t_int, False, 'reservation_duration',                       30,                       "For how long you can reserve a book")
    _svd(config, t_int, False, 'reservation_rush',                            4,                       "How quick you need to rent reserved book when it becomes available")
    _svd(config, t_unicode, False, 'message_book_reserved',  u'Reservation active since %s till %s',   "Message to show right after user reserves a book. Has to contain exactly two `%s` which will be filled with reservation start and end date")
    _svd(config, t_unicode, False, 'message_book_rented',    u'Rental made untill %s.',                "Message to show right after user rents a book. Has to contain exactly one `%s` which will be filled with rental end date")
    _svd(config, t_int, False, 'due_remind_time',                             3,                       "How many days before due date (reservation end date) user will be reminded to return book")

    # book request
    _svd(config, t_int, False, 'book_request_info_min_len',                  10,                       "Minimal length of book request information")
    _svd(config, t_unicode, False, 'book_request_bookinfo_template', u'Title:\n\n\nAuthors:\n\n\nNumber of copies:\n\n\nSuggested locations:\n\n\nAdditional info:\n\n',   "Template which is displayed to help in filling request book form")
    _svd(config, t_unicode, False, 'book_request_copyinfo_template', u'Number of copies:\n\n\nSuggested locations:\n\n\nAdditional info:\n\n',   "Template which is displayed to help in filling request book form")

    # searching
    _svd(config, t_int,  True , 'copies_location_select_size',                5,        "Number of location elements to display in select list when filtering copies of a book")
    _svd(config, t_int,  True , 'categories_select_size',                     6,        "Number of categories displayed in select list while filtering books")
    _svd(config, t_bool, True , 'list_only_existing_categories_in_search', True,        "True iff in booklist (book search, not book copy search) only those categories will be listed, that exist a book (in database) with such category.")
    _svd(config, t_bool, True , 'cut_categories_list_to_found_books',     False,        "True iff in booklist (book search, not book copy search) only those categories will be listed, that exist a book (in results) with such category.")
    _svd(config, t_int,  False, 'when_reserved_period',                      90,        "When listing book copies, it says for how many days forward user will be shown when a copy is reserved.")
    _svd(config, t_bool, True,  'list_all_books_as_default',              False,        "If true then in searching all books will be listed as default")
    _svd(config, t_bool, True,  'show_nr_of_available_copies',            False,        "When listing books (not copies) this shows number of currently available copies of each book. Warning: this is much slower than normal listing books.")

    # time bar
    _svd(config, t_bool, False, 'enable_time_bar',                         True,        "True iff time bar is displayed.")
    _svd(config, t_int,  False, 'tb_max_days_in_date_range',                365,        "Time bar. Max number of days date range can describe. If wider then the range will be shortened.")
    _svd(config, t_int,  False, 'tb_max_days_to_display_days',               10,        "Time bar. Max number of days in date range, for which scale unit will be one day.")
    _svd(config, t_int,  False, 'tb_max_days_to_display_weeks',              40,        "Time bar. Max number of days in date range, for which scale unit will be one week (or one day, see tb_max_days_to_display_days).")

    # global
    _svd(config, t_unicode,  False, 'application_url', 'http://glonull1.mobile.fp.nsn-rdnet.net:8080',
                                                                                        "URL under which app is running.")

    # misc
    _svd(config, t_bool, False, 'is_cost_center_visible_to_anyone',       False,        "True iff copy's cost center info is visible to anyone (= no perms required)")
    _svd(config, t_bool, True , 'display_tips',                            True,        "True iff tips are visible")
    _svd(config, t_bool, False, 'display_only_editable_config_options',    True,        "True iff user see only editable options.")
    _svd(config, t_unicode, False, 'default_go_back_link_name',         u'Back',     "Name of link displayed when filtering books/copies/...")
    return config
Ejemplo n.º 12
0
 def __init__(self, link_name):
     if not link_name:
         config = Config()
         link_name = config.get_str("default_go_back_link_name")
     self.link_name = link_name
Ejemplo n.º 13
0
 def __init__(self, link_name):
     if not link_name:
         config = Config()
         link_name = config.get_str('default_go_back_link_name')
     self.link_name = link_name
Ejemplo n.º 14
0
 def setUp(self):
     self.time_bar = TimeBar(Config(), one=1)
Ejemplo n.º 15
0
 def setUp(self):
     user = User.objects.get(pk=1)
     self.c = Config(user=user)
Ejemplo n.º 16
0
class BaseConfigTest(TestCase):
    '''
    Tests for configuration stored in database and accessed via Config module.
    Checks setting and getting keys and values in config.
    '''

    fixtures = ['active_user.json']
    
    def setUp(self):
        typenames = ['int', 'bool', 'list_groupnames', 'unicode']
        for typename in typenames:
            ConfigurationValueType(name=typename).save()
        t_int = ConfigurationValueType.objects.get(name='int')
        t_bool = ConfigurationValueType.objects.get(name='bool')
        t_unicode = ConfigurationValueType.objects.get(name='unicode')
#        t_list_groupnames = ConfigurationValueType.objects.get(name='list_groupnames')

        user = User.objects.get(pk=1)
        self.c = Config(user)
        
        data = [
            ('mickey_mouse_creator', 'Disney', t_unicode),
            ('random_text', 'p2835ybnas12da', t_unicode),
            ('most_funny_number', '8', t_int),
            ('some_true_value', 'true', t_bool),
            ('some_false_value', 'false', t_bool),
            ('some_bool_value', 'false', t_bool),
#            ('simple_int_list', '[1, 2, 7]'),
#            ('empty_list', '[]'),
            ]
        for k, v, t in data:
            ConfigModel(key=k, value=v, type=t).save()

    def test_containing(self):
        ''' Checks if config contains values set up in setUp method. '''
        self.assertTrue('most_funny_number' in self.c)
        self.assertTrue('some_true_value' in self.c)
        self.assertTrue('some_false_value' in self.c)
        self.assertTrue('simple_int_list' in self.c)
        self.assertTrue('empty_list' in self.c)
        self.assertFalse('this_string_is_not_in_config' in self.c)


    ''' string tests '''
    def test_get_string(self):
        self.assertEqual('Disney', self.c['mickey_mouse_creator'])

    def test_updating_string_with_brackets(self):
        self.c['mickey_mouse_creator'] = 'Walt Disney'
        self.assertEqual(unicode, type(self.c.get_str('mickey_mouse_creator')))
        self.assertEqual('Walt Disney', self.c.get_str('mickey_mouse_creator'))

    def test_updating_string_with_setter(self):
        m_key, m_value = u'mickey_mouse_creator', u'Walt Disney'
        self.c.set_str(m_key, m_value)
        self.assertEqual(unicode, type(self.c.get_str(m_key)))
        self.assertEqual(m_value, self.c.get_str(m_key))

        r_key, r_value = u'random_text', u'sadjboqi73t2fhj'
        self.c.set_str(r_key, r_value)
        self.assertEqual(unicode, type(self.c[r_key]))
        self.assertEqual(r_value, self.c[r_key])

    def test_creating_string_with_brackets(self):
        self.c['almost_random_prefix'] = 'tralala'
        self.assertEqual('tralala', self.c['almost_random_prefix'])

    def test_creating_string_with_setter(self):
        self.c.set_str('almost_random_prefix', 'tralala')
        self.assertEqual('tralala', self.c['almost_random_prefix'])


    ''' int tests '''
    def test_get_int(self):
        self.assertEqual(8, self.c.get_int('most_funny_number'))

    def test_updating_int_with_brackets(self):
        self.c['most_funny_number'] = 42
        self.assertEqual(type(42), type(self.c.get_int('most_funny_number')))
        self.assertEqual(42, self.c.get_int('most_funny_number'))

    def test_updating_int_with_setter(self):
        self.c.set_int('most_funny_number', 42)
        self.assertEqual(type(42), type(self.c.get_int('most_funny_number')))
        self.assertEqual(42, self.c.get_int('most_funny_number'))

    def test_creating_int_with_brackets(self):
        self.c['some_int_name'] = 123654
        self.assertEqual(123654, self.c.get_int('some_int_name'))

    def test_creating_int_with_setter(self):
        self.c.set_int('some_int_name', 123654)
        self.assertEqual(123654, self.c.get_int('some_int_name'))


    ''' bool tests '''
    def test_get_bool(self):
        self.assertEqual(True, self.c.get_bool('some_true_value'))
        self.assertEqual(False, self.c.get_bool('some_false_value'))

    def test_updating_bool_with_brackets(self):
        self.c['some_bool_value'] = True
        self.assertEqual(type(True), type(self.c.get_bool('some_bool_value')))
        self.assertEqual(True, self.c.get_bool('some_bool_value'))
        #
        self.c['some_bool_value'] = False
        self.assertEqual(type(False), type(self.c.get_bool('some_bool_value')))
        self.assertEqual(False, self.c.get_bool('some_bool_value'))

    def test_updating_bool_with_setter(self):
        self.c.set_bool('some_bool_value', True)
        self.assertEqual(type(True), type(self.c.get_bool('some_bool_value')))
        self.assertEqual(True, self.c.get_bool('some_bool_value'))
        #
        self.c.set_bool('some_bool_value', False)
        self.assertEqual(type(False), type(self.c.get_bool('some_bool_value')))
        self.assertEqual(False, self.c.get_bool('some_bool_value'))

    def test_creating_bool_with_brackets(self):
        self.c['green_apples_exists'] = True
        self.assertEqual(Config._true_value, self.c['green_apples_exists'])           # when using brackets Config doesn't know value's type
        self.assertEqual(type(True), type(self.c.get_bool('green_apples_exists')))    # so you should use get_bool() while _true_value is private
        self.assertEqual(True, self.c.get_bool('green_apples_exists'))
        self.assertEqual(False, not self.c.get_bool('green_apples_exists'))

    def test_creating_bool_with_setter(self):
        self.c.set_bool('green_apples_exists', True)
        self.assertEqual(Config._true_value, self.c['green_apples_exists'])           # when using brackets Config doesn't know value's type
        self.assertEqual(type(True), type(self.c.get_bool('green_apples_exists')))    # so you should use get_bool() while _true_value is private
        self.assertEqual(True, self.c.get_bool('green_apples_exists'))
        self.assertEqual(False, not self.c.get_bool('green_apples_exists'))


    ''' list tests '''
    def test_get_list(self):
        self.assertEqual([1,2,7], self.c.get_list('simple_int_list'))
        self.assertEqual([], self.c.get_list('empty_list'))

    def test_updating_list_with_brackets(self):
        self.c['simple_int_list'] = [5, 25, 256, 20]
        self.assertEqual(type([]), type(self.c.get_list('simple_int_list')))
        self.assertEqual([5, 25, 256, 20], self.c.get_list('simple_int_list'))
        #
        self.c['simple_int_list'] = []
        self.assertEqual(type([]), type(self.c.get_list('simple_int_list')))
        self.assertEqual([], self.c.get_list('simple_int_list'))

    def test_updating_list_with_setter(self):
        self.c.set_list('simple_int_list', [5, 25, 256, 20])
        self.assertEqual(type([]), type(self.c.get_list('simple_int_list')))
        self.assertEqual([5, 25, 256, 20], self.c.get_list('simple_int_list'))
        #
        self.c.set_list('simple_int_list', [])
        self.assertEqual(type([]), type(self.c.get_list('simple_int_list')))
        self.assertEqual([], self.c.get_list('simple_int_list'))

    def test_creating_list_with_brackets(self):
        self.c['mixed_list'] = [1, 3.1416,'hello', "world"]
        self.assertEqual(type([]), type(self.c.get_list('mixed_list')))
        self.assertEqual([1,3.1416, 'hello', "world"], self.c.get_list('mixed_list'))

    def test_creating_list_with_setter(self):
        self.c.set_list('mixed_list', [1, 3.1416,'hello', "world"])
        self.assertEqual(type([]), type(self.c.get_list('mixed_list')))
        self.assertEqual([1,3.1416, 'hello', "world"], self.c.get_list('mixed_list'))
Ejemplo n.º 17
0
class BaseConfigTest(TestCase):
    '''
    Tests for configuration stored in database and accessed via Config module.
    Checks setting and getting keys and values in config.
    '''

    fixtures = ['active_user.json']

    def setUp(self):
        typenames = ['int', 'bool', 'list_groupnames', 'unicode']
        for typename in typenames:
            ConfigurationValueType(name=typename).save()
        t_int = ConfigurationValueType.objects.get(name='int')
        t_bool = ConfigurationValueType.objects.get(name='bool')
        t_unicode = ConfigurationValueType.objects.get(name='unicode')
        #        t_list_groupnames = ConfigurationValueType.objects.get(name='list_groupnames')

        user = User.objects.get(pk=1)
        self.c = Config(user)

        data = [
            ('mickey_mouse_creator', 'Disney', t_unicode),
            ('random_text', 'p2835ybnas12da', t_unicode),
            ('most_funny_number', '8', t_int),
            ('some_true_value', 'true', t_bool),
            ('some_false_value', 'false', t_bool),
            ('some_bool_value', 'false', t_bool),
            #            ('simple_int_list', '[1, 2, 7]'),
            #            ('empty_list', '[]'),
        ]
        for k, v, t in data:
            ConfigModel(key=k, value=v, type=t).save()

    def test_containing(self):
        ''' Checks if config contains values set up in setUp method. '''
        self.assertTrue('most_funny_number' in self.c)
        self.assertTrue('some_true_value' in self.c)
        self.assertTrue('some_false_value' in self.c)
        self.assertTrue('simple_int_list' in self.c)
        self.assertTrue('empty_list' in self.c)
        self.assertFalse('this_string_is_not_in_config' in self.c)

    ''' string tests '''

    def test_get_string(self):
        self.assertEqual('Disney', self.c['mickey_mouse_creator'])

    def test_updating_string_with_brackets(self):
        self.c['mickey_mouse_creator'] = 'Walt Disney'
        self.assertEqual(unicode, type(self.c.get_str('mickey_mouse_creator')))
        self.assertEqual('Walt Disney', self.c.get_str('mickey_mouse_creator'))

    def test_updating_string_with_setter(self):
        m_key, m_value = u'mickey_mouse_creator', u'Walt Disney'
        self.c.set_str(m_key, m_value)
        self.assertEqual(unicode, type(self.c.get_str(m_key)))
        self.assertEqual(m_value, self.c.get_str(m_key))

        r_key, r_value = u'random_text', u'sadjboqi73t2fhj'
        self.c.set_str(r_key, r_value)
        self.assertEqual(unicode, type(self.c[r_key]))
        self.assertEqual(r_value, self.c[r_key])

    def test_creating_string_with_brackets(self):
        self.c['almost_random_prefix'] = 'tralala'
        self.assertEqual('tralala', self.c['almost_random_prefix'])

    def test_creating_string_with_setter(self):
        self.c.set_str('almost_random_prefix', 'tralala')
        self.assertEqual('tralala', self.c['almost_random_prefix'])

    ''' int tests '''

    def test_get_int(self):
        self.assertEqual(8, self.c.get_int('most_funny_number'))

    def test_updating_int_with_brackets(self):
        self.c['most_funny_number'] = 42
        self.assertEqual(type(42), type(self.c.get_int('most_funny_number')))
        self.assertEqual(42, self.c.get_int('most_funny_number'))

    def test_updating_int_with_setter(self):
        self.c.set_int('most_funny_number', 42)
        self.assertEqual(type(42), type(self.c.get_int('most_funny_number')))
        self.assertEqual(42, self.c.get_int('most_funny_number'))

    def test_creating_int_with_brackets(self):
        self.c['some_int_name'] = 123654
        self.assertEqual(123654, self.c.get_int('some_int_name'))

    def test_creating_int_with_setter(self):
        self.c.set_int('some_int_name', 123654)
        self.assertEqual(123654, self.c.get_int('some_int_name'))

    ''' bool tests '''

    def test_get_bool(self):
        self.assertEqual(True, self.c.get_bool('some_true_value'))
        self.assertEqual(False, self.c.get_bool('some_false_value'))

    def test_updating_bool_with_brackets(self):
        self.c['some_bool_value'] = True
        self.assertEqual(type(True), type(self.c.get_bool('some_bool_value')))
        self.assertEqual(True, self.c.get_bool('some_bool_value'))
        #
        self.c['some_bool_value'] = False
        self.assertEqual(type(False), type(self.c.get_bool('some_bool_value')))
        self.assertEqual(False, self.c.get_bool('some_bool_value'))

    def test_updating_bool_with_setter(self):
        self.c.set_bool('some_bool_value', True)
        self.assertEqual(type(True), type(self.c.get_bool('some_bool_value')))
        self.assertEqual(True, self.c.get_bool('some_bool_value'))
        #
        self.c.set_bool('some_bool_value', False)
        self.assertEqual(type(False), type(self.c.get_bool('some_bool_value')))
        self.assertEqual(False, self.c.get_bool('some_bool_value'))

    def test_creating_bool_with_brackets(self):
        self.c['green_apples_exists'] = True
        self.assertEqual(
            Config._true_value, self.c['green_apples_exists']
        )  # when using brackets Config doesn't know value's type
        self.assertEqual(
            type(True), type(self.c.get_bool('green_apples_exists'))
        )  # so you should use get_bool() while _true_value is private
        self.assertEqual(True, self.c.get_bool('green_apples_exists'))
        self.assertEqual(False, not self.c.get_bool('green_apples_exists'))

    def test_creating_bool_with_setter(self):
        self.c.set_bool('green_apples_exists', True)
        self.assertEqual(
            Config._true_value, self.c['green_apples_exists']
        )  # when using brackets Config doesn't know value's type
        self.assertEqual(
            type(True), type(self.c.get_bool('green_apples_exists'))
        )  # so you should use get_bool() while _true_value is private
        self.assertEqual(True, self.c.get_bool('green_apples_exists'))
        self.assertEqual(False, not self.c.get_bool('green_apples_exists'))

    ''' list tests '''

    def test_get_list(self):
        self.assertEqual([1, 2, 7], self.c.get_list('simple_int_list'))
        self.assertEqual([], self.c.get_list('empty_list'))

    def test_updating_list_with_brackets(self):
        self.c['simple_int_list'] = [5, 25, 256, 20]
        self.assertEqual(type([]), type(self.c.get_list('simple_int_list')))
        self.assertEqual([5, 25, 256, 20], self.c.get_list('simple_int_list'))
        #
        self.c['simple_int_list'] = []
        self.assertEqual(type([]), type(self.c.get_list('simple_int_list')))
        self.assertEqual([], self.c.get_list('simple_int_list'))

    def test_updating_list_with_setter(self):
        self.c.set_list('simple_int_list', [5, 25, 256, 20])
        self.assertEqual(type([]), type(self.c.get_list('simple_int_list')))
        self.assertEqual([5, 25, 256, 20], self.c.get_list('simple_int_list'))
        #
        self.c.set_list('simple_int_list', [])
        self.assertEqual(type([]), type(self.c.get_list('simple_int_list')))
        self.assertEqual([], self.c.get_list('simple_int_list'))

    def test_creating_list_with_brackets(self):
        self.c['mixed_list'] = [1, 3.1416, 'hello', "world"]
        self.assertEqual(type([]), type(self.c.get_list('mixed_list')))
        self.assertEqual([1, 3.1416, 'hello', "world"],
                         self.c.get_list('mixed_list'))

    def test_creating_list_with_setter(self):
        self.c.set_list('mixed_list', [1, 3.1416, 'hello', "world"])
        self.assertEqual(type([]), type(self.c.get_list('mixed_list')))
        self.assertEqual([1, 3.1416, 'hello', "world"],
                         self.c.get_list('mixed_list'))
Ejemplo n.º 18
0
from baseapp.models import *
from django.contrib.auth.models import User
from baseapp.utils import today, after_days
from baseapp.config import Config
from datetime import datetime
import baseapp.views_aux as aux
import baseapp.emails as mail

for r in Rental.objects.all():
    if not r.end_date:
        if r.reservation.end_date < today(
        ):  # reservation expired: notify reader every day
            mail.overdued(r)
        if r.reservation.end_date == after_days(
                Config().get_int('due_remind_time')):
            mail.returnal_date_coming(
                r)  # reservation will expire soon: notify reader

for r in Reservation.objects.filter(aux.Q_reservation_active):
    if not r.active_since and aux.is_reservation_rentable(r):
        # reservation has just become active - notify user
        r.active_since = today()
        r.save()
        mail.reservation_active(r)

    if r.active_since and r.active_since <= after_days(
            -1 * Config().get_int('reservation_rush')):
        # reservation has been active for 'reservation_rush' days, so it expires
        r.when_cancelled = datetime.now()
        r.save()
Ejemplo n.º 19
0
 def setUp(self):
     # self.config = fill_config()
     self.config = Config()
     self.login('superadmin', 'superadmin')