示例#1
0
 def test_requires_field_names(self):
     with pytest.raises(ValueError) as excinfo:
         index_name(Author)
     assert (
         "At least one field name required" in
         str(excinfo.value)
     )
示例#2
0
 def test_requires_field_names(self):
     with pytest.raises(ValueError) as excinfo:
         index_name(Author)
     assert (
         "At least one field name required" in
         six.text_type(excinfo.value)
     )
示例#3
0
 def test_invalid_kwarg(self):
     with pytest.raises(ValueError) as excinfo:
         index_name(Author, 'name', nonexistent_kwarg=True)
     assert (
         "The only supported keyword argument is 'using'" in
         six.text_type(excinfo.value)
     )
示例#4
0
 def test_invalid_kwarg(self):
     with pytest.raises(ValueError) as excinfo:
         index_name(Author, 'name', nonexistent_kwarg=True)
     assert (
         "The only supported keyword argument is 'using'" in
         str(excinfo.value)
     )
示例#5
0
 def test_requires_real_field_names(self):
     with pytest.raises(ValueError) as excinfo:
         index_name(Author, 'nonexistent')
     assert (
         "Fields do not exist: nonexistent" in
         six.text_type(excinfo.value)
     )
示例#6
0
 def test_requires_real_field_names(self):
     with pytest.raises(ValueError) as excinfo:
         index_name(Author, 'nonexistent')
     assert (
         "Fields do not exist: nonexistent" in
         str(excinfo.value)
     )
示例#7
0
 def test_ignore_index_multiple(self):
     name_idx = index_name(AuthorMultiIndex, "name")
     name_country_idx = index_name(AuthorMultiIndex, "name", "country")
     with CaptureLastQuery() as cap:
         list(
             AuthorMultiIndex.objects.filter(name__gt="").ignore_index(
                 name_idx, name_country_idx))
     assert ("IGNORE INDEX (`" + name_idx + "`,`" + name_country_idx +
             "`)") in cap.query
     used = used_indexes(cap.query)
     assert name_idx not in used
     assert name_country_idx not in used
示例#8
0
 def test_ignore_index_multiple(self):
     name_idx = index_name(AuthorMultiIndex, 'name')
     name_country_idx = index_name(AuthorMultiIndex, 'name', 'country')
     with CaptureLastQuery() as cap:
         list(
             AuthorMultiIndex.objects.filter(name__gt='').ignore_index(
                 name_idx, name_country_idx))
     assert ('IGNORE INDEX (`' + name_idx + '`,`' + name_country_idx + '`)'
             in cap.query)
     used = used_indexes(cap.query)
     assert name_idx not in used
     assert name_country_idx not in used
 def test_ignore_index_multiple(self):
     name_idx = index_name(AuthorMultiIndex, 'name')
     name_country_idx = index_name(AuthorMultiIndex, 'name', 'country')
     with CaptureLastQuery() as cap:
         list(AuthorMultiIndex.objects
                              .filter(name__gt='')
                              .ignore_index(name_idx, name_country_idx))
     assert (
         'IGNORE INDEX (`' + name_idx + '`,`' + name_country_idx + '`)'
         in cap.query
     )
     used = used_indexes(cap.query)
     assert name_idx not in used
     assert name_country_idx not in used
示例#10
0
 def setUp(self):
     super(HandlerMultipartIndexTests, self).setUp()
     self.smith1 = AuthorMultiIndex.objects.create(name="John Smith",
                                                   country="Scotland")
     self.smith2 = AuthorMultiIndex.objects.create(name="John Smith",
                                                   country="England")
     self.index_name = index_name(AuthorMultiIndex, "name", "country")
示例#11
0
 def test_force_index(self):
     name_idx = index_name(Author, 'name')
     with CaptureLastQuery() as cap:
         list(Author.objects.filter(name__gt='')
                            .force_index(name_idx))
     assert ('FORCE INDEX (`' + name_idx + '`)') in cap.query
     assert name_idx in used_indexes(cap.query)
示例#12
0
 def test_use_index(self):
     name_idx = index_name(Author, 'name')
     with CaptureLastQuery() as cap:
         list(Author.objects.filter(name__gt='').use_index(name_idx))
     assert ('USE INDEX (`' + name_idx + '`)') in cap.query
     used = used_indexes(cap.query)
     assert len(used) == 0 or name_idx in used
示例#13
0
 def test_use_index(self):
     name_idx = index_name(Author, "name")
     with CaptureLastQuery() as cap:
         list(Author.objects.filter(name__gt="").use_index(name_idx))
     assert ("USE INDEX (`" + name_idx + "`)") in cap.query
     used = used_indexes(cap.query)
     assert len(used) == 0 or name_idx in used
示例#14
0
    def test_index_hint_force_order_by(self):
        name_idx = index_name(Author, "name")
        with CaptureLastQuery() as cap:
            list(Author.objects.force_index(name_idx, for_="ORDER BY").order_by("name"))

        assert ("FORCE INDEX FOR ORDER BY (`" + name_idx + "`)") in cap.query
        assert name_idx in used_indexes(cap.query)
示例#15
0
 def setUp(self):
     super(HandlerMultipartIndexTests, self).setUp()
     self.smith1 = AuthorMultiIndex.objects.create(name='John Smith',
                                                   country='Scotland')
     self.smith2 = AuthorMultiIndex.objects.create(name='John Smith',
                                                   country='England')
     self.index_name = index_name(AuthorMultiIndex, 'name', 'country')
