def test_missmatched_checksum_should_log_error(self, mock: MagicMock):
        # Given
        secure_key = 'uuid'
        entity_type = 'run_experiment'
        index = f'{entity_type}1'
        file_name = 'file_name.extension1.ex2'
        expected_checksum = 'checksum'
        wrong_checksum = 'not-checksum'
        mock.return_value = f"{file_name},{expected_checksum}"

        # When
        validator = UploadValidator(secure_key)
        attributes = {
            'uploaded_file_1': file_name,
            'uploaded_file_1_checksum': wrong_checksum
        }
        entity = Entity(entity_type, index, attributes)
        validator.validate_entity(entity)

        # Then
        expected_errors = {
            'uploaded_file_1_checksum': [
                f'The checksum found on drag-and-drop {expected_checksum} does not match: {wrong_checksum}'
            ]
        }
        self.assertDictEqual(expected_errors, entity.get_errors())
Exemple #2
0
    def test_valid_sample_name_should_not_return_error(self):
        # Given
        sample_attributes = {
            'scientific_name': 'Severe acute respiratory syndrome coronavirus 2'
        }
        self.taxonomy_validator.ena_taxonomy.validate_scientific_name = MagicMock(return_value=self.valid_sarscov2)
        sample = Entity('sample', 'sample1', sample_attributes)

        # When
        self.taxonomy_validator.validate_entity(sample)

        # Then
        self.assertFalse(sample.has_errors())
        self.assertDictEqual({}, sample.get_errors())
Exemple #3
0
    def test_valid_sample_tax_id_should_not_return_error(self):
        # Given
        sample_attributes = {
            'tax_id': '2697049'
        }
        self.taxonomy_validator.ena_taxonomy.validate_tax_id = MagicMock(return_value=self.valid_sarscov2)
        sample = Entity('sample', 'sample1', sample_attributes)

        # When
        self.taxonomy_validator.validate_entity(sample)

        # Then
        self.assertFalse(sample.has_errors())
        self.assertDictEqual({}, sample.get_errors())
Exemple #4
0
    def test_invalid_name_should_return_error(self):
        sample_attributes = {'scientific_name': 'Lorem Ipsum'}
        error = 'Not valid scientific_name: Lorem Ipsum.'
        expected_error = {
            'scientific_name': [error]
        }
        self.taxonomy_validator.ena_taxonomy.validate_scientific_name = MagicMock(return_value={'error': error})

        sample = Entity('sample', 'sample1', sample_attributes)
        
        # When
        self.taxonomy_validator.validate_entity(sample)

        # Then
        self.assertTrue(sample.has_errors())
        self.assertDictEqual(expected_error, sample.get_errors())
Exemple #5
0
    def test_invalid_tax_id_should_return_error(self):
        # Given
        sample_attributes = {'tax_id': '999999999999'}
        error = 'Not valid tax_id: 999999999999.'
        expected_error = {
            'tax_id': [error]
        }
        self.taxonomy_validator.ena_taxonomy.validate_tax_id = MagicMock(return_value={'error': error})
        sample = Entity('sample', 'sample1', sample_attributes)

        # When
        self.taxonomy_validator.validate_entity(sample)

        # Then
        self.assertTrue(sample.has_errors())
        self.assertDictEqual(expected_error, sample.get_errors())
    def test_missing_file_should_log_error(self, mock: MagicMock):
        # Given
        entity_type = 'run_experiment'
        index = f'{entity_type}1'
        mock.return_value = f"file_name.extension1.ex2,checksum"
        validator = UploadValidator('uuid')
        entity = Entity(entity_type, index,
                        {'uploaded_file_1': 'missing.file'})
        expected_errors = {
            'uploaded_file_1':
            ['File has not been uploaded to drag-and-drop: missing.file']
        }
        # When
        validator.validate_entity(entity)

        # Then
        self.assertDictEqual(expected_errors, entity.get_errors())
    def test_validation_with_second_file_present(self, mock: MagicMock):
        # Given
        secure_key = 'uuid'
        entity_type = 'run_experiment'
        index = f'{entity_type}1'
        mock.return_value = f"first-file,first-checksum\n" \
                            f"second-file,second-checksum"
        # When
        validator = UploadValidator(secure_key)
        attributes = {
            'uploaded_file_1': 'first-file',
            'uploaded_file_1_checksum': 'first-checksum',
            'uploaded_file_2': 'second-file',
            'uploaded_file_2_checksum': 'second-checksum',
        }
        entity = Entity(entity_type, index, attributes)
        validator.validate_entity(entity)

        # Then
        self.assertDictEqual({}, entity.get_errors())
Exemple #8
0
    def test_inconsistent_sample_should_return_error(self):
        # Given
        sample_attributes = {
            'scientific_name': 'Severe acute respiratory syndrome coronavirus 2',
            'tax_id': '9606'
        }
        self.taxonomy_validator.ena_taxonomy.validate_scientific_name = MagicMock(return_value=self.valid_sarscov2)
        self.taxonomy_validator.ena_taxonomy.validate_tax_id = MagicMock(return_value=self.valid_human)
        consistent_error = 'Information is not consistent between taxId: 9606 and scientificName: Severe acute respiratory syndrome coronavirus 2'
        expected_errors = {
            'scientific_name': [consistent_error],
            'tax_id': [consistent_error]
        }
        
        sample = Entity('sample', 'sample1', sample_attributes)

        # When
        self.taxonomy_validator.validate_entity(sample)

        # Then
        self.assertTrue(sample.has_errors())
        self.assertDictEqual(expected_errors, sample.get_errors())
    def test_validation_with_second_file_missing(self, mock: MagicMock):
        # Given
        secure_key = 'uuid'
        entity_type = 'run_experiment'
        index = f'{entity_type}1'
        mock.return_value = f"first-file,first-checksum"

        # When
        validator = UploadValidator(secure_key)
        attributes = {
            'uploaded_file_1': 'first-file',
            'uploaded_file_2': 'second-file'
        }
        entity = Entity(entity_type, index, attributes)
        validator.validate_entity(entity)

        # Then
        expected_errors = {
            'uploaded_file_2':
            ['File has not been uploaded to drag-and-drop: second-file']
        }
        self.assertDictEqual(expected_errors, entity.get_errors())
Exemple #10
0
    def test_invalid_sample_name_should_return_error(self):
        # Given
        sample_attributes = {
            'scientific_name': 'Lorem Ipsum',
            'tax_id': '2697049'
        }
        error = 'Not valid scientific_name: Lorem Ipsum.'
        consistent_error = 'Information is not consistent between taxId: 2697049 and scientificName: Lorem Ipsum'
        expected_errors = {
            'scientific_name': [error, consistent_error],
            'tax_id': [consistent_error]
        }
        self.taxonomy_validator.ena_taxonomy.validate_scientific_name = MagicMock(return_value={'error': error})
        self.taxonomy_validator.ena_taxonomy.validate_tax_id = MagicMock(return_value=self.valid_sarscov2)
        
        sample = Entity('sample', 'sample1', sample_attributes)
        
        # When
        self.taxonomy_validator.validate_entity(sample)

        # Then
        self.assertTrue(sample.has_errors())
        self.assertDictEqual(expected_errors, sample.get_errors())