Ejemplo n.º 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)
     )
Ejemplo n.º 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)
     )
Ejemplo n.º 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)
     )
Ejemplo n.º 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)
     )
Ejemplo n.º 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)
     )
Ejemplo n.º 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)
     )
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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")
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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')
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 20
0
 def test_secondary_multiple_fields_non_existent(self):
     with pytest.raises(KeyError):
         index_name(AuthorMultiIndex, 'country', 'id')
Ejemplo n.º 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')
Ejemplo n.º 22
0
 def test_secondary_multiple_fields(self):
     name = index_name(AuthorMultiIndex, 'name', 'country')
     assert name.startswith('testapp_authormultiindex')
Ejemplo n.º 23
0
 def test_primary_key(self):
     assert index_name(Author, 'id') == 'PRIMARY'
Ejemplo n.º 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')
Ejemplo n.º 25
0
 def test_secondary_multiple_fields(self):
     name = index_name(AuthorMultiIndex, 'name', 'country')
     assert name.startswith('testapp_authormultiindex')
Ejemplo n.º 26
0
 def test_primary_key_using_other(self):
     assert index_name(Author, "id", using="other") == "PRIMARY"
Ejemplo n.º 27
0
 def test_secondary_single_field(self):
     name = index_name(Author, "name")
     assert name.startswith("testapp_author_")
Ejemplo n.º 28
0
 def test_secondary_multiple_fields_non_existent(self):
     with pytest.raises(KeyError):
         index_name(AuthorMultiIndex, 'country', 'id')
Ejemplo n.º 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')
Ejemplo n.º 30
0
 def test_secondary_single_field(self):
     name = index_name(Author, 'name')
     assert name.startswith('testapp_author_')
Ejemplo n.º 31
0
 def test_primary_key(self):
     assert index_name(Author, "id") == "PRIMARY"
Ejemplo n.º 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)
Ejemplo n.º 33
0
 def test_primary_key(self):
     assert index_name(Author, 'id') == 'PRIMARY'
Ejemplo n.º 34
0
 def test_primary_key_using_other(self):
     assert index_name(Author, 'id', using='other') == 'PRIMARY'
Ejemplo n.º 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)
Ejemplo n.º 36
0
 def test_primary_key_using_other(self):
     assert index_name(Author, 'id', using='other') == 'PRIMARY'
Ejemplo n.º 37
0
 def test_secondary_single_field(self):
     name = index_name(Author, 'name')
     assert name.startswith('testapp_author_')
Ejemplo n.º 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)
Ejemplo n.º 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')
Ejemplo n.º 40
0
 def test_secondary_multiple_fields(self):
     name = index_name(AuthorMultiIndex, "name", "country")
     assert name.startswith("testapp_authormultiindex")