from interface.tests import AccessTestCase from django.contrib.auth.models import User from interface.models import Ensemble, Project from . import models class IntegrationTestCase(AccessTestCase): USERS = ( {'username': 'admin', 'password': 'secret', 'is_superuser': True, 'is_staff': True}, {'username': 'homer', 'password': 'maggie'}, ) ENSEMBLES = ( {'name': 'The Be Sharps', 'slug': 'be-sharps', 'admins': ['homer']}, {'name': 'Lisa & the Bleeding Gums', 'slug': 'bleeding-gums'}, {'name': 'Party Posse'}, ) PROJECTS = ( ('Baker St', 'bleeding-gums', -12), ('Navy Recruitment Day', 'party-posse', 6), ('Barbershop Contest', 'be-sharps', 28), ('Open Mic Night', 'bleeding-gums', 1) ) COLLECTIONS = ( {'name': 'Springfield Elementary Library', 'prefix': 'sel'}, {'name': 'Neds Library', 'prefix': 'ned', 'admins': ['homer']}, ) WORKS = ( {'name': 'Baby on Board', 'collection': 'ned'}, ) @classmethod def setUpTestData(cls): super().setUpTestData() cls.collections = {} for details in cls.COLLECTIONS: admins = details.pop('admins', []) obj = models.Collection.objects.create(**details) for admin in admins: obj.administrators.add(cls.users[admin]) cls.collections[details['prefix']] = obj cls.works = {} for details in cls.WORKS: collection = details.pop('collection') cls.works[details['name']] = models.Work.objects.create(collection=cls.collections[collection], **details) def oldSetUp(self): self.homer = User.objects.create(username='homer') self.ned = User.objects.create(username="ned") self.lisa = User.objects.create(username="lisa") self.dewey = User.objects.create(username="dewey") self.be_sharps = self.homer.ensembles.create(name='Be Sharps', code="barbershop") self.sesd = self.dewey.ensembles.create(name="Springfield Elementary School Band", code="sax") self.sel = self.lisa.collections.create(name="Springfield Elementary Library") self.flanders = self.ned.collections.create(name="Neds Shed") def test_integration(self): pass def test_superuser_access(self): self.login('admin', 'secret') self.assertAccess({ '/collections': True, '/collections/1': True, '/collections/2/works/1': True, }) def test_administrator_access(self): self.login('homer', 'maggie') self.assertAccess({ '/collections': True, '/collections/1': False, '/collections/2': True, '/collections/2/works/1': True, }) def test_link_access(self): self.assertAccess({ '/collections': True, '/collections/1': False, '/collections/2': False, '/collections/2/works/1': False, }) self.authorize(models.Collection, pk=2) self.assertAccess({ '/collections': True, '/collections/1': False, '/collections/2': True, '/collections/2/works/1': True, }) def test_anon_access(self): self.assertAccess({ '/collections': True, '/collections/1': False, '/collections/2': False, '/collections/2/works/1': False, }) def test_movement_from_large_work(self): ''' Will be common to store a work which has several movements, but the project is only going to play one. This also should give us the ability to store an anthology as one Work have Project reference 'no:23' ''' work = self.collections['sel'].works.create(name="Some Quartet", composer="Beethoven") for g in ('vl-1', 'vl-2', 'vla', 'vc'): doc = work.docs.create(upload=f'sel/beethoven/some_quartet/some_quartet_{g}.pdf') doc.sections.create(tag='mvmt-1', start=1, end=3) doc.sections.create(tag='mvmt-2', start=4, end=8) doc.sections.create(tag='mvmt-3', start=9, end=12) doc.sections.create(tag=g) # no tags - get nothing (should it be everything?) self.assertEqual(work.extract(), []) # single tag - should get just that range self.assertEqual(work.extract('vl-1'), [('sel/beethoven/some_quartet/some_quartet_vl-1.pdf', None, None)]) # single tag - returns all documents with that range result = work.extract('mvmt-2') self.assertEqual(len(result), 4) # multiple tags - returns the overlapping portion of all documents that have all tags self.assertEqual(work.extract('vl-1', 'mvmt-2'), [('sel/beethoven/some_quartet/some_quartet_vl-1.pdf', 4, 8)]) self.assertEqual(work.extract('vl-1', 'vl-2'), [])