def test_unregister(self):
     gen = AbstractKeyGenerator()
     gen.register()
     registry = Registry()
     self.assertEqual(registry.get('abstract'), gen)
     gen.unregister()
     self.assertRaises(GeneratorError, registry.get, 'abstract')
Beispiel #2
0
 def test_unregister(self):
     gen = AbstractKeyGenerator()
     gen.register()
     registry = Registry()
     self.assertEqual(registry.get('abstract'), gen)
     gen.unregister()
     self.assertRaises(GeneratorError, registry.get, 'abstract')
Beispiel #3
0
 def test_reset(self):
     registry = Registry()
     expected = DEFAULT_GENERATOR_NAMES
     registry.register('abstract', AbstractKeyGenerator)
     now_expected = DEFAULT_GENERATOR_NAMES + ['abstract']
     self.assertEqual(set(registry.available()), set(now_expected))
     registry.reset()
     self.assertEqual(set(registry.available()), set(expected))
 def test_reset(self):
     registry = Registry()
     expected = DEFAULT_GENERATOR_NAMES
     registry.register('abstract', AbstractKeyGenerator)
     now_expected = DEFAULT_GENERATOR_NAMES + ['abstract']
     self.assertEqual(set(registry.available()), set(now_expected))
     registry.reset()
     self.assertEqual(set(registry.available()), set(expected))
 def test_register(self):
     registry = Registry()
     registry.register('abstract', AbstractKeyGenerator)
     self.assertEqual(registry.get('abstract'), AbstractKeyGenerator)
 def test_get(self):
     registry = Registry()
     sms = registry.get('sms')
     self.assertEqual(sms, SMSKeyGenerator)
 def test_available(self):
     registry = Registry()
     available = registry.available()
     expected = DEFAULT_GENERATOR_NAMES
     self.assertEqual(set(available), set(expected))
 def setUp(self):
     registry = Registry()
     registry.reset()
Beispiel #9
0
        return reverse_lazy('meetup-activate',
                            kwargs={'group': self.keygroup.name})

    def generate_keys(self):
        Key = get_model('verification', 'Key')
        Generator = self.keygroup.get_generator()
        used_keys = set(
            Key.objects.filter(group__generator=Generator.name).values_list(
                'key', flat=True))
        generator = Generator()
        all_keys = set(generator.generate_all_keys())
        keys = sample(all_keys - used_keys, self.estimated_number_of_attendees)
        expires = datetime.combine(self.valid_until, datetime.max.time())
        for keystring in keys:
            key = Key.objects.create(
                key=keystring,
                group=self.keygroup,
                expires=expires.replace(tzinfo=pytz.utc),
            )

    def set_actual_number_of_attendees(self):
        self.actual_number_of_attendees = self.badge.receivers.count()
        self.save()


registry = Registry()
registry.register('cals', CALSGenerator)
registry.register('hexcolor', HexColorGenerator)
registry.register('isodate', IsoDateGenerator)
registry.register('zeropaddedpin', ZeroPaddedNumberGenerator)
 def tearDown(self):
     registry = Registry()
     registry.unregister('abstract')
Beispiel #11
0
 def test_unregister(self):
     registry = Registry()
     registry.register('abstract', AbstractKeyGenerator)
     registry.unregister('abstract')
     self.assertRaises(GeneratorError, registry.get, 'abstract')
     self.assertFalse(registry.get('abstract', False))
Beispiel #12
0
 def test_register(self):
     registry = Registry()
     registry.register('abstract', AbstractKeyGenerator)
     self.assertEqual(registry.get('abstract'), AbstractKeyGenerator)
Beispiel #13
0
 def test_get(self):
     registry = Registry()
     sms = registry.get('sms')
     self.assertEqual(sms, SMSKeyGenerator)
Beispiel #14
0
 def test_available(self):
     registry = Registry()
     available = registry.available()
     expected = DEFAULT_GENERATOR_NAMES
     self.assertEqual(set(available), set(expected))
Beispiel #15
0
 def setUp(self):
     registry = Registry()
     registry.reset()
 def test_unregister(self):
     registry = Registry()
     registry.register('abstract', AbstractKeyGenerator)
     registry.unregister('abstract')
     self.assertRaises(GeneratorError, registry.get, 'abstract')
     self.assertFalse(registry.get('abstract', False))
Beispiel #17
0
 def tearDown(self):
     registry = Registry()
     registry.unregister('abstract')
Beispiel #18
0
 def test_register(self):
     gen = AbstractKeyGenerator()
     gen.register()
     registry = Registry()
     self.assertEqual(registry.get('abstract'), gen)
 def test_register(self):
     gen = AbstractKeyGenerator()
     gen.register()
     registry = Registry()
     self.assertEqual(registry.get('abstract'), gen)
Beispiel #20
0
    badge = models.ForeignKey("badge.Badge")
    valid_from = models.DateField(blank=True, null=True)
    valid_until = models.DateField(blank=True, null=True)
    estimated_number_of_attendees = models.IntegerField(default=0, blank=True, null=True)
    actual_number_of_attendees = models.IntegerField(default=0, blank=True, null=True)

    def get_absolute_url(self):
        return reverse_lazy("meetup-activate", kwargs={"group": self.keygroup.name})

    def generate_keys(self):
        Key = get_model("verification", "Key")
        Generator = self.keygroup.get_generator()
        used_keys = set(Key.objects.filter(group__generator=Generator.name).values_list("key", flat=True))
        generator = Generator()
        all_keys = set(generator.generate_all_keys())
        keys = sample(all_keys - used_keys, self.estimated_number_of_attendees)
        expires = datetime.combine(self.valid_until, datetime.max.time())
        for keystring in keys:
            key = Key.objects.create(key=keystring, group=self.keygroup, expires=expires.replace(tzinfo=pytz.utc))

    def set_actual_number_of_attendees(self):
        self.actual_number_of_attendees = self.badge.receivers.count()
        self.save()


registry = Registry()
registry.register("cals", CALSGenerator)
registry.register("hexcolor", HexColorGenerator)
registry.register("isodate", IsoDateGenerator)
registry.register("zeropaddedpin", ZeroPaddedNumberGenerator)