<commit_before>from django.test import TestCase
from couchexport.models import ExportSchema

class ExportSchemaTest(TestCase):

    def testSaveAndLoad(self):
        index = ["foo", 2]
        schema = ExportSchema(seq=5, index=index)
        inner = {"dict": {"bar": 1, "baz": [2,3]},
                 "list": ["foo", "bar"],
                 "dictlist": [{"bip": 1, "bop": "blah"},
                              {"bip": 2, "bop": "blah2"}],
                 "item": "yoyoyo"}
        schema.schema = inner
        schema.save()
        back = ExportSchema.get(schema.get_id)
        self.assertEqual(inner, back.schema)
        self.assertEqual(index, back.index)
<commit_msg>add test for function that gets the last schema<commit_after>from django.test import TestCase
from couchexport.models import ExportSchema
from datetime import datetime
import time

class ExportSchemaTest(TestCase):

    def testSaveAndLoad(self):
        index = ["foo", 2]
        schema = ExportSchema(seq=5, index=index)
        inner = {"dict": {"bar": 1, "baz": [2,3]},
                 "list": ["foo", "bar"],
                 "dictlist": [{"bip": 1, "bop": "blah"},
                              {"bip": 2, "bop": "blah2"}],
                 "item": "yoyoyo"}
        schema.schema = inner
        schema.save()
        back = ExportSchema.get(schema.get_id)
        self.assertEqual(inner, back.schema)
        self.assertEqual(index, back.index)

    def testGetLast(self):
        indices = ["a string", ["a", "list"]]
        for index in indices:
            self.assertEqual(None, ExportSchema.last(index))
            schema1 = ExportSchema(seq=2, index=index)
            schema1.save()
            self.assertEqual(schema1._id, ExportSchema.last(index)._id)
            schema2 = ExportSchema(seq=3, index=index)
            schema2.save()
            self.assertEqual(schema2._id, ExportSchema.last(index)._id)
            # by design, if something has a timestamp it always wins out, even
            # if something has a higher seq
            schema3 = ExportSchema(seq=1, index=index, timestamp=datetime.utcnow())
            schema3.save()
            self.assertEqual(schema3._id, ExportSchema.last(index)._id)
            time.sleep(.1)
            schema4 = ExportSchema(seq=1, index=index, timestamp=datetime.utcnow())
            schema4.save()
            self.assertEqual(schema4._id, ExportSchema.last(index)._id)
{'fraction_non_alphanumeric': 0.13542526837324526, 'fraction_numerical': 0.013625103220478944, 'mean_word_length': 2.256720430107527, 'pattern_counts': {'":': 20, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1534137', 'n_tokens_mistral': 729, 'n_tokens_neox': 695, 'n_words': 166}