Пример #1
0
 def testSuperAccepterSingle(self):
     backends_by_class = super_accepter(EpicFailBackend, ALERT_BACKENDS)
     backends_by_id = super_accepter("EpicFail", ALERT_BACKENDS)
     
     self.assertEqual(len(backends_by_class), 1)
     self.assertEqual(len(backends_by_id), 1)
     self.assertEqual(backends_by_class, backends_by_id)
Пример #2
0
    def testSuperAccepterSingle(self):
        backends_by_class = super_accepter(EpicFailBackend, ALERT_BACKENDS)
        backends_by_id = super_accepter("EpicFail", ALERT_BACKENDS)

        self.assertEqual(len(backends_by_class), 1)
        self.assertEqual(len(backends_by_id), 1)
        self.assertEqual(backends_by_class, backends_by_id)
Пример #3
0
 def __init__(self, *args, **kwargs):
     kwargs = kwargs.copy()
     alerts = kwargs.pop('alerts', None)
     backends = kwargs.pop('backends', None)
     
     if 'user' not in kwargs.keys():
         raise TypeError("The \"user\" keyword argument is required but no keyword argument \"user\" was passed")
     
     user = kwargs.pop('user')
             
     self.user = user
     self.alerts = super_accepter(alerts, ALERT_TYPES)
     self.backends = super_accepter(backends, ALERT_BACKENDS)
     self.prefs = AlertPreference.objects.get_user_prefs(user).items()
     
     super(AlertPreferenceForm, self).__init__(*args, **kwargs)
     
     ids = lambda lst: (x.id for x in lst)
     
     for ((alert_type, backend), pref) in self.prefs:
         if (alert_type not in ids(self.alerts) or backend not in ids(self.backends)): 
             continue
         
         attr = self._field_id(alert_type, backend)
         alert = ALERT_TYPES[alert_type]
         self.fields[attr] = forms.BooleanField(
                                                label=alert.title, 
                                                help_text=alert.description,
                                                initial=pref,
                                                required=False
                                                )
Пример #4
0
    def __init__(self, *args, **kwargs):
        kwargs = kwargs.copy()
        alerts = kwargs.pop('alerts', None)
        backends = kwargs.pop('backends', None)

        if 'user' not in kwargs.keys():
            raise TypeError(
                "The \"user\" keyword argument is required but no keyword argument \"user\" was passed"
            )

        user = kwargs.pop('user')

        self.user = user
        self.alerts = super_accepter(alerts, ALERT_TYPES)
        self.backends = super_accepter(backends, ALERT_BACKENDS)
        self.prefs = AlertPreference.objects.get_user_prefs(user).items()

        super(AlertPreferenceForm, self).__init__(*args, **kwargs)

        ids = lambda lst: (x.id for x in lst)

        for ((alert_type, backend), pref) in self.prefs:
            if (alert_type not in ids(self.alerts)
                    or backend not in ids(self.backends)):
                continue

            attr = self._field_id(alert_type, backend)
            alert = ALERT_TYPES[alert_type]
            self.fields[attr] = forms.BooleanField(label=alert.title,
                                                   help_text=alert.description,
                                                   initial=pref,
                                                   required=False)
Пример #5
0
 def testSuperAccepterList(self):
     backends_by_class = super_accepter([EpicFailBackend, DummyBackend], ALERT_BACKENDS)
     backends_by_id = super_accepter(["EpicFail", "DummyBackend"], ALERT_BACKENDS)
     backends_by_mixed = super_accepter(["EpicFail", DummyBackend], ALERT_BACKENDS)
     
     self.assertEqual(len(backends_by_class), 2)
     self.assertEqual(len(backends_by_id), 2)
     self.assertEqual(len(backends_by_mixed), 2)
     
     self.assertEqual(backends_by_class, backends_by_id)
     self.assertEqual(backends_by_class, backends_by_mixed)
     self.assertEqual(backends_by_mixed, backends_by_id)
Пример #6
0
 def testSuperAccepterList(self):
     backends_by_class = super_accepter([EpicFailBackend, DummyBackend], ALERT_BACKENDS)
     backends_by_id = super_accepter(["EpicFail", "DummyBackend"], ALERT_BACKENDS)
     backends_by_mixed = super_accepter(["EpicFail", DummyBackend], ALERT_BACKENDS)
     
     self.assertEqual(len(backends_by_class), 2)
     self.assertEqual(len(backends_by_id), 2)
     self.assertEqual(len(backends_by_mixed), 2)
     
     self.assertEqual(backends_by_class, backends_by_id)
     self.assertEqual(backends_by_class, backends_by_mixed)
     self.assertEqual(backends_by_mixed, backends_by_id)
Пример #7
0
 def testSuperAccepterDuplicates(self):
     backends = super_accepter([EpicFailBackend, DummyBackend, "EpicFail"], ALERT_BACKENDS)
     self.assertEqual(len(backends), 2)
Пример #8
0
 def testSuperAccepterNone(self):
     types = super_accepter(None, ALERT_TYPES)
     backends = super_accepter(None, ALERT_BACKENDS)
     
     self.assertEqual(len(types), len(ALERT_TYPES))
     self.assertEqual(len(backends), len(ALERT_BACKENDS))
Пример #9
0
 def testSuperAccepterDuplicates(self):
     backends = super_accepter([EpicFailBackend, DummyBackend, "EpicFail"],
                               ALERT_BACKENDS)
     self.assertEqual(len(backends), 2)
Пример #10
0
    def testSuperAccepterNone(self):
        types = super_accepter(None, ALERT_TYPES)
        backends = super_accepter(None, ALERT_BACKENDS)

        self.assertEqual(len(types), len(ALERT_TYPES))
        self.assertEqual(len(backends), len(ALERT_BACKENDS))