示例#16
0
 def test_force_index(self):
     name_idx = index_name(Author, 'name')
     with CaptureLastQuery() as cap:
         list(Author.objects.filter(name__gt='')
                            .force_index(name_idx))
     assert ('FORCE INDEX (`' + name_idx + '`)') in cap.query
     assert name_idx in used_indexes(cap.query)
示例#17
0
 def test_use_index(self):
     name_idx = index_name(Author, 'name')
     with CaptureLastQuery() as cap:
         list(Author.objects.filter(name__gt='')
                            .use_index(name_idx))
     assert ('USE INDEX (`' + name_idx + '`)') in cap.query
     used = used_indexes(cap.query)
     assert len(used) == 0 or name_idx in used
示例#18
0
    def test_index_hint_force_order_by(self):
        name_idx = index_name(Author, 'name')
        with CaptureLastQuery() as cap:
            list(Author.objects.force_index(name_idx, for_='ORDER BY')
                               .order_by('name'))

        assert ('FORCE INDEX FOR ORDER BY (`' + name_idx + "`)") in cap.query
        assert name_idx in used_indexes(cap.query)
示例#19
0
 def test_force_index_inner_query(self):
     title_idx = index_name(Book, "title")
     with CaptureLastQuery() as cap:
         list(
             Author.objects.annotate(
                 has_books=Exists(
                     Book.objects.filter(
                         author_id=OuterRef("id"), title__gt=""
                     ).force_index(title_idx, table_name="testapp_book")
                 )
             ).filter(has_books=True)
         )
     assert ("FORCE INDEX (`" + title_idx + "`)") in cap.query
     used = used_indexes(cap.query)
     assert title_idx in used
示例#20
0
 def test_secondary_multiple_fields_non_existent(self):
     with pytest.raises(KeyError):
         index_name(AuthorMultiIndex, 'country', 'id')
示例#21
0
 def test_secondary_multiple_fields_non_existent_reversed_existent(self):
     # Checks that order is preserved
     with pytest.raises(KeyError):
         index_name(AuthorMultiIndex, 'country', 'name')
示例#22
0
 def test_secondary_multiple_fields(self):
     name = index_name(AuthorMultiIndex, 'name', 'country')
     assert name.startswith('testapp_authormultiindex')
示例#23
0
 def test_primary_key(self):
     assert index_name(Author, 'id') == 'PRIMARY'
示例#24
0
 def setUp(self):
     self.smith1 = AuthorMultiIndex.objects.create(name='John Smith',
                                                   country='Scotland')
     self.smith2 = AuthorMultiIndex.objects.create(name='John Smith',
                                                   country='England')
     self.index_name = index_name(AuthorMultiIndex, 'name', 'country')
示例#25
0
 def test_secondary_multiple_fields(self):
     name = index_name(AuthorMultiIndex, 'name', 'country')
     assert name.startswith('testapp_authormultiindex')
示例#26
0
 def test_primary_key_using_other(self):
     assert index_name(Author, "id", using="other") == "PRIMARY"
示例#27
0
 def test_secondary_single_field(self):
     name = index_name(Author, "name")
     assert name.startswith("testapp_author_")
示例#28
0
 def test_secondary_multiple_fields_non_existent(self):
     with pytest.raises(KeyError):
         index_name(AuthorMultiIndex, 'country', 'id')
示例#29
0
 def test_secondary_multiple_fields_non_existent_reversed_existent(self):
     # Checks that order is preserved
     with pytest.raises(KeyError):
         index_name(AuthorMultiIndex, 'country', 'name')
示例#30
0
 def test_secondary_single_field(self):
     name = index_name(Author, 'name')
     assert name.startswith('testapp_author_')
示例#31
0
 def test_primary_key(self):
     assert index_name(Author, "id") == "PRIMARY"
示例#32
0
 def test_index_does_not_exist(self):
     with pytest.raises(KeyError) as excinfo:
         index_name(Author, 'bio')
     assert "There is no index on (bio)" in six.text_type(excinfo.value)
示例#33
0
 def test_primary_key(self):
     assert index_name(Author, 'id') == 'PRIMARY'
示例#34
0
 def test_primary_key_using_other(self):
     assert index_name(Author, 'id', using='other') == 'PRIMARY'
示例#35
0
 def test_ignore_index(self):
     name_idx = index_name(Author, "name")
     with CaptureLastQuery() as cap:
         list(Author.objects.filter(name__gt="").ignore_index(name_idx))
     assert ("IGNORE INDEX (`" + name_idx + "`)") in cap.query
     assert name_idx not in used_indexes(cap.query)
示例#36
0
 def test_primary_key_using_other(self):
     assert index_name(Author, 'id', using='other') == 'PRIMARY'
示例#37
0
 def test_secondary_single_field(self):
     name = index_name(Author, 'name')
     assert name.startswith('testapp_author_')
示例#38
0
 def test_index_does_not_exist(self):
     with pytest.raises(KeyError) as excinfo:
         index_name(Author, 'bio')
     assert "There is no index on (bio)" in str(excinfo.value)
示例#39
0
 def setUp(self):
     self.smith1 = AuthorMultiIndex.objects.create(name='John Smith',
                                                   country='Scotland')
     self.smith2 = AuthorMultiIndex.objects.create(name='John Smith',
                                                   country='England')
     self.index_name = index_name(AuthorMultiIndex, 'name', 'country')
示例#40
0
 def test_secondary_multiple_fields(self):
     name = index_name(AuthorMultiIndex, "name", "country")
     assert name.startswith("testapp_authormultiindex")