Esempio n. 1
0
 def test_command_output_automatic_handlers(self):
     maat.register(TestModel, TestMaatHandler)
     out = StringIO()
     call_command('populate_maat_ranking', stdout=out, **{'verbosity': 1})
     self.assertIn('Handler: djangomaat.testmodel - Typology: typology1', out.getvalue())
     self.assertIn('Handler: djangomaat.testmodel - Typology: typology2', out.getvalue())
     maat.unregister(TestModel)
Esempio n. 2
0
 def test_register_monkey_patching(self):
     maat.register(TestModel, TestMaatHandler)
     self.assertTrue(hasattr(TestModel, 'maat'))
     self.assertEqual(TestModel.maat.__class__, TestMaatHandler)
     self.assertTrue(hasattr(TestModel, 'maat_ranking'))
     self.assertEqual(TestModel.maat_ranking.__class__, RGD)
     maat.unregister(TestModel)
Esempio n. 3
0
 def test_register_monkey_patching(self):
     maat.register(TestModel, TestMaatHandler)
     self.assertTrue(hasattr(TestModel, 'maat'))
     self.assertEqual(TestModel.maat.__class__, TestMaatHandler)
     self.assertTrue(hasattr(TestModel, 'maat_ranking'))
     self.assertEqual(TestModel.maat_ranking.__class__, RGD)
     maat.unregister(TestModel)
Esempio n. 4
0
 def test_command_output_given_all_handlers_ad_typologies(self):
     maat.register(TestModel, TestMaatHandler)
     out = StringIO()
     args = ['djangomaat.testmodel:typology1,typology2']
     call_command('populate_maat_ranking', stdout=out, *args, **{'verbosity': 1})
     self.assertIn('Handler: djangomaat.testmodel - Typology: typology1', out.getvalue())
     self.assertIn('Handler: djangomaat.testmodel - Typology: typology2', out.getvalue())
     maat.unregister(TestModel)
Esempio n. 5
0
 def test_flush_and_retrieve_typology_wrong(self):
     maat.register(TestModel, TestMaatHandler)
     self.assertRaises(
         TypologyNotImplemented,
         self.h.flush_ordered_objects,
         'typology3'
     )
     maat.unregister(TestModel)
Esempio n. 6
0
 def test_command_output_automatic_handlers(self):
     maat.register(TestModel, TestMaatHandler)
     out = StringIO()
     call_command('populate_maat_ranking', stdout=out, **{'verbosity': 1})
     self.assertIn('Handler: djangomaat.testmodel - Typology: typology1',
                   out.getvalue())
     self.assertIn('Handler: djangomaat.testmodel - Typology: typology2',
                   out.getvalue())
     maat.unregister(TestModel)
Esempio n. 7
0
 def test_simulated_and_logged_flush_and_retrieve(self):
     maat.register(TestModel, TestMaatHandler)
     TestModel.objects.create(name='object1')
     TestModel.objects.create(name='object2')
     TestModel.objects.create(name='object3')
     TestModel.objects.create(name='object4')
     TestModel.objects.create(name='object5')
     self.h.flush_ordered_objects(logger=MockLogger(), simulate=True)
     self.assertEqual(list(TestModel.maat.ordered_by('typology1')), [])
     TestModel.objects.all().delete()
     maat.unregister(TestModel)
Esempio n. 8
0
 def test_simulated_and_logged_flush_and_retrieve(self):
     maat.register(TestModel, TestMaatHandler)
     TestModel.objects.create(name='object1')
     TestModel.objects.create(name='object2')
     TestModel.objects.create(name='object3')
     TestModel.objects.create(name='object4')
     TestModel.objects.create(name='object5')
     self.h.flush_ordered_objects(logger=MockLogger(), simulate=True)
     self.assertEqual(list(TestModel.maat.ordered_by('typology1')), [])
     TestModel.objects.all().delete()
     maat.unregister(TestModel)
Esempio n. 9
0
 def test_command_output_given_handlers_and_typology(self):
     maat.register(TestModel, TestMaatHandler)
     out = StringIO()
     args = ['djangomaat.testmodel:typology1']
     call_command('populate_maat_ranking',
                  stdout=out,
                  *args,
                  **{'verbosity': 1})
     self.assertIn('Handler: djangomaat.testmodel - Typology: typology1',
                   out.getvalue())
     self.assertNotIn('typology2', out.getvalue())
     maat.unregister(TestModel)
Esempio n. 10
0
 def test_flush_and_retrieve_typology(self):
     maat.register(TestModel, TestMaatHandler)
     object1 = TestModel.objects.create(name='object1')
     object2 = TestModel.objects.create(name='object2')
     object3 = TestModel.objects.create(name='object3')
     object4 = TestModel.objects.create(name='object4')
     object5 = TestModel.objects.create(name='object5')
     self.h.flush_ordered_objects('typology1')
     expected = [object1, object2, object3, object4, object5]
     self.assertEqual(list(TestModel.maat.ordered_by('typology1')), expected)
     expected.reverse()
     self.assertEqual(list(TestModel.maat.ordered_by('-typology1')), expected)
     TestModel.objects.all().delete()
     maat.unregister(TestModel)
