コード例 #1
0
 def test_deleted_from_client(self):
     """Asserts "default" instance is deleted when "client" instance
     is deleted.
     """
     test_model = TestModel.objects.using('client').create(f1='model1')
     tx_exporter = TransactionExporter(export_path=self.export_path,
                                       using='client')
     batch = tx_exporter.export_batch()
     tx_importer = TransactionImporter(import_path=self.import_path)
     batch = tx_importer.import_batch(filename=batch.filename)
     tx_deserializer = TransactionDeserializer(override_role=NODE_SERVER,
                                               allow_self=True)
     tx_deserializer.deserialize_transactions(
         transactions=batch.saved_transactions, deserialize_only=True)
     test_model.delete()
     tx_exporter = TransactionExporter(export_path=self.export_path,
                                       using='client')
     batch = tx_exporter.export_batch()
     tx_importer = TransactionImporter(import_path=self.import_path)
     batch = tx_importer.import_batch(filename=batch.filename)
     tx_deserializer = TransactionDeserializer(override_role=NODE_SERVER,
                                               allow_self=True)
     tx_deserializer.deserialize_transactions(
         transactions=batch.saved_transactions)
     try:
         TestModel.objects.get(f1='model1')
     except TestModel.DoesNotExist:
         pass
     else:
         self.fail('TestModel unexpectedly exists')
コード例 #2
0
 def test_deleted_from_client(self):
     """Asserts "default" instance is deleted when "client" instance
     is deleted.
     """
     test_model = TestModel.objects.using('client').create(f1='model1')
     tx_exporter = TransactionExporter(
         export_path=self.export_path, using='client')
     batch = tx_exporter.export_batch()
     tx_importer = TransactionImporter(import_path=self.import_path)
     batch = tx_importer.import_batch(filename=batch.filename)
     tx_deserializer = TransactionDeserializer(
         override_role=NODE_SERVER, allow_self=True)
     tx_deserializer.deserialize_transactions(
         transactions=batch.saved_transactions, deserialize_only=True)
     test_model.delete()
     tx_exporter = TransactionExporter(
         export_path=self.export_path, using='client')
     batch = tx_exporter.export_batch()
     tx_importer = TransactionImporter(import_path=self.import_path)
     batch = tx_importer.import_batch(filename=batch.filename)
     tx_deserializer = TransactionDeserializer(
         override_role=NODE_SERVER, allow_self=True)
     tx_deserializer.deserialize_transactions(
         transactions=batch.saved_transactions)
     try:
         TestModel.objects.get(f1='model1')
     except TestModel.DoesNotExist:
         pass
     else:
         self.fail('TestModel unexpectedly exists')
コード例 #3
0
 def test_allow_saved_on_any_device(self):
     """Asserts can save on self by default.
     """
     TestModel.objects.create(f1='model1')
     tx_exporter = TransactionExporter(export_path=self.export_path)
     batch = tx_exporter.export_batch()
     tx_importer = TransactionImporter(import_path=self.import_path)
     tx_importer.import_batch(filename=batch.filename)
     self.assertRaises(TransactionDeserializerError,
                       TransactionDeserializer, allow_self=True)
コード例 #4
0
 def test_dont_allow_saved_on_self(self):
     """Asserts cannot save on self by default.
     """
     TestModel.objects.create(f1='model1')
     tx_exporter = TransactionExporter(export_path=self.export_path)
     batch = tx_exporter.export_batch()
     tx_importer = TransactionImporter(import_path=self.import_path)
     tx_importer.import_batch(filename=batch.filename)
     self.assertRaises(TransactionDeserializerError,
                       TransactionDeserializer)
