コード例 #1
0
 def test_encode_known_pids(self):
     # check codec logic against a sample of real production noids
     noids = ['2dbx', '5z8x', '13kpr', '17gvd', '17ktk']
     for noid in noids:
         i = decode_noid(noid)
         encoded = encode_noid(i)
         self.assertEqual(noid, encoded)
コード例 #2
0
ファイル: tests.py プロジェクト: emory-libraries/pidman
 def test_encode_known_pids(self):
     # check codec logic against a sample of real production noids
     noids = ['2dbx', '5z8x', '13kpr', '17gvd', '17ktk']
     for noid in noids:
         i = decode_noid(noid)
         encoded = encode_noid(i)
         self.assertEqual(noid, encoded)
コード例 #3
0
def pid_sequence_lastvalue(apps, schema_editor):
    # if the database has existing pids, update the sequence last value
    # so it will start minting pids starting after the current set
    Pid = apps.get_model("pid", "Pid")
    Sequence = apps.get_model("sequences", "Sequence")

    if Pid.objects.count():
        # pid noids are generated in sequence, so the pid with the
        # highest pk _should_ be the one with the highest noid
        max_noid = Pid.objects.all().order_by('pk').last().pid
        # (previously using aggregate max, but doesn't seem to find
        # the highest pid value correctly)
        last_val = decode_noid(max_noid)
        try:
            # try to find the pid sequence by name, in case it already exists
            pid_seq = Sequence.objects.get(name=pid_models.Pid.SEQUENCE_NAME)
            pid_seq.last = last_val
        except Sequence.DoesNotExist:
            # if sequence does not exist, create a new one
            pid_seq = Sequence.objects.create(name=pid_models.Pid.SEQUENCE_NAME,
                                              last=last_val)
        pid_seq.save()
コード例 #4
0
def pid_sequence_lastvalue(apps, schema_editor):
    # if the database has existing pids, update the sequence last value
    # so it will start minting pids starting after the current set
    Pid = apps.get_model("pid", "Pid")
    Sequence = apps.get_model("sequences", "Sequence")

    if Pid.objects.count():
        # pid noids are generated in sequence, so the pid with the
        # highest pk _should_ be the one with the highest noid
        max_noid = Pid.objects.all().order_by('pk').last().pid
        # (previously using aggregate max, but doesn't seem to find
        # the highest pid value correctly)
        last_val = decode_noid(max_noid)
        try:
            # try to find the pid sequence by name, in case it already exists
            pid_seq = Sequence.objects.get(name=pid_models.Pid.SEQUENCE_NAME)
            pid_seq.last = last_val
        except Sequence.DoesNotExist:
            # if sequence does not exist, create a new one
            pid_seq = Sequence.objects.create(
                name=pid_models.Pid.SEQUENCE_NAME, last=last_val)
        pid_seq.save()
コード例 #5
0
 def test_round_trip_to_int(self):
     for i in xrange(10000):
         pid = encode_noid(i)
         decoded = decode_noid(pid)
         self.assertEqual(i, decoded)
コード例 #6
0
ファイル: tests.py プロジェクト: emory-libraries/pidman
 def test_round_trip_to_int(self):
     for i in xrange(10000):
         pid = encode_noid(i)
         decoded = decode_noid(pid)
         self.assertEqual(i, decoded)