Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove compat module that no longer seems to be needed #207

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions sortedm2m_tests/compat.py

This file was deleted.

23 changes: 11 additions & 12 deletions sortedm2m_tests/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from sortedm2m.compat import get_field, get_rel
from sortedm2m.fields import SORT_VALUE_FIELD_NAME

from .compat import m2m_set
from .models import Book, DoItYourselfShelf, SelfReference, Shelf, Store, TaggedDoItYourselfShelf


Expand Down Expand Up @@ -80,45 +79,45 @@ def test_set_items(self):
self.assertEqual(list(shelf.books.all()), [])

books = self.books[5:2:-1]
m2m_set(shelf, "books", books)
shelf.books.set(books)
self.assertEqual(list(shelf.books.all()), books)

books.reverse()
m2m_set(shelf, "books", books)
shelf.books.set(books)
self.assertEqual(list(shelf.books.all()), books)

shelf.books.add(self.books[8])
self.assertEqual(list(shelf.books.all()), books + [self.books[8]])

m2m_set(shelf, "books", [])
shelf.books.set([])
self.assertEqual(list(shelf.books.all()), [])

m2m_set(shelf, "books", [self.books[9]])
shelf.books.set([self.books[9]])
self.assertEqual(list(shelf.books.all()), [
self.books[9]])

m2m_set(shelf, "books", [])
shelf.books.set([])
self.assertEqual(list(shelf.books.all()), [])

def test_set_items_by_pk(self):
shelf = self.model.objects.create()
self.assertEqual(list(shelf.books.all()), [])

books = self.books[5:2:-1]
m2m_set(shelf, "books", [b.pk for b in books])
shelf.books.set([b.pk for b in books])
self.assertEqual(list(shelf.books.all()), books)

m2m_set(shelf, "books", [self.books[5].pk, self.books[2]])
shelf.books.set([self.books[5].pk, self.books[2]])
self.assertEqual(list(shelf.books.all()), [
self.books[5],
self.books[2]])

m2m_set(shelf, "books", [force_str(self.books[8].pk)])
shelf.books.set([force_str(self.books[8].pk)])
self.assertEqual(list(shelf.books.all()), [self.books[8]])

def test_remove_items(self):
shelf = self.model.objects.create()
m2m_set(shelf, "books", self.books[2:5])
shelf.books.set(self.books[2:5])
self.assertEqual(list(shelf.books.all()), [
self.books[2],
self.books[3],
Expand All @@ -134,7 +133,7 @@ def test_remove_items(self):

def test_remove_items_by_pk(self):
shelf = self.model.objects.create()
m2m_set(shelf, "books", self.books[2:5])
shelf.books.set(self.books[2:5])
self.assertEqual(list(shelf.books.all()), [
self.books[2],
self.books[3],
Expand Down Expand Up @@ -175,7 +174,7 @@ def test_prefetch_related_queries_num(self):
def test_prefetch_related_sorting(self):
shelf = self.model.objects.create()
books = [self.books[0], self.books[2], self.books[1]]
m2m_set(shelf, "books", books)
shelf.books.set(books)

shelf = self.model.objects.filter(pk=shelf.pk).prefetch_related('books')[0]

Expand Down