Best Python code snippet using Kiwi_python
mixins.py
Source:mixins.py
...12from .. import models13from .. import permissions14class EditalTestData:15 @classmethod16 def setUpTestData(cls):17 super().setUpTestData()18 cls.edital = edital_abertura.make()19class CursoTestData:20 @classmethod21 def setUpTestData(cls):22 super().setUpTestData()23 DiretoresdeEnsino().sync()24 cls.curso = recipes.curso_psct.make()25class ProcessoSeletivoTestData:26 @classmethod27 def setUpTestData(cls):28 super().setUpTestData()29 cls.edicao = edicao.make()30 cls.processo_seletivo = cls.edicao.processo_seletivo31class ModalidadeAmplaConcorrenciaSetUpTestData:32 @classmethod33 def setUpTestData(cls):34 super().setUpTestData()35 cls.modalidade_ampla = models.Modalidade.objects.get(36 equivalente=ModalidadeEnum.ampla_concorrencia37 )38class CandidatoMixin(UserTestMixin):39 @classmethod40 def setUpTestData(cls):41 super().setUpTestData()42 cls.user_candidato = cls.usuario_base43 cls.candidato = recipes.candidato.make(44 nome=cls.user_candidato.get_full_name(),45 email=cls.user_candidato.email,46 user=cls.user_candidato,47 )48 permissions.CandidatosPSCT.add_user(user=cls.user_candidato)49class ProcessoInscricaoMixin(50 EditalTestData, ProcessoSeletivoTestData, ModalidadeAmplaConcorrenciaSetUpTestData51):52 fixtures = [53 "processoseletivo/fixtures/modalidade.json",54 "psct/tests/fixtures/modalidade_cota.json",55 ]56 @classmethod57 def setUpTestData(cls):58 super().setUpTestData()59 # Preparação dos dados do processo seletivo para realizar os testes de inscrição60 DiretoresdeEnsino().sync()61 cls.curso_tecnico = curso_selecao_subsequente.make()62 cls.psct_subsequente = recipes.processo_inscricao.make(63 edital=cls.edital,64 cursos=[cls.curso_tecnico],65 formacao=models.ProcessoInscricao.SUBSEQUENTE66 )67 recipes.modalidade_vaga_curso_edital.make(68 curso_edital__edital=cls.edital,69 curso_edital__curso=cls.curso_tecnico,70 modalidade=cls.modalidade_ampla71 )72 cls.modeloquestionario = recipes.modelo_questionario.make(edital=cls.edital)73class FaseAnaliseTestData:74 @classmethod75 def setUpTestData(cls):76 permissions.AvaliadorPSCT().sync()77 permissions.HomologadorPSCT().sync()78 cls.yesterday = timezone.now() - datetime.timedelta(days=1)79 with freeze_time(cls.yesterday):80 super().setUpTestData()81 cls.grupo_avaliadores = recipes.grupo_edital.make(edital=cls.edital)82 cls.grupo_avaliadores.grupo.user_set.add(base.tests.recipes.user.make())83 cls.grupo_homologadores = recipes.grupo_edital.make(edital=cls.edital)84 cls.grupo_homologadores.grupo.user_set.add(base.tests.recipes.user.make())85 cls.faseanalise_recipe = recipes.fase_analise.extend(86 edital=cls.edital,87 avaliadores=cls.grupo_avaliadores,88 )89 cls.fase_analise = cls.faseanalise_recipe.make(90 requer_homologador=True,91 homologadores=cls.grupo_homologadores,92 )93class AvaliadorPSCTTestData:94 @classmethod95 def setUpTestData(cls):96 super().setUpTestData()97 cls.usuario_avaliador = base.tests.recipes.user.make()98 permissions.AvaliadorPSCT().sync()99 permissions.AvaliadorPSCT.add_user(cls.usuario_avaliador)100class HomologadorPSCTTestData:101 @classmethod102 def setUpTestData(cls):103 super().setUpTestData()104 cls.usuario_homologador = base.tests.recipes.user.make()105 permissions.HomologadorPSCT().sync()106 permissions.HomologadorPSCT.add_user(cls.usuario_homologador)107class AdministradorPSCTTestData:108 @classmethod109 def setUpTestData(cls):110 super().setUpTestData()111 cls.usuario_administrador = base.tests.recipes.user.make()112 permissions.AdministradoresPSCT().sync()113 permissions.AdministradoresPSCT.add_user(cls.usuario_administrador)114class InscricaoPreAnaliseTestData:115 @classmethod116 def setUpTestData(cls):117 super().setUpTestData()118 permissions.AvaliadorPSCT().sync()119 cls.processo_inscricao = recipes.processo_inscricao.make(edital=cls.edital)120 cls.inscricao_original = recipes.inscricao.make(121 edital=cls.edital,122 curso=cls.curso,123 )124 cls.inscricao = recipes.inscricao_pre_analise.make(125 candidato=cls.inscricao_original.candidato,126 fase__edital=cls.edital,127 curso=cls.curso,128 modalidade=cls.inscricao_original.modalidade_cota,...
test_admin.py
Source:test_admin.py
...31 self.count = Parameter.objects.count()32 super().setUp()33class ReferenceAdminTestCase(AdminTestCase, TestCase):34 @classmethod35 def setUpTestData(cls):36 ReferenceFactory.create_batch(2)37 super().setUpTestData()38 def setUp(self):39 self.admin_url_name = "catalogue_reference"40 self.admin_instance_pk = Reference.objects.last().pk41 self.count = Reference.objects.count()42 super().setUp()43class AstroObjectClassificationAdminTestCase(AdminTestCase, TestCase):44 fixtures = [45 "fixtures/catalogue_AstroObjectClassification.json",46 ]47 def setUp(self):48 self.admin_url_name = "catalogue_astroobjectclassification"49 self.admin_instance_pk = AstroObjectClassification.objects.last().pk50 self.count = AstroObjectClassification.objects.count()51 super().setUp()52class AstroObjectAdminTestCase(AdminTestCase, TestCase):53 @classmethod54 def setUpTestData(cls):55 AstroObjectFactory.create_batch(2)56 super().setUpTestData()57 def setUp(self):58 self.admin_url_name = "catalogue_astroobject"59 self.admin_instance_pk = AstroObject.objects.last().pk60 self.count = AstroObject.objects.count()61 super().setUp()62class ProfileAdminTestCase(AdminTestCase, TestCase):63 @classmethod64 def setUpTestData(cls):65 ProfileFactory.create_batch(2)66 super().setUpTestData()67 def setUp(self):68 self.admin_url_name = "catalogue_profile"69 self.admin_instance_pk = Profile.objects.last().pk70 self.count = Profile.objects.count()71 super().setUp()72class AuxiliaryAdminTestCase(AdminTestCase, TestCase):73 @classmethod74 def setUpTestData(cls):75 AuxiliaryFactory.create_batch(2)76 super().setUpTestData()77 def setUp(self):78 self.admin_url_name = "catalogue_auxiliary"79 self.admin_instance_pk = Auxiliary.objects.last().pk80 self.count = Auxiliary.objects.count()81 super().setUp()82class ObservationAdminTestCase(AdminTestCase, TestCase):83 @classmethod84 def setUpTestData(cls):85 ObservationFactory.create_batch(2)86 super().setUpTestData()87 def setUp(self):88 self.admin_url_name = "catalogue_observation"89 self.admin_instance_pk = Observation.objects.last().pk90 self.count = Observation.objects.count()91 super().setUp()92class RankAdminTestCase(AdminTestCase, TestCase):93 @classmethod94 def setUpTestData(cls):95 RankFactory.create_batch(2)96 super().setUpTestData()97 def setUp(self):98 self.admin_url_name = "catalogue_rank"99 self.admin_instance_pk = Rank.objects.last().pk100 self.count = Rank.objects.count()...
test_models.py
Source:test_models.py
2from app.models import User, Pronunciation, Poem, Algorithm, PoemScansion34class TestUser(TestCase):5 @classmethod6 def setUpTestData(cls):7 User.objects.create(username="someone", points=0)89 def test_user(self):10 u = User.objects.filter(username="someone")11 self.assertTrue(u.exists())12 self.assertEqual(u[0].points, 0)13 self.assertFalse(u[0].promoted)14 self.assertEqual(u[0].__str__(), "someone, Promoted: False")1516class TestPronunciation(TestCase):17 @classmethod18 def setUpTestData(cls):19 Pronunciation.objects.create(word="moon", stresses="/")2021 def test_pronunciation(self):22 p = Pronunciation.objects.filter(word="moon")23 self.assertTrue(p.exists())24 self.assertEqual(p[0].stresses, "/")25 self.assertEqual(p[0].popularity, 0)26 self.assertEqual(p[0].__str__(), "moon, /, popularity: 0")2728class TestPoem(TestCase):29 @classmethod30 def setUpTestData(cls):31 poem = """THE moon is a wavering rim where one fish slips,32 The water makes a quietness of sound;33 Night is an anchoring of many ships34 Home-bound."""35 scansion = """u / u u /uu / u / u /36 u /u / u /u/ u /37 / u u /u/ u /u /38 u/ """39 Poem.objects.create(title="Home-Bound", poem=poem, scansion=scansion,40 human_scanned=True, poet="Auslander, Joseph")41 Poem.objects.create(poem="moon squirrel")4243 def test_regular_poem(self):44 p = Poem.objects.filter(poet="Auslander, Joseph")45 self.assertTrue(p.exists())46 p2 = Poem.objects.filter(poem="moon squirrel")47 self.assertTrue(p2.exists())48 self.assertEqual(p2[0].title, "")49 self.assertFalse(p2[0].human_scanned)5051class TestAlgorithm(TestCase):52 @classmethod53 def setUpTestData(cls):54 Algorithm.objects.create(name="Real Scan", about="gets up to 95% right",55 function_name="real_scan")56 Algorithm.objects.create(name="Imaginary Scan",57 about="This scan passes a scansion Turing test!",58 function_name="imaginary_scan", preferred=True)5960 def test_algorithm(self):61 a = Algorithm.objects.all().order_by("-preferred")62 self.assertTrue(a.exists())63 self.assertEqual(a[0].name, "Imaginary Scan")64 self.assertEqual(a[1].name, "Real Scan")65 self.assertFalse(a[1].preferred)6667class TestPoemScansion(TestCase):68 @classmethod69 def setUpTestData(cls):70 Algorithm.objects.create(name="Real Scan", about="gets up to 95% right",71 function_name="real_scan")72 Poem.objects.create(poem="moon squirrel")73 p = Poem.objects.get(poem="moon squirrel")74 a = Algorithm.objects.get(name="Real Scan")75 PoemScansion.objects.create(poem=p, scansion="/ u/ ", type=a)7677 def test_poem_scansion(self):78 ps = PoemScansion.objects.all()79 self.assertTrue(ps.exists())80 self.assertEqual(ps[0].poem.poem, "moon squirrel")81 self.assertFalse(ps[0].poem.human_scanned)82 self.assertEqual(ps[0].scansion, "/ u/ ")83 self.assertEqual(ps[0].type.function_name, "real_scan")
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!