Пример #1
0
    def get_composers(self):
        self.__connect()
        self.curs.execute(COMPOSERS_QUERY)
        composers = self.curs.fetchall()

        print "Deleting composer objects"
        Composer.objects.all().delete()

        print "Adding composers"
        for composer in composers:
            '''
            c = {
                'old_id': composer.get('old_id', None),
                'name': composer.get('name'),
                'birth_date': pytz.utc.localize(composer.get('birth')),
                'death_date': pytz.utc.localize(composer.get('death_date', None)),
                'created': datetime.datetime.fromtimestamp(composer.get('created')),
                'updated': datetime.datetime.fromtimestamp(composer.get('updated')),                
            }
            '''
            print(composer.get('name'))
            c = Composer(**composer)
            c.name = my_decoder(c.name)
            c.save()

        self.__disconnect()
Пример #2
0
def composer_handler(composer):
	if composer:
		for c in Composer.objects.all():
			if str(c.name) == str(composer):
				return c
		composer_instance = Composer(name=composer)
		composer_instance.save()
		return composer_instance
	return None
Пример #3
0
    def get_composers(self):
        self.__connect()
        self.curs.execute(COMPOSERS_QUERY)
        composers = self.curs.fetchall()

        print "Deleting composer objects"
        Composer.objects.all().delete()

        print "Adding composers"
        for composer in composers:
            c = Composer(**composer)
            c.save()
        self.__disconnect()
Пример #4
0
    def get_composers(self):
        self.__connect()
        self.curs.execute(COMPOSERS_QUERY)
        composers = self.curs.fetchall()

        print "Deleting composer objects"
        Composer.objects.all().delete()

        print "Adding composers"
        for composer in composers:
            c = Composer(**composer)
            c.save()
        self.__disconnect()
Пример #5
0
def create_composer(request):
	picture = choice(os.listdir(os.path.abspath('elvis/media/generics/composers')))
	if request.method == 'POST':
		form = ComposerForm(request.POST)
		if form.is_valid():
			clean_form = form.cleaned_data
			# use **qwargs for additional data? 
			composer = Composer(name=clean_form['name'], 
								birth_date=clean_form['birth_date'], 
								death_date=clean_form['death_date'])
			composer.save()
			return HttpResponseRedirect('/uploads/success/')
	else:
		form = ComposerForm( initial={'name': 'Composer name', 
        							'birth_date': 'birth date', 
        							'death_date': 'death date'} )
	return render(request, 'forms/composer.html', {'form': form, 'picture':picture})
Пример #6
0
    def setUp(self):
        self.setUp_user()

        self.c = Collection()
        self.c.title = "This is the collection title"
        self.c.save()

        self.p = Piece()
        self.p.creator = self.creator_user
        self.p.save()

        self.composer = Composer()
        self.composer.name = "Fake Composer"
        self.composer.save()

        self.m = Movement()
        self.m.creator = self.creator_user
        self.m.composer = self.composer
        self.m.save()
Пример #7
0
    def setUp(self):
        self.setUp_user()

        self.p = Piece()
        self.p.creator = self.creator_user
        self.p.save()

        self.composer = Composer()
        self.composer.name = "Fake Composer"
        self.composer.save()

        self.m = Movement()
        self.m.creator = self.creator_user
        self.m.composer = self.composer
        self.m.title = "This is the movement title"
        self.m.save()

        self.source1 = Source()
        self.source1.title = "Source 1"
        self.source1.save()

        self.source2 = Source()
        self.source2.title = "Source 2"
        self.source2.save()

        self.genre1 = Genre()
        self.genre1.title = "Genre 1"
        self.genre1.save()

        self.genre2 = Genre()
        self.genre2.title = "Genre 2"
        self.genre2.save()

        self.attachment1 = Attachment()
        self.attachment1.description = "Attachment 1"
        self.attachment1.save()

        self.attachment2 = Attachment()
        self.attachment2.description = "Attachment 2"
        self.attachment2.save()
