File: test_fields.py

package info (click to toggle)
mssql-django 1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 644 kB
  • sloc: python: 5,289; sh: 105; makefile: 7
file content (36 lines) | stat: -rw-r--r-- 1,324 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Copyright (c) Microsoft Corporation.
# Licensed under the BSD license.

from django.test import TestCase

from ..models import UUIDModel, Customer_name, Customer_address


class TestUUIDField(TestCase):
    def test_create(self):
        UUIDModel.objects.create()


class TestOrderBy(TestCase):
    def test_order_by(self):
        # Issue 109
        # Sample: https://github.com/jwaschkau/django-mssql-issue109
        john = Customer_name.objects.create(Customer_name='John')
        Customer_address.objects.create(Customer_address='123 Main St', Customer_name=john)
        names = Customer_name.objects.select_for_update().all()
        addresses = Customer_address.objects.filter(Customer_address='123 Main St', Customer_name__in=names)
        self.assertEqual(len(addresses), 1)

    def test_random_order_by(self):
        # https://code.djangoproject.com/ticket/33531
        Customer_name.objects.bulk_create([
            Customer_name(Customer_name='Jack'),
            Customer_name(Customer_name='Jane'),
            Customer_name(Customer_name='John'),
        ])
        names = []
        # iterate 20 times to make sure we don't get the same result
        for _ in range(20):
            names.append(list(Customer_name.objects.order_by('?')))

        self.assertNotEqual(names.count(names[0]), 20)