コード例 #5
0
    def setUp(self):
        site_sync_models.registry = {}
        site_sync_models.loaded = False
        sync_models = [
            'edc_sync.testmodel',
            'edc_sync.testmodelwithfkprotected',
            'edc_sync.testmodelwithm2m',
            'edc_sync.testmodelhook',
        ]
        site_sync_models.register(sync_models)

        self.export_path = os.path.join(tempfile.gettempdir(), 'export')
        if not os.path.exists(self.export_path):
            os.mkdir(self.export_path)
        self.import_path = self.export_path
        IncomingTransaction.objects.all().delete()
        OutgoingTransaction.objects.using('client').all().delete()
        TestModel.objects.all().delete()
        TestModel.objects.using('client').all().delete()
        TestModel.history.all().delete()
        TestModel.history.using('client').all().delete()
        TestModel.objects.using('client').create(f1='model1')
        TestModel.objects.using('client').create(f1='model2')

        tx_exporter = TransactionExporter(export_path=self.export_path,
                                          using='client')
        batch = tx_exporter.export_batch()
        tx_importer = TransactionImporter(import_path=self.import_path)
        self.batch = tx_importer.import_batch(filename=batch.filename)
コード例 #6
0
    def setUp(self):
        site_sync_models.registry = {}
        site_sync_models.loaded = False
        sync_models = ['edc_sync.testmodeldates']
        site_sync_models.register(sync_models, wrapper_cls=SyncModel)

        self.export_path = os.path.join(tempfile.gettempdir(), 'export')
        if not os.path.exists(self.export_path):
            os.mkdir(self.export_path)
        self.import_path = self.export_path
        IncomingTransaction.objects.all().delete()
        OutgoingTransaction.objects.using('client').all().delete()
        TestModelDates.objects.all().delete()
        TestModelDates.objects.using('client').all().delete()
        self.date = get_utcnow()
        TestModelDates.objects.using('client').create(f2=self.date.date())

        tx_exporter = TransactionExporter(
            export_path=self.export_path,
            using='client')
        batch = tx_exporter.export_batch()
        tx_importer = TransactionImporter(import_path=self.import_path)
        self.batch = tx_importer.import_batch(filename=batch.filename)

        datetime_format = '%Y-%m-%dT%H:%M:%S.%fZ'
        self.obj = IncomingTransaction.objects.all()[0]
        bad_date = self.date.strftime(datetime_format)
        json_text = self.obj.aes_decrypt(self.obj.tx)
        json_obj = json.loads(json_text)
        json_obj[0]['fields']['f2'] = bad_date
        json_text = json.dumps(json_obj)
        self.obj.tx = self.obj.aes_encrypt(json_text)
        self.obj.save()
        self.obj = IncomingTransaction.objects.get(id=self.obj.id)
        self.app_config = copy(django_apps.get_app_config('edc_sync'))
コード例 #7
0
    def setUp(self):
        site_sync_models.registry = {}
        site_sync_models.loaded = False
        sync_models = ['edc_sync.testmodeldates']
        site_sync_models.register(sync_models, wrapper_cls=SyncModel)

        self.export_path = os.path.join(tempfile.gettempdir(), 'export')
        if not os.path.exists(self.export_path):
            os.mkdir(self.export_path)
        self.import_path = self.export_path
        IncomingTransaction.objects.all().delete()
        OutgoingTransaction.objects.using('client').all().delete()
        TestModelDates.objects.all().delete()
        TestModelDates.objects.using('client').all().delete()
        self.date = get_utcnow()
        TestModelDates.objects.using('client').create(f2=self.date.date())

        tx_exporter = TransactionExporter(export_path=self.export_path,
                                          using='client')
        batch = tx_exporter.export_batch()
        tx_importer = TransactionImporter(import_path=self.import_path)
        self.batch = tx_importer.import_batch(filename=batch.filename)

        datetime_format = '%Y-%m-%dT%H:%M:%S.%fZ'
        self.obj = IncomingTransaction.objects.all()[0]
        bad_date = self.date.strftime(datetime_format)
        json_text = self.obj.aes_decrypt(self.obj.tx)
        json_obj = json.loads(json_text)
        json_obj[0]['fields']['f2'] = bad_date
        json_text = json.dumps(json_obj)
        self.obj.tx = self.obj.aes_encrypt(json_text)
        self.obj.save()
        self.obj = IncomingTransaction.objects.get(id=self.obj.id)
        self.app_config = copy(django_apps.get_app_config('edc_sync'))