Пример #8
0
class CollectionTestCase(ElvisTestSetup, APITestCase):

    def setUp(self):
        self.setUp_user()

        self.c = Collection()
        self.c.title = "This is the collection title"
        self.c.save()

        self.p = Piece()
        self.p.creator = self.creator_user
        self.p.save()

        self.composer = Composer()
        self.composer.name = "Fake Composer"
        self.composer.save()

        self.m = Movement()
        self.m.creator = self.creator_user
        self.m.composer = self.composer
        self.m.save()

    def tearDown(self):
        self.c.delete()
        self.p.delete()
        self.m.delete()
        self.composer.delete()

    def test_unicode(self):
        self.assertEqual(str(self.c), "This is the collection title")

    def test_add_piece(self):
        self.assertTrue(self.p not in self.c)
        self.assertEqual(self.c.piece_count, 0)
        self.c.add(self.p)
        self.assertEqual(self.c.piece_count, 1)
        self.assertEqual(self.p, self.c.pieces.first())
        self.assertTrue(self.p in self.c)

    def test_add_movement(self):
        self.assertTrue(self.m not in self.c)
        self.assertEqual(self.c.movement_count, 0)
        self.c.add(self.m)
        self.assertEqual(self.c.movement_count, 1)
        self.assertEqual(self.m, self.c.movements.first())
        self.assertTrue(self.m in self.c)

    def test_remove_piece(self):
        self.assertTrue(self.p not in self.c)
        self.c.add(self.p)
        self.assertTrue(self.p in self.c)
        self.c.remove(self.p)
        self.assertTrue(self.p not in self.c)

    def test_remove_movement(self):
        self.assertTrue(self.m not in self.c)
        self.c.add(self.m)
        self.assertTrue(self.m in self.c)
        self.c.remove(self.m)
        self.assertTrue(self.m not in self.c)

    def test_get_free_movements(self):
        # First test with a free movement
        self.assertListEqual(list(self.c.free_movements), [])
        self.assertEqual(self.c.free_movements_count, 0)
        self.c.add(self.m)
        self.assertListEqual(list(self.c.free_movements), [self.m])
        self.assertEqual(self.c.free_movements_count, 1)
        # Then, make self.m unfree and see that it responds
        self.m.piece = self.p
        self.p.movements.add(self.m)
        self.assertListEqual(list(self.c.free_movements), [])
        self.assertEqual(self.c.free_movements_count, 0)

    def test_container_contains_none(self):
        """
        Test that checking "None in collection" does not crash the program.
        Instead, it returns false.

        :return:
        """
        self.assertFalse(None in self.c)

    def test_invalid_contains_parameter(self):
        """
        Test that calling the __contains__ interface on Collection with an
        unacceptable parameter throws an exception.

        :return:
        """
        with self.assertRaises(Exception):
            5 in self.c
        with self.assertRaises(Exception):
            "bad" in self.c

    def test_maintain_valid_collection(self):
        """
        Test that a collection does not enter an invalid state when adding a
        movement or piece such that the movement is in the piece.

        An invalid state is when a collection contains both the movement and the
        piece even though the movement is contained within the piece.

        :return:
        """
        # M is a movement in P
        self.m.piece = self.p
        self.p.movements.add(self.m)
        # Neither M or P is in C
        self.assertTrue(self.m not in self.c)
        self.assertTrue(self.p not in self.c)
        # Only M is in C
        self.c.add(self.m)
        self.assertTrue(self.m in self.c)
        self.assertTrue(self.p not in self.c)
        # Add P to C, thereby removing just M
        self.c.add(self.p)
        self.assertTrue(self.m not in self.c)
        self.assertTrue(self.p in self.c)
        # Try to add just M.  M remains not in C and P remains in C
        self.c.add(self.m)
        self.assertTrue(self.m not in self.c)
        self.assertTrue(self.p in self.c)
Пример #9
0
class MovementTestCase(ElvisTestSetup, APITestCase):

    def setUp(self):
        self.setUp_user()

        self.p = Piece()
        self.p.creator = self.creator_user
        self.p.save()

        self.composer = Composer()
        self.composer.name = "Fake Composer"
        self.composer.save()

        self.m = Movement()
        self.m.creator = self.creator_user
        self.m.composer = self.composer
        self.m.title = "This is the movement title"
        self.m.save()

        self.source1 = Source()
        self.source1.title = "Source 1"
        self.source1.save()

        self.source2 = Source()
        self.source2.title = "Source 2"
        self.source2.save()

        self.genre1 = Genre()
        self.genre1.title = "Genre 1"
        self.genre1.save()

        self.genre2 = Genre()
        self.genre2.title = "Genre 2"
        self.genre2.save()

        self.attachment1 = Attachment()
        self.attachment1.description = "Attachment 1"
        self.attachment1.save()

        self.attachment2 = Attachment()
        self.attachment2.description = "Attachment 2"
        self.attachment2.save()

    def tearDown(self):
        self.p.delete()
        self.m.delete()
        self.composer.delete()
        self.source1.delete()
        self.source2.delete()
        self.genre1.delete()
        self.genre2.delete()
        self.attachment1.delete()

    def test_unicode(self):
        self.assertEqual(str(self.m), "This is the movement title")

    def test_get_parent_cart_id(self):
        # No piece
        self.assertEqual(self.m.get_parent_cart_id, "")
        # Add the piece
        self.m.piece = self.p
        # Assert that it matches the regex
        self.assertRegexpMatches(self.m.get_parent_cart_id, self.uuid_regexp)
        # Remove it
        self.m.piece = None
        self.assertEqual(self.m.get_parent_cart_id, "")