'Calling :func:`update_repo` downloads the new RPMs, creates the
metadata, and uploads it to S3.
- Existing packages on S3 are preserved in the metadata.
- Other packages on the buildserver are not downloaded.
- Existing metadata files are left untouched.'

def test_fake_rpm(self):

    existing_s3_keys = {os.path.join(self.target_key, 'existing_package.rpm'): '', os.path.join(self.target_key, 'clusterhq-flocker-cli-0.3.3-0.dev.7.noarch.rpm'): 'existing-content-to-be-replaced', os.path.join(self.target_key, 'repodata', 'repomod.xml'): '<oldhash>-metadata.xml', os.path.join(self.target_key, 'repodata', '<oldhash>-metadata.xml'): 'metadata    for:    existing_package.rpm'}
    expected_keys = existing_s3_keys.copy()
    aws = FakeAWS(routing_rules={}, s3_buckets={self.target_bucket: existing_s3_keys})
    unspecified_package = 'unspecified-package-0.3.3-0.dev.7.noarch.rpm'
    repo_contents = {'clusterhq-flocker-cli-0.3.3-0.dev.7.noarch.rpm': 'cli-package', 'clusterhq-flocker-node-0.3.3-0.dev.7.noarch.rpm': 'node-package', 'clusterhq-flocker-docker-plugin-0.3.3-0.dev.7.noarch.rpm': 'docker-plugin-package', unspecified_package: 'unspecified-package-content'}
    self.update_repo(aws=aws, yum=FakeYum(), package_directory=self.package_directory, target_bucket=self.target_bucket, target_key=self.target_key, source_repo=create_fake_repository(self, files=repo_contents), packages=self.packages, flocker_version='0.3.3.dev7', distribution=Distribution(name='centos', version='7'))
    expected_packages = {'existing_package.rpm', 'clusterhq-flocker-cli-0.3.3-0.dev.7.noarch.rpm', 'clusterhq-flocker-node-0.3.3-0.dev.7.noarch.rpm', 'clusterhq-flocker-docker-plugin-0.3.3-0.dev.7.noarch.rpm'}
    expected_keys.update({'test/target/key/clusterhq-flocker-cli-0.3.3-0.dev.7.noarch.rpm': 'cli-package', 'test/target/key/clusterhq-flocker-node-0.3.3-0.dev.7.noarch.rpm': 'node-package', 'test/target/key/clusterhq-flocker-docker-plugin-0.3.3-0.dev.7.noarch.rpm': 'docker-plugin-package'})
    expected_keys.update({os.path.join(self.target_key, 'repodata', 'repomod.xml'): '<newhash>-metadata.xml', os.path.join(self.target_key, 'repodata', '<newhash>-metadata.xml'): ('metadata    content    for:    ' + ','.join(sorted(expected_packages)))})
    self.assertEqual(expected_keys, aws.s3_buckets[self.target_bucket])
