Esempio n. 1
0
    def test_big_insert_update(self):
        # Expected to fail in SQLite (too many variables)
        set1 = [TestModelA(a="Test", b=i, c=1) for i in range(1000)]

        insert_many(TestModelA, set1)
        self.assertEqual(1000, TestModelA.objects.all().count())

        set2 = [TestModelA(a="Test", b=i, c=2) for i in range(500, 2000)]
        insert_or_update_many(TestModelA, set2, keys=['b'])
        self.assertEqual(2000, TestModelA.objects.all().count())
Esempio n. 2
0
    def test_duplicate_insert_update(self):
        set1 = [
            TestModelA(a="Test1", b=1, c=1),
            TestModelA(a="Test2", b=2, c=2),
            TestModelA(a="Test2", b=2, c=3),
            ]

        insert_or_update_many(TestModelA, set1, keys=['b'])
        self.assertEqual(2, TestModelA.objects.all().count())
        self.assertEqual(3, TestModelA.objects.get(a="Test2").c)
Esempio n. 3
0
    def test_duplicate_insert_update(self):
        set1 = [
            TestModelA(a="Test1", b=1, c=1),
            TestModelA(a="Test2", b=2, c=2),
            TestModelA(a="Test2", b=2, c=3),
            ]

        insert_or_update_many(TestModelA, set1, keys=['b'])
        self.assertEqual(2, TestModelA.objects.all().count())
        self.assertEqual(3, TestModelA.objects.get(a="Test2").c)
Esempio n. 4
0
    def test_big_insert_update(self):
        # Expected to fail in SQLite (too many variables)
        set1 = [TestModelA(a="Test", b=i, c=1) for i in range(1000)]

        insert_many(TestModelA, set1)
        self.assertEqual(1000, TestModelA.objects.all().count())

        set2 = [TestModelA(a="Test", b=i, c=2) for i in range(500, 2000)]
        insert_or_update_many(TestModelA, set2, keys=['b'])
        self.assertEqual(2000, TestModelA.objects.all().count())
Esempio n. 5
0
    def test_basic_insert_update(self):
        n = TestModelA(a="Test1", b=1, c=2)
        n.save()

        update_set = [
            TestModelA(a="Test1", b=5, c=5),
            TestModelA(a="Test2", b=6, c=6),
            ]

        insert_or_update_many(TestModelA, update_set, keys=['a'])
        self.assertEqual(2, TestModelA.objects.all().count())

        n = TestModelA.objects.get(a="Test1")
        self.assertEqual(n.b, 5)
        self.assertEqual(n.c, 5)

        n = TestModelA.objects.get(a="Test2")
        self.assertEqual(n.b, 6)
        self.assertEqual(n.c, 6)
Esempio n. 6
0
    def test_basic_insert_update(self):
        n = TestModelA(a="Test1", b=1, c=2)
        n.save()

        update_set = [
            TestModelA(a="Test1", b=5, c=5),
            TestModelA(a="Test2", b=6, c=6),
            ]

        insert_or_update_many(TestModelA, update_set, keys=['a'])
        self.assertEqual(2, TestModelA.objects.all().count())

        n = TestModelA.objects.get(a="Test1")
        self.assertEqual(n.b, 5)
        self.assertEqual(n.c, 5)

        n = TestModelA.objects.get(a="Test2")
        self.assertEqual(n.b, 6)
        self.assertEqual(n.c, 6)
Esempio n. 7
0
    def test_returned_results_insert_update(self):
        # Expected to fail in SQLite (too many variables)
        set1 = [TestModelA(a="Test", b=i, c=1) for i in range(1000)]
        insert_many(TestModelA, set1)

        set2 = [TestModelA(a="Test", b=i, c=2) for i in range(500, 2000)]
        inserted, updated = insert_or_update_many(TestModelA, set2, keys=['b'])
        self.assertEqual(1000, len(inserted))
        self.assertEqual(500, len(updated))
        self.assertTrue(isinstance(inserted[0], dict))
        self.assertTrue(isinstance(updated[0], dict))
Esempio n. 8
0
    def test_returned_results_insert_update(self):
        # Expected to fail in SQLite (too many variables)
        set1 = [TestModelA(a="Test", b=i, c=1) for i in range(1000)]
        insert_many(TestModelA, set1)

        set2 = [TestModelA(a="Test", b=i, c=2) for i in range(500, 2000)]
        inserted, updated = insert_or_update_many(TestModelA, set2, keys=['b'])
        self.assertEqual(1000, len(inserted))
        self.assertEqual(500, len(updated))
        self.assertTrue(isinstance(inserted[0], dict))
        self.assertTrue(isinstance(updated[0], dict))
Esempio n. 9
0
    def test_multikey_insert_update(self):
        # Expected to fail in SQLite (no tuple comparison)
        set1 = [
            TestModelA(a="Test1", b=1, c=1),
            TestModelA(a="Test2", b=2, c=2),
            ]

        insert_many(TestModelA, set1)
        self.assertEqual(2, TestModelA.objects.all().count())

        set2 = [
            TestModelA(a="Test1", b=1, c=3),
            TestModelA(a="Test2", b=3, c=4),
            TestModelA(a="Test3", b=3, c=3),
            ]

        insert_or_update_many(TestModelA, set2, keys=['a', 'b'])
        self.assertEqual(4, TestModelA.objects.all().count())
        self.assertEqual(2, TestModelA.objects.filter(a="Test2").count())

        self.assertEqual(3, TestModelA.objects.get(a="Test1", b=1).c)
        self.assertEqual(3, TestModelA.objects.get(a="Test3", b=3).c)
Esempio n. 10
0
    def test_multikey_insert_skip_update(self):
        # Expected to fail in SQLite (no tuple comparison)
        set1 = [
            TestModelA(a="Test1", b=1, c=1),
            TestModelA(a="Test2", b=2, c=2),
            ]

        insert_many(TestModelA, set1)
        self.assertEqual(2, TestModelA.objects.all().count())

        set2 = [
            TestModelA(a="Test1", b=1, c=3),
            TestModelA(a="Test2", b=3, c=4),
            TestModelA(a="Test3", b=3, c=3),
            ]

        insert_or_update_many(TestModelA, set2, keys=['a', 'b'], skip_update=True)
        self.assertEqual(4, TestModelA.objects.all().count())
        self.assertEqual(2, TestModelA.objects.filter(a="Test2").count())

        self.assertEqual(1, TestModelA.objects.get(a="Test1", b=1).c)
        self.assertEqual(3, TestModelA.objects.get(a="Test3", b=3).c)
Esempio n. 11
0
    def test_insert_update_exclude_field(self):
        # Expected to fail in SQLite (no tuple comparison)
        set1 = [
            TestModelA(a="Test1", b=1, c=1),
            TestModelA(a="Test2", b=2, c=2),
            ]

        insert_many(TestModelA, set1)
        self.assertEqual(2, TestModelA.objects.all().count())

        set2 = [
            TestModelA(a="Test1", b=1, c=3),
            TestModelA(a="Test2", b=3, c=4),
            TestModelA(a="Test3", b=3, c=3),
            ]

        insert_or_update_many(TestModelA, set2, keys=['a'],
                              exclude_fields=['c'])
        self.assertEqual(3, TestModelA.objects.all().count())

        self.assertEqual(1, TestModelA.objects.get(a="Test1", b=1).c)
        self.assertEqual(2, TestModelA.objects.get(a="Test2", b=3).c)
        self.assertEqual(3, TestModelA.objects.get(a="Test3", b=3).c)