コード例 #8
0
    def setUp(self):
        site_sync_models.registry = {}
        site_sync_models.loaded = False
        sync_models = [
            'edc_sync.testmodel',
            'edc_sync.testmodelwithfkprotected',
            'edc_sync.testmodelwithm2m',
            'edc_sync.testmodelhook', ]
        site_sync_models.register(sync_models)

        self.export_path = os.path.join(tempfile.gettempdir(), 'export')
        if not os.path.exists(self.export_path):
            os.mkdir(self.export_path)
        self.import_path = self.export_path
        IncomingTransaction.objects.all().delete()
        OutgoingTransaction.objects.using('client').all().delete()
        TestModel.objects.all().delete()
        TestModel.objects.using('client').all().delete()
        TestModel.history.all().delete()
        TestModel.history.using('client').all().delete()
        TestModel.objects.using('client').create(f1='model1')
        TestModel.objects.using('client').create(f1='model2')

        tx_exporter = TransactionExporter(
            export_path=self.export_path,
            using='client')
        batch = tx_exporter.export_batch()
        tx_importer = TransactionImporter(import_path=self.import_path)
        self.batch = tx_importer.import_batch(filename=batch.filename)
コード例 #9
0
 def test_saved_on_self(self):
     """Asserts can save on self if allow_self=True.
     """
     TestModel.objects.create(f1='model1')
     tx_exporter = TransactionExporter(export_path=self.export_path)
     batch = tx_exporter.export_batch()
     tx_importer = TransactionImporter(import_path=self.import_path)
     batch = tx_importer.import_batch(filename=batch.filename)
     tx_deserializer = TransactionDeserializer(
         override_role=NODE_SERVER, allow_self=True)
     tx_deserializer.deserialize_transactions(
         transactions=batch.saved_transactions)
     try:
         TestModel.objects.get(f1='model1')
     except TestModel.DoesNotExist:
         self.fail('TestModel unexpectedly does not exist')
コード例 #10
0
 def test_flagged_as_deserialized(self):
     """Asserts "default" instance is created when "client" instance
     is created.
     """
     TestModel.objects.using('client').create(f1='model1')
     tx_exporter = TransactionExporter(
         export_path=self.export_path, using='client')
     batch = tx_exporter.export_batch()
     tx_importer = TransactionImporter(import_path=self.import_path)
     batch = tx_importer.import_batch(filename=batch.filename)
     tx_deserializer = TransactionDeserializer(
         override_role=NODE_SERVER, allow_self=True)
     tx_deserializer.deserialize_transactions(
         transactions=batch.saved_transactions)
     for transaction in batch.saved_transactions:
         self.assertTrue(transaction.is_consumed)
コード例 #11
0
 def test_saved_on_self(self):
     """Asserts can save on self if allow_self=True.
     """
     TestModel.objects.create(f1='model1')
     tx_exporter = TransactionExporter(export_path=self.export_path)
     batch = tx_exporter.export_batch()
     tx_importer = TransactionImporter(import_path=self.import_path)
     batch = tx_importer.import_batch(filename=batch.filename)
     tx_deserializer = TransactionDeserializer(override_role=NODE_SERVER,
                                               allow_self=True)
     tx_deserializer.deserialize_transactions(
         transactions=batch.saved_transactions)
     try:
         TestModel.objects.get(f1='model1')
     except TestModel.DoesNotExist:
         self.fail('TestModel unexpectedly does not exist')