Esempio n. 11
0
   def test_flush_and_retrieve_massive(self):
       maat.register(TestModel, TestMaatHandler)
       TestModel.objects.bulk_create((TestModel(name='object{:05d}'.format(i)) for i in range(20000)), 250)
       expected = list(TestModel.objects.all())
       self.h.flush_ordered_objects()
       self.assertEqual(list(TestModel.maat.ordered_by('typology1')), expected)
       expected.reverse()
       self.assertEqual(list(TestModel.maat.ordered_by('-typology1')), expected)
       self.assertEqual(list(TestModel.maat.ordered_by('typology2')), [])
       self.assertEqual(list(TestModel.maat.ordered_by('-typology2')), [])
       # Avoid "too many sql variables"
       for i in range(0, 21000, 100):
           TestModel.objects.filter(id__lt=i).delete()
 
       maat.unregister(TestModel)
Esempio n. 12
0
 def test_flush_and_retrieve_typology(self):
     maat.register(TestModel, TestMaatHandler)
     object1 = TestModel.objects.create(name='object1')
     object2 = TestModel.objects.create(name='object2')
     object3 = TestModel.objects.create(name='object3')
     object4 = TestModel.objects.create(name='object4')
     object5 = TestModel.objects.create(name='object5')
     self.h.flush_ordered_objects('typology1')
     expected = [object1, object2, object3, object4, object5]
     self.assertEqual(list(TestModel.maat.ordered_by('typology1')),
                      expected)
     expected.reverse()
     self.assertEqual(list(TestModel.maat.ordered_by('-typology1')),
                      expected)
     TestModel.objects.all().delete()
     maat.unregister(TestModel)
Esempio n. 13
0
    def test_flush_and_retrieve_massive(self):
        maat.register(TestModel, TestMaatHandler)
        TestModel.objects.bulk_create((TestModel(name='object{:05d}'.format(i))
                                       for i in range(20000)), 250)
        expected = list(TestModel.objects.all())
        self.h.flush_ordered_objects()
        self.assertEqual(list(TestModel.maat.ordered_by('typology1')),
                         expected)
        expected.reverse()
        self.assertEqual(list(TestModel.maat.ordered_by('-typology1')),
                         expected)
        self.assertEqual(list(TestModel.maat.ordered_by('typology2')), [])
        self.assertEqual(list(TestModel.maat.ordered_by('-typology2')), [])
        # Avoid "too many sql variables"
        for i in range(0, 21000, 100):
            TestModel.objects.filter(id__lt=i).delete()

        maat.unregister(TestModel)
Esempio n. 14
0
 def test_register_handler_for_model(self):
     maat.register(TestModel, TestMaatHandler)
     self.assertEqual(
         maat.get_handler_for_model(TestModel).__class__, TestMaatHandler)
     maat.unregister(TestModel)
Esempio n. 15
0
 def test_retrieve_not_implemente_typology(self):
     maat.register(TestModel, TestMaatHandler)
     self.assertRaises(TypologyNotImplemented, TestModel.maat.ordered_by,
                       'x')
     maat.unregister(TestModel)
Esempio n. 16
0
 def test_register_handler_for_model(self):
     maat.register(TestModel, TestMaatHandler)
     self.assertEqual(maat.get_handler_for_model(TestModel).__class__, TestMaatHandler)
     maat.unregister(TestModel)
Esempio n. 17
0
 def test_flush_and_retrieve_typology_wrong(self):
     maat.register(TestModel, TestMaatHandler)
     self.assertRaises(TypologyNotImplemented, self.h.flush_ordered_objects,
                       'typology3')
     maat.unregister(TestModel)
Esempio n. 18
0
 def test_register_already_registered_model(self):
     maat.register(TestModel, TestMaatHandler)
     self.assertRaises(ModelAlreadyRegistered, maat.register, TestModel, TestMaatHandler)
     maat.unregister(TestModel)
Esempio n. 19
0
 def test_register_handlers_list(self):
     maat.register(TestModel, TestMaatHandler)
     self.assertEqual(maat.get_registered_handlers()[0].__class__, TestMaatHandler)
     maat.unregister(TestModel)
Esempio n. 20
0
 def test_retrieve_implemented_empty_typology(self):
     maat.register(TestModel, TestMaatHandler)
     self.assertEqual(list(TestModel.maat.ordered_by('typology1')), [])
     maat.unregister(TestModel)
Esempio n. 21
0
 def test_register_already_registered_model(self):
     maat.register(TestModel, TestMaatHandler)
     self.assertRaises(ModelAlreadyRegistered, maat.register, TestModel,
                       TestMaatHandler)
     maat.unregister(TestModel)
Esempio n. 22
0
 def test_retrieve_implemented_empty_typology(self):
     maat.register(TestModel, TestMaatHandler)
     self.assertEqual(list(TestModel.maat.ordered_by('typology1')), [])
     maat.unregister(TestModel)
Esempio n. 23
0
 def test_register_handlers_list(self):
     maat.register(TestModel, TestMaatHandler)
     self.assertEqual(maat.get_registered_handlers()[0].__class__,
                      TestMaatHandler)
     maat.unregister(TestModel)
Esempio n. 24
0
 def test_retrieve_not_implemente_typology(self):
     maat.register(TestModel, TestMaatHandler)
     self.assertRaises(TypologyNotImplemented, TestModel.maat.ordered_by, 'x')
     maat.unregister(TestModel)