class TestMediaForm: """Uses one of subclass of MediaForm""" @pytest.mark.parametrize("form", [(ImageForm()), (SoundtrackForm()), (VideoForm())]) @pytest.mark.parametrize("obj, change", [(None, True), (object(), False)]) def test_update_medias_skip(self, form, obj, change): list_files = [1, 2, 3] update_method = form.update_medias(obj, list_files, change, '') assert update_method == list_files @pytest.mark.parametrize( "form, media, attr", [(ImageForm(), ImageFactory.build(), "image"), (SoundtrackForm(), SoundtrackFactory.build(), "soundtrack"), (VideoForm(), VideoFactory.build(), "video")]) @pytest.mark.django_db def test_update_medias(self, form, media, attr): form.cleaned_data = {'game': GameFactory(), 'role': 'slide'} list_files = [getattr(media, attr).file] assert [] == form.update_medias(media, list_files, True, attr) assert media.__class__.objects.count() == 1 @pytest.mark.django_db @pytest.mark.parametrize( "form, attr, factory", [(ImageForm(), "image", ImageFactory.build()), (SoundtrackForm(), "soundtrack", SoundtrackFactory.build()), (VideoForm(), "video", VideoFactory.build())]) def test_save_instances(self, form, attr, factory, mock): form.cleaned_data = {'game': GameFactory(), 'role': 'slide'} list_files = [getattr(factory, attr).file] with mock.patch("media.forms.MediaForm.update_medias", return_value=list_files): form.save_instances(list_files, factory, False, attr) assert factory.__class__.objects.count() == 1
class TestAdminMedia: data = { 'image': ImageFactory.build().image.file, 'video': VideoFactory.build().video.file, 'soundtrack': SoundtrackFactory.build().soundtrack.file } def setup_method(self, method): class MockRequest: class FILES: @classmethod def getlist(cls, attr): return TestAdminMedia.data[attr] self.site = AdminSite() self.request = MockRequest @pytest.mark.parametrize("admin, form, factory, model, attr", [ (ImageAdmin, ImageForm, ImageFactory, Image, "image"), (SoundtrackAdmin, SoundtrackForm, SoundtrackFactory, Soundtrack, "soundtrack"), (VideoAdmin, VideoForm, VideoFactory, Video, "video") ]) def test_save_model(self, admin, form, factory, model, attr): with mock.patch("media.forms.MediaForm.save_instances") as m: mediaAdmin = admin(model, self.site) args = [factory.build(), form()] mediaAdmin.save_model(self.request, args[0], args[1], True) m.assert_called_once_with(TestAdminMedia.data[attr], args[0], True, attr)
def __multiple_data__(self, genre, award, *args, **kwargs): for i in range(1, kwargs['loop'] + 1): self.stdout.write("Game {}:".format(i)) developer = DeveloperFactory.create_batch(kwargs['non_loop']) self.stdout.write("\tDeveloper: {}".format("." * kwargs['non_loop'])) information = InformationFactory.create( awards=[award[i % kwargs['non_loop']]], developers=developer, genres=[genre[i % kwargs['non_loop']]]) self.stdout.write("\tInformation: .") ImageFactory.create_batch(kwargs['media'], game=information.game) self.stdout.write("\tImage: {}".format("." * kwargs['media'])) VideoFactory.create_batch(kwargs['video'], game=information.game) self.stdout.write("\tVideo: {}".format("." * kwargs['video'])) PackageFactory(game=information.game) self.stdout.write("\tPackage: .")
def game(self): platform = Platform() video_game = Video() sound_game = Soundtrack() award_game = Award() developer = Developer() information_game = Information() game = GameFactory() ImageFactory(game=game) package_game = PackageFactory.build(game=game) platform.name = 'Ubuntu' platform.extensions = EXTENSION_CHOICES[0][0] platform.icon = 'Platform/linux.png' platform.save() package_game.save() package_game.platforms.add(platform) video_game.video = 'videos/exemplo.mp4' video_game.role = ROLE_CHOICES[0][0] video_game.game_id = game.id video_game.save() sound_game.soundtrack = 'soundtrack/exemplo.mp3' sound_game.role = ROLE_CHOICES[0][0] sound_game.game_id = game.id sound_game.save() award_game.name = 'Game of the year' award_game.year = 2014 award_game.place = 'Conference game' award_game.save() developer.name = 'Developer 1' developer.login = '******' developer.github_page = 'https://github.com/PlataformaJogosUnb/' developer.save() information_game.description = 'This is a test game used to test the\ serializer of the model game.' information_game.launch_year = 2013 information_game.semester = 1 information_game.game = game information_game.save() information_game.developers.add(developer) information_game.awards.add(award_game) return game
def game(self): credit = CreditFactory() award_game = AwardFactory() game = GameFactory() InformationFactory(game=game, awards=[award_game], credits=[credit]) ImageFactory(game=game) PlatformFactory() PackageFactory(game=game) VideoFactory(game=game) SoundtrackFactory(game=game) return game
def test_image_valid_extension(self, game_created): image = ImageFactory.build(game=game_created) image.save() assert Image.objects.last() == image
def test_image_invalid_extension(self, image, errors_dict, game_created): image = ImageFactory.build(image=image, game=game_created)