コード例 #12
0
 def test_flagged_as_deserialized(self):
     """Asserts "default" instance is created when "client" instance
     is created.
     """
     TestModel.objects.using('client').create(f1='model1')
     tx_exporter = TransactionExporter(export_path=self.export_path,
                                       using='client')
     batch = tx_exporter.export_batch()
     tx_importer = TransactionImporter(import_path=self.import_path)
     batch = tx_importer.import_batch(filename=batch.filename)
     tx_deserializer = TransactionDeserializer(override_role=NODE_SERVER,
                                               allow_self=True)
     tx_deserializer.deserialize_transactions(
         transactions=batch.saved_transactions)
     for transaction in batch.saved_transactions:
         self.assertTrue(transaction.is_consumed)
コード例 #13
0
 def test_deserialized_with_history(self):
     """Asserts correctly deserialized model with history.
     """
     TestModel.objects.using('client').create(f1='model1')
     tx_exporter = TransactionExporter(
         export_path=self.export_path, using='client')
     batch = tx_exporter.export_batch()
     tx_importer = TransactionImporter(import_path=self.import_path)
     batch = tx_importer.import_batch(filename=batch.filename)
     tx_deserializer = TransactionDeserializer(
         allow_self=True, override_role=NODE_SERVER)
     tx_deserializer.deserialize_transactions(
         transactions=batch.saved_transactions)
     try:
         TestModel.history.get(f1='model1')
     except TestModel.DoesNotExist:
         self.fail('TestModel history unexpectedly does not exists')
コード例 #14
0
 def test_deserialized_with_history(self):
     """Asserts correctly deserialized model with history.
     """
     TestModel.objects.using('client').create(f1='model1')
     tx_exporter = TransactionExporter(export_path=self.export_path,
                                       using='client')
     batch = tx_exporter.export_batch()
     tx_importer = TransactionImporter(import_path=self.import_path)
     batch = tx_importer.import_batch(filename=batch.filename)
     tx_deserializer = TransactionDeserializer(allow_self=True,
                                               override_role=NODE_SERVER)
     tx_deserializer.deserialize_transactions(
         transactions=batch.saved_transactions)
     try:
         TestModel.history.get(f1='model1')
     except TestModel.DoesNotExist:
         self.fail('TestModel history unexpectedly does not exists')
コード例 #15
0
 def test_deserialize_with_m2m_missing(self):
     """Asserts deserialization error if m2m instance does not
     exist on destination.
     """
     obj = TestModelWithM2m.objects.using('client').create(f1='model1')
     m2m = M2m.objects.using('client').create(name='erik')
     obj.m2m.add(m2m)
     tx_exporter = TransactionExporter(export_path=self.export_path,
                                       using='client')
     batch = tx_exporter.export_batch()
     tx_importer = TransactionImporter(import_path=self.import_path)
     batch = tx_importer.import_batch(filename=batch.filename)
     tx_deserializer = TransactionDeserializer(allow_self=True,
                                               override_role=NODE_SERVER)
     self.assertRaises(DeserializationError,
                       tx_deserializer.deserialize_transactions,
                       transactions=batch.saved_transactions)
コード例 #16
0
 def test_deserialize_with_m2m_missing(self):
     """Asserts deserialization error if m2m instance does not
     exist on destination.
     """
     obj = TestModelWithM2m.objects.using('client').create(f1='model1')
     m2m = M2m.objects.using('client').create(name='erik')
     obj.m2m.add(m2m)
     tx_exporter = TransactionExporter(
         export_path=self.export_path, using='client')
     batch = tx_exporter.export_batch()
     tx_importer = TransactionImporter(import_path=self.import_path)
     batch = tx_importer.import_batch(filename=batch.filename)
     tx_deserializer = TransactionDeserializer(
         allow_self=True, override_role=NODE_SERVER)
     self.assertRaises(
         DeserializationError,
         tx_deserializer.deserialize_transactions,
         transactions=batch.saved_transactions)
コード例 #17
0
 def test_deserialized_with_fk(self):
     """Asserts correctly deserialized model with FK.
     """
     test_model = TestModel.objects.using('client').create(f1='model1')
     TestModelWithFkProtected.objects.using('client').create(
         f1='f1', test_model=test_model)
     tx_exporter = TransactionExporter(export_path=self.export_path,
                                       using='client')
     batch = tx_exporter.export_batch()
     tx_importer = TransactionImporter(import_path=self.import_path)
     batch = tx_importer.import_batch(filename=batch.filename)
     tx_deserializer = TransactionDeserializer(allow_self=True,
                                               override_role=NODE_SERVER)
     tx_deserializer.deserialize_transactions(
         transactions=batch.saved_transactions)
     test_model = TestModel.objects.get(f1='model1')
     try:
         obj = TestModelWithFkProtected.objects.get(f1='f1')
     except TestModelWithFkProtected.DoesNotExist:
         self.fail('TestModel unexpectedly does not exists')
     self.assertEqual(test_model, obj.test_model)
コード例 #18
0
 def test_deserialized_with_fk(self):
     """Asserts correctly deserialized model with FK.
     """
     test_model = TestModel.objects.using('client').create(f1='model1')
     TestModelWithFkProtected.objects.using(
         'client').create(f1='f1', test_model=test_model)
     tx_exporter = TransactionExporter(
         export_path=self.export_path, using='client')
     batch = tx_exporter.export_batch()
     tx_importer = TransactionImporter(import_path=self.import_path)
     batch = tx_importer.import_batch(filename=batch.filename)
     tx_deserializer = TransactionDeserializer(
         allow_self=True, override_role=NODE_SERVER)
     tx_deserializer.deserialize_transactions(
         transactions=batch.saved_transactions)
     test_model = TestModel.objects.get(f1='model1')
     try:
         obj = TestModelWithFkProtected.objects.get(f1='f1')
     except TestModelWithFkProtected.DoesNotExist:
         self.fail('TestModel unexpectedly does not exists')
     self.assertEqual(test_model, obj.test_model)
コード例 #19
0
    def test_deserialize_with_m2m(self):
        """Asserts deserializes model with M2M as long as
        M2M instance exists on destination.
        """
        obj = TestModelWithM2m.objects.using('client').create(f1='model1')
        m2m = M2m.objects.using('client').create(name='erik', short_name='bob')
        obj.m2m.add(m2m)

        tx_exporter = TransactionExporter(
            export_path=self.export_path, using='client')
        batch = tx_exporter.export_batch()
        tx_importer = TransactionImporter(import_path=self.import_path)
        batch = tx_importer.import_batch(filename=batch.filename)

        M2m.objects.create(name='erik', short_name='bob')

        tx_deserializer = TransactionDeserializer(
            allow_self=True, override_role=NODE_SERVER)
        tx_deserializer.deserialize_transactions(
            transactions=batch.saved_transactions, deserialize_only=False)
        obj = TestModelWithM2m.objects.get(f1='model1')

        obj.m2m.get(short_name='bob')
コード例 #20
0
    def test_deserialize_with_m2m(self):
        """Asserts deserializes model with M2M as long as
        M2M instance exists on destination.
        """
        obj = TestModelWithM2m.objects.using('client').create(f1='model1')
        m2m = M2m.objects.using('client').create(name='erik', short_name='bob')
        obj.m2m.add(m2m)

        tx_exporter = TransactionExporter(export_path=self.export_path,
                                          using='client')
        batch = tx_exporter.export_batch()
        tx_importer = TransactionImporter(import_path=self.import_path)
        batch = tx_importer.import_batch(filename=batch.filename)

        M2m.objects.create(name='erik', short_name='bob')

        tx_deserializer = TransactionDeserializer(allow_self=True,
                                                  override_role=NODE_SERVER)
        tx_deserializer.deserialize_transactions(
            transactions=batch.saved_transactions, deserialize_only=False)
        obj = TestModelWithM2m.objects.get(f1='model1')

        obj.m2m.get(short_name='bob')