'Test for new_lineage() class method.'

@mock.patch('certbot.storage.relevant_values')
def test_new_lineage(self, mock_rv):

    mock_rv.side_effect = (lambda x: x)
    from certbot import storage
    result = storage.RenewableCert.new_lineage('the-lineage.com', 'cert', 'privkey', 'chain', self.config)
    self.assertTrue(result._consistent())
    self.assertTrue(os.path.exists(os.path.join(self.config.renewal_configs_dir, 'the-lineage.com.conf')))
    self.assertTrue(os.path.exists(os.path.join(self.config.live_dir, 'the-lineage.com', 'README')))
    with open(result.fullchain, 'rb') as f:
        self.assertEqual(f.read(), ('cert' + 'chain'))
    result = storage.RenewableCert.new_lineage('the-lineage.com', 'cert2', 'privkey2', 'chain2', self.config)
    self.assertTrue(os.path.exists(os.path.join(self.config.renewal_configs_dir, 'the-lineage.com-0001.conf')))
    self.assertTrue(os.path.exists(os.path.join(self.config.live_dir, 'the-lineage.com-0001', 'README')))
    os.mkdir(os.path.join(self.config.live_dir, 'the-lineage.com-0002'))
    self.assertRaises(errors.CertStorageError, storage.RenewableCert.new_lineage, 'the-lineage.com', 'cert3', 'privkey3', 'chain3', self.config)
    os.mkdir(os.path.join(self.config.default_archive_dir, 'other-example.com'))
    self.assertRaises(errors.CertStorageError, storage.RenewableCert.new_lineage, 'other-example.com', 'cert4', 'privkey4', 'chain4', self.config)
    result = storage.RenewableCert.new_lineage('the-lineage.com', 'cert2', 'privkey2', 'chain2', self.config)
