Exemple #1
0
    def test_get_last(self):
        indices = ["a string", ["a", "list"]]
        save_args = get_safe_write_kwargs()

        for index in indices:
            self.addCleanup(
                lambda idx:
                [cp.delete() for cp in ExportSchema.get_all_checkpoints(idx)],
                index)

        for index in indices:
            self.assertEqual(None, ExportSchema.last(index))
            dt = datetime.utcnow()
            schema1 = ExportSchema(index=index, timestamp=dt)
            schema1.save(**save_args)
            self.assert_docs_equal(schema1, ExportSchema.last(index))
            schema2 = ExportSchema(index=index,
                                   timestamp=dt + timedelta(seconds=1))
            schema2.save(**save_args)
            self.assert_docs_equal(schema2, ExportSchema.last(index))
            schema3 = ExportSchema(index=index,
                                   timestamp=dt - timedelta(seconds=1))
            schema3.save(**save_args)
            # still schema2 (which has a later date than schema3)
            self.assert_docs_equal(schema2, ExportSchema.last(index))
Exemple #2
0
    def test_get_all_checkpoints(self):
        index = ["mydomain", "myxmlns"]
        self.addCleanup(lambda: [cp.delete() for cp in ExportSchema.get_all_checkpoints(index)])

        schema1 = ExportSchema(index=index, timestamp=datetime.utcnow())
        schema1.save()
        schema1_prime, = list(ExportSchema.get_all_checkpoints(index))
        self.assert_docs_equal(schema1_prime, schema1)
        schema2 = ExportSchema(index=index, timestamp=datetime.utcnow())
        schema2.save()
        schema1_prime, schema2_prime = list(ExportSchema.get_all_checkpoints(index))
        self.assert_docs_equal(schema1_prime, schema1)
        self.assert_docs_equal(schema2_prime, schema2)
Exemple #3
0
 def create_new_checkpoint(self):
     checkpoint = ExportSchema(seq=str(self.current_seq),
                               schema=self.get_latest_schema(),
                               timestamp=self.timestamp,
                               index=self.schema_index)
     checkpoint.save()
     return checkpoint
Exemple #4
0
    def testGetLast(self):
        indices = ["a string", ["a", "list"]]
        save_args = get_safe_write_kwargs()

        for index in indices:
            self.assertEqual(None, ExportSchema.last(index))
            dt = datetime.utcnow()
            schema1 = ExportSchema(index=index, timestamp=dt)
            schema1.save(**save_args)
            self.assertEqual(schema1._id, ExportSchema.last(index)._id)
            schema2 = ExportSchema(index=index, timestamp=dt + timedelta(seconds=1))
            schema2.save(**save_args)
            self.assertEqual(schema2._id, ExportSchema.last(index)._id)
            schema3 = ExportSchema(index=index, timestamp=dt - timedelta(seconds=1))
            schema3.save(**save_args)
            self.assertEqual(schema2._id, ExportSchema.last(index)._id)
Exemple #5
0
 def test_wrap_datetime_min(self):
     schema_bad = ExportSchema(
         schema={},
         timestamp=datetime.min,
         index='index',
     )
     schema_good = ExportSchema.wrap(schema_bad.to_json())
     self.assertEqual(schema_good.timestamp, datetime(1970, 1, 1))
Exemple #6
0
 def test_wrap_datetime_hippy(self):
     schema1 = ExportSchema(
         schema={},
         timestamp=datetime(1970, 1, 2),
         index='index',
     )
     schema2 = ExportSchema.wrap(schema1.to_json())
     self.assertEqual(schema2.timestamp, datetime(1970, 1, 2))
Exemple #7
0
def create_basic_form_checkpoint(index):
    checkpoint = ExportSchema(
        schema=BASIC_FORM_SCHEMA,
        timestamp=datetime(1970, 1, 1),
        index=index,
    )
    checkpoint.save()
    return checkpoint
Exemple #8
0
    def testGetLast(self):
        indices = ["a string", ["a", "list"]]
        save_args = get_safe_write_kwargs()

        for index in indices:
            self.assertEqual(None, ExportSchema.last(index))
            # by design, if something has a timestamp it always wins out, even
            # if something has a higher seq

            dt = datetime.utcnow()
            schema1 = ExportSchema(seq="2", index=index, timestamp=dt)
            schema1.save(**save_args)
            self.assertEqual(schema1._id, ExportSchema.last(index)._id)
            schema2 = ExportSchema(seq="1", index=index, timestamp=dt + timedelta(seconds=1))
            schema2.save(**save_args)
            self.assertEqual(schema2._id, ExportSchema.last(index)._id)
            schema3 = ExportSchema(seq="3", index=index, timestamp=dt - timedelta(seconds=1))
            schema3.save(**save_args)
            self.assertEqual(schema2._id, ExportSchema.last(index)._id)
Exemple #9
0
 def testSaveAndLoad(self):
     index = ["foo", 2]
     schema = ExportSchema(seq="5", index=index, timestamp=datetime.now())
     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)