def test_largest_value_stored_in_db(self):
     sut = TableStrategy('tests.ShardedModelIDs')
     for i in xrange(100):
         id = sut.get_next_id()
         self.assertEqual(ShardedModelIDs.objects.latest('pk').pk, id)
         self.assertFalse(
             ShardedModelIDs.objects.filter(pk__gt=id).exists())
Exemple #2
0
 def __init__(self, *args, **kwargs):
     from django_sharding_library.id_generation_strategies import TableStrategy
     kwargs['strategy'] = TableStrategy(
         backing_model_name=kwargs['source_table_name'])
     setattr(self, 'source_table_name', kwargs['source_table_name'])
     del kwargs['source_table_name']
     return super(TableShardedIDField, self).__init__(*args, **kwargs)
 def test_returns_unique_values(self):
     sut = TableStrategy('tests.ShardedModelIDs')
     ids = [sut.get_next_id() for i in xrange(100)]
     self.assertEqual(ids, list(set(ids)))
 def test_largest_value_stored_in_db(self):
     sut = TableStrategy(ShardedModelIDs)
     for i in xrange(100):
         id = sut.get_next_id()
         self.assertEqual(ShardedModelIDs.objects.latest('pk').pk, id)
         self.assertFalse(ShardedModelIDs.objects.filter(pk__gt=id).exists())
 def test_returns_unique_values(self):
     sut = TableStrategy(ShardedModelIDs)
     ids = [sut.get_next_id() for i in xrange(100)]
     self.assertEqual(ids, list(set(ids)))