class TestTestStage(TestCase): ORG_NAME = 'org-name' CHALLENGE_NAME = 'challenge-name' SUBMISSION_NAME = 'submission-01' SUBMISSION_URL = '[email protected]:org/submission.git' BASE_PATH = 'tests' CONTAINER_COMMAND = ['./gradlew', 'test'] challenge = Challenge(ORG_NAME, CHALLENGE_NAME) submission = Submission(SUBMISSION_NAME, SUBMISSION_URL, challenge) submission_path = f'{BASE_PATH}/{submission.path}' container_name = f'{submission.slug}--test' def setUp(self): self.executor = mock() self.stage = TestStage(self.BASE_PATH, self.executor) def test_run_submission_container(self): container = mock() when(self.executor).create_container( self.submission.slug, self.container_name, self.CONTAINER_COMMAND, self.submission_path).thenReturn(container) self.stage.execute(self.submission) verify(container).run()
class TestGitRepository(TestCase): ORG_NAME = 'org-name' CHALLENGE_NAME = 'challenge-name' SUBMISSION_NAME = 'submission-01' SUBMISSION_URL = '[email protected]:org/submission.git' BASE_PATH = 'tests' challenge = Challenge(ORG_NAME, CHALLENGE_NAME) submission = Submission(SUBMISSION_NAME, SUBMISSION_URL, challenge) submission_path = f'{BASE_PATH}/{submission.path}' def setUp(self): patch(git.Repo.clone_from, lambda a, b: '') self.repository = GitRepository(self.BASE_PATH) def test_clone_from_submission_url_into_path(self): self.repository.clone(self.submission) verify(Repo).clone_from(self.SUBMISSION_URL, self.submission_path) def test_old_submission_is_cleared_given_it_already_exists(self): patch(shutil.rmtree, lambda str: '') when(os.path).exists(self.submission_path).thenReturn(True) self.repository.clone(self.submission) verify(shutil).rmtree(self.submission_path)
class TestChallengeVerifier(TestCase): the_challenge = Challenge('an-ord', 'a-name') submission_repository = mock() verification_pipeline = mock() def setUp(self): verification_pipeline_factory = mock() when(verification_pipeline_factory).create().thenReturn( self.verification_pipeline) self.challenge_verifier = ChallengeVerifier( self.submission_repository, verification_pipeline_factory) def test_verification_pipeline_should_verify_each_submission(self): submissions = self.__given_submissions() self.challenge_verifier.verify_submissions(self.the_challenge) for submission in submissions: verify(self.verification_pipeline).verify(submission) def __given_submissions(self): submissions = [mock(), mock()] when(self.submission_repository).find_by_challenge( self.the_challenge).thenReturn(submissions) return submissions
class TestPreparationStage(TestCase): challenge = Challenge('org-name', 'challenge-name') submission = Submission('submission-01', 'submission-url', challenge) repository = mock() def setUp(self): self.preparation_stage = PreparationStage(self.repository) def test_clone_submission_repository(self): self.preparation_stage.execute(self.submission) verify(self.repository).clone(self.submission)
class TestTrackProgressStage(TestCase): ORG_NAME = 'org-name' CHALLENGE_NAME = 'challenge-name' SUBMISSION_NAME = 'submission-01' SUBMISSION_URL = '[email protected]:org/submission.git' BASE_PATH = 'tests' MONGO_HOST = 'mongo' CONTAINER_COMMAND = [ './gradlew', 'accept', f'-DteamToken={SUBMISSION_NAME}', f'-DmongoHost={MONGO_HOST}' ] challenge = Challenge(ORG_NAME, CHALLENGE_NAME) submission = Submission(SUBMISSION_NAME, SUBMISSION_URL, challenge) submission_path = f'{BASE_PATH}/{submission.path}' container_name = f'{submission.slug}--track-progress' def setUp(self): self.executor = mock() self.container = self.__setup_container() self.stage = TrackProgressStage(self.BASE_PATH, self.executor, self.MONGO_HOST) def test_the_container_is_run(self): self.stage.execute(self.submission) verify(self.container).run() def __setup_container(self): the_container = mock() when(self.executor).create_container( self.submission.slug, self.container_name, self.CONTAINER_COMMAND, self.submission_path).thenReturn(the_container) return the_container
from challenge.challenge import Challenge mensaje = "hola mundo" mensaje2 = " " c = Challenge() print(c.convertion(mensaje))
def convert(): return Challenge()
class TestVerificationPipeline(TestCase): A_TIMESTAMP = 1 A_STAGE_NAME = 'build' VERIFICATION_STAGE_STARTED = VerificationStageStatus.STARTED VERIFICATION_STAGE_SUCCEEDED = VerificationStageStatus.SUCCEEDED VERIFICATION_STAGE_FAILED = VerificationStageStatus.FAILED challenge = Challenge('org-name', 'challenge-name') submission = Submission('submission-01', 'submission-url', challenge) def setUp(self): when(time).time().thenReturn(self.A_TIMESTAMP) self.stage_started_event = self.__setup_verification_stage_event( self.VERIFICATION_STAGE_STARTED) self.stage_succeeded_event = self.__setup_verification_stage_event( self.VERIFICATION_STAGE_SUCCEEDED) self.stage_failed_event = self.__setup_verification_stage_event( self.VERIFICATION_STAGE_FAILED) self.failed_verification_stage = self.__setup_failed_verification_stage( ) self.first_verification_stage = self.__setup_succeeded_verification_stage( ) self.second_verification_stage = self.__setup_succeeded_verification_stage( ) self.event_store = mock() def test_each_verification_stage_is_executed_for_the_submission(self): some_verification_stages = [ self.first_verification_stage, self.second_verification_stage ] pipeline = VerificationPipeline(self.event_store, some_verification_stages) pipeline.verify(self.submission) for stage in some_verification_stages: verify(stage, inorder=True).execute(self.submission) def test_store_verification_stage_started_event(self): pipeline = VerificationPipeline(self.event_store, [self.first_verification_stage]) pipeline.verify(self.submission) verify(self.event_store).store(self.stage_started_event) def test_store_verification_stage_succeeded_event(self): pipeline = VerificationPipeline(self.event_store, [self.first_verification_stage]) pipeline.verify(self.submission) verify(self.event_store).store(self.stage_succeeded_event) def test_second_verification_stage_is_not_executed_given_first_verification_stage_failed( self): verification_stages = [ self.failed_verification_stage, self.second_verification_stage ] pipeline = VerificationPipeline(self.event_store, verification_stages) pipeline.verify(self.submission) verify(self.second_verification_stage, times=0).execute(self.submission) def test_store_verification_staged_failed_event_given_verification_stage_failed( self): pipeline = VerificationPipeline(self.event_store, [self.failed_verification_stage]) pipeline.verify(self.submission) verify(self.event_store).store(self.stage_failed_event) def __setup_succeeded_verification_stage(self): stage = mock({'name': self.A_STAGE_NAME}) return stage def __setup_failed_verification_stage(self): stage = mock({'name': self.A_STAGE_NAME}) when(stage).execute(self.submission).thenRaise( VerificationStageFailed(stage)) return stage def __setup_verification_stage_event(self, event): return VerificationStageEvent(self.A_STAGE_NAME, self.submission.name, event)