예제 #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
예제 #9
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
예제 #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")