def test_insert_model(self):
     model = ModelWithUser.find_by_name('With User')
     self.assertIsNone(model)
     process_message(get_object_json())
     model = ModelWithUser.find_by_name('With User')
     self.assertIsNotNone(model)
     self.assertIsNone(model.user)
Beispiel #2
0
 def test_insert_model(self):
     model = ModelWithUser.find_by_name('With User')
     self.assertIsNone(model)
     process_message(get_object_json())
     model = ModelWithUser.find_by_name('With User')
     self.assertIsNotNone(model)
     self.assertIsNone(model.user)
 def test_insert_model(self):
     model = ModelWithUser.find_by_name('With User')
     self.assertIsNone(model)
     insert_or_update(get_object_json())
     model = ModelWithUser.find_by_name('With User')
     self.assertIsNotNone(model)
     self.assertIsNone(model.user)
 def test_delete_model(self):
     model = ModelWithUser(name='With User', uuid='c03a1839-6eb3-4565-b256-e0aea5ec8437')
     model.save()
     model = ModelWithUser.find_by_name('With User')
     self.assertIsNotNone(model)
     process_message(get_object_json(to_delete=True))
     model = ModelWithUser.find_by_name('With User')
     self.assertIsNone(model)
Beispiel #5
0
 def test_update_with_user_object_user_undefined(self):
     model_with_user = get_object(model_name='modelwithuser',
                                  name='With User Undefined',
                                  uuid='c03a1839-6eb3-4565-b256-e0aea5ec8437')
     model_with_user.save()
     model_id = model_with_user.id
     model_with_user = ModelWithUser.find_by_id(id=model_id)
     self.assertEqual(model_with_user.name, 'With User Undefined')
     self.assertIsNone(model_with_user.user)
     process_message(get_object_json(model_name='modelwithuser'))
     model_with_user = ModelWithUser.find_by_id(id=model_id)
     self.assertEqual(model_with_user.name, 'With User')
     self.assertIsNone(model_with_user.user)
 def test_update_with_user_object_user_undefined(self):
     model_with_user = get_object(model_name='modelwithuser',
                                  name='With User Undefined',
                                  uuid='c03a1839-6eb3-4565-b256-e0aea5ec8437')
     model_with_user.save()
     model_id = model_with_user.id
     model_with_user = ModelWithUser.find_by_id(id=model_id)
     self.assertEqual(model_with_user.name, 'With User Undefined')
     self.assertIsNone(model_with_user.user)
     process_message(get_object_json(model_name='modelwithuser'))
     model_with_user = ModelWithUser.find_by_id(id=model_id)
     self.assertEqual(model_with_user.name, 'With User')
     self.assertIsNone(model_with_user.user)
    def test_make_upsert_case_update(self):
        obj = ModelWithUser(user='******', name='With User')
        obj.save()

        structure_serialized = serialize(obj, to_delete=False)
        structure_serialized['fields']['name'] = "Update name"
        _make_upsert(
            structure_serialized['fields'],
            SerializableModel,
            ModelWithUser,
            instance=obj
        )

        obj.refresh_from_db()
        self.assertTrue(obj.pk)
        self.assertEqual(obj.name, "Update name")
Beispiel #8
0
    def test_make_upsert_case_insert(self):
        obj = ModelWithUser(user='******', name='With User')

        structure_serialized = serialize(obj, to_delete=False)
        pk = _make_upsert(structure_serialized['fields'], SerializableModel,
                          ModelWithUser)
        self.assertTrue(pk)
        self.assertTrue(
            ModelWithUser.objects.filter(pk=pk, user='******',
                                         name='With User').exists())
Beispiel #9
0
 def test_delete_model(self):
     model = ModelWithUser(name='With User', uuid='c03a1839-6eb3-4565-b256-e0aea5ec8437')
     model.save()
     model = ModelWithUser.find_by_name('With User')
     self.assertIsNotNone(model)
     process_message(get_object_json(to_delete=True))
     model = ModelWithUser.find_by_name('With User')
     self.assertIsNone(model)
Beispiel #10
0
    def test_make_upsert_case_update(self):
        obj = ModelWithUser(user='******', name='With User')
        obj.save()

        structure_serialized = serialize(obj, to_delete=False)
        structure_serialized['fields']['name'] = "Update name"
        _make_upsert(structure_serialized['fields'],
                     SerializableModel,
                     ModelWithUser,
                     instance=obj)

        obj.refresh_from_db()
        self.assertTrue(obj.pk)
        self.assertEqual(obj.name, "Update name")
class TestSerializeObjectOnCommit(TransactionTestCase):
    def setUp(self):
        self.model_with_user = ModelWithUser(user='******', name='With User')

    @patch("osis_common.models.serializable_model.serializable_model_post_save", side_effect=None)
    def test_save(self, mock_post_save):
        self.model_with_user.save()
        self.assertTrue(mock_post_save.called)
        mock_post_save.assert_called_once_with(self.model_with_user)

    @patch("osis_common.models.serializable_model.serializable_model_post_delete", side_effect=None)
    def test_delete(self, mock_post_delete):
        self.model_with_user.save()
        self.model_with_user.delete()
        self.assertTrue(mock_post_delete.called)
        mock_post_delete.assert_called_once_with(self.model_with_user, to_delete=True)
class TestSerializeObjectOnCommit(TransactionTestCase):
    def setUp(self):
        self.model_with_user = ModelWithUser(user='******', name='With User')

    @patch(
        "osis_common.models.serializable_model.serializable_model_post_save",
        side_effect=None)
    def test_save(self, mock_post_save):
        self.model_with_user.save()
        self.assertTrue(mock_post_save.called)
        mock_post_save.assert_called_once_with(self.model_with_user)

    @patch(
        "osis_common.models.serializable_model.serializable_model_post_delete",
        side_effect=None)
    def test_delete(self, mock_post_delete):
        self.model_with_user.save()
        self.model_with_user.delete()
        self.assertTrue(mock_post_delete.called)
        mock_post_delete.assert_called_once_with(self.model_with_user,
                                                 to_delete=True)
Beispiel #13
0
def get_object(model_name, name, uuid, user=None):
    if 'modelwithuser' == model_name:
        return ModelWithUser(name=name, uuid=uuid, user=user)
    elif 'modelwithoutuser' == model_name:
        return ModelWithoutUser(name=name, uuid=uuid)
    return None
 def setUpTestData(cls):
     cls.model_with_user = ModelWithUser(user='******', name='With User')
     cls.model_without_user = ModelWithoutUser(name='Without User')
 def setUp(self):
     self.model_with_user = ModelWithUser(user='******', name='With User')
 def setUp(self):
     self.model_with_user = ModelWithUser(user='******', name='With User')