class RepresentationSetTestCase(TestCase):
    fixtures = ["note_testdata.json"]

    def setUp(self):
        data = Note.objects.all()
        self.repr_set = RepresentationSet(NoteRepresentation, data, {"api_name": "v1", "resource_name": "notes"})

    def test_slicing(self):
        self.assertEqual(len(list(self.repr_set)), 6)
        self.assertEqual(len(list(self.repr_set[:3])), 3)
        self.assertEqual(len(list(self.repr_set[3:])), 3)
        self.assertEqual(len(list(self.repr_set[1:4])), 3)
        # unsliced set should remain the same (copied)
        self.assertEqual(len(list(self.repr_set)), 6)

    def test_slicing_len(self):
        self.assertEqual(len(self.repr_set), 6)
        self.assertEqual(len(self.repr_set[:3]), 3)
        self.assertEqual(len(self.repr_set[3:]), 3)
        self.assertEqual(len(self.repr_set[1:4]), 3)
        # unsliced set should remain the same (copied)
        self.assertEqual(len(self.repr_set), 6)

    def test_iter(self):
        seen = 0
        for repr in self.repr_set:
            seen += 1
        self.assertEqual(seen, 6)

        seen = 0
        for repr in self.repr_set[3:]:
            seen += 1
        self.assertEqual(seen, 3)

    def test_getitem(self):
        item0 = self.repr_set[0]
        self.assert_(isinstance(item0, NoteRepresentation))

        item1 = self.repr_set[1]
        self.assert_(isinstance(item1, NoteRepresentation))

        self.assertNotEqual(item0.instance.pk, item1.instance.pk)

    def test_resource_uri(self):
        self.assertEqual(self.repr_set.get_resource_uri(), "/api/v1/notes/")

        self.repr_set.api_name = None
        self.repr_set.resource_name = None
        self.assertRaises(NoReverseMatch, self.repr_set.get_resource_uri)
 def setUp(self):
     data = Note.objects.all()
     self.repr_set = RepresentationSet(NoteRepresentation, data, {"api_name": "v1", "resource_name": "notes"})