Skip to content

Commit

Permalink
Remove RepositoryPublishURLSerializer and use PublicationSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
David Davis committed Apr 29, 2019
1 parent 20a7a54 commit 3886e53
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 86 deletions.
1 change: 1 addition & 0 deletions .travis/before_install.sh
Expand Up @@ -7,6 +7,7 @@ export PULP_FILE_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:
export PULP_SMASH_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/PulpQE\/pulp-smash\/pull\/(\d+)' | awk -F'/' '{print $7}')
export PULP_PLUGIN_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/pulpcore-plugin\/pull\/(\d+)' | awk -F'/' '{print $7}')
export PULP_ROLES_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/ansible-pulp\/pull\/(\d+)' | awk -F'/' '{print $7}')
export PULP_CERTGUARD_PR_NUMBER=$(echo $COMMIT_MSG | grep -oP 'Required\ PR:\ https\:\/\/github\.com\/pulp\/pulp-certguard\/pull\/(\d+)' | awk -F'/' '{print $7}')

cd ..
git clone https://github.com/pulp/ansible-pulp.git
Expand Down
1 change: 0 additions & 1 deletion pulpcore/app/serializers/__init__.py
Expand Up @@ -38,7 +38,6 @@
ExporterSerializer,
RemoteSerializer,
PublisherSerializer,
RepositoryPublishURLSerializer,
RepositorySerializer,
RepositorySyncURLSerializer,
RepositoryVersionSerializer,
Expand Down
41 changes: 36 additions & 5 deletions pulpcore/app/serializers/publication.py
Expand Up @@ -16,15 +16,12 @@
RelatedField,
MasterModelSerializer,
ModelSerializer,
validate_unknown_fields,
)


class PublicationSerializer(MasterModelSerializer):
_href = DetailIdentityField()
publisher = DetailRelatedField(
help_text=_('The publisher that created this publication.'),
queryset=models.Publisher.objects.all()
)
_distributions = serializers.HyperlinkedRelatedField(
help_text=_('This publication is currently being served as'
'defined by these distributions.'),
Expand All @@ -36,8 +33,41 @@ class PublicationSerializer(MasterModelSerializer):
view_name='versions-detail',
lookup_field='number',
parent_lookup_kwargs={'repository_pk': 'repository__pk'},
read_only=True,
queryset=models.RepositoryVersion.objects.all(),
required=False,
)
repository = serializers.HyperlinkedRelatedField(
help_text=_('A URI of the repository to be published.'),
required=False,
label=_('Repository'),
queryset=models.Repository.objects.all(),
view_name='repositories-detail',
)

def validate(self, data):
if hasattr(self, 'initial_data'):
validate_unknown_fields(self.initial_data, self.fields)

repository = data.pop('repository', None) # not an actual field on publication
repository_version = data.get('repository_version')
if not repository and not repository_version:
raise serializers.ValidationError(
_("Either the 'repository' or 'repository_version' need to be specified"))
elif not repository and repository_version:
return data
elif repository and not repository_version:
version = models.RepositoryVersion.latest(repository)
if version:
new_data = {'repository_version': version}
new_data.update(data)
return new_data
else:
raise serializers.ValidationError(
detail=_('Repository has no version available to create Publication from'))
raise serializers.ValidationError(
_("Either the 'repository' or 'repository_version' need to be specified "
"but not both.")
)

class Meta:
abstract = True
Expand All @@ -46,6 +76,7 @@ class Meta:
'publisher',
'_distributions',
'repository_version',
'repository'
)


Expand Down
47 changes: 0 additions & 47 deletions pulpcore/app/serializers/repository.py
Expand Up @@ -14,7 +14,6 @@
MasterModelSerializer,
ModelSerializer,
)
from pulpcore.app.serializers import validate_unknown_fields


class RepositorySerializer(ModelSerializer):
Expand Down Expand Up @@ -168,52 +167,6 @@ class Meta:
)


class RepositoryPublishURLSerializer(serializers.Serializer):

repository = serializers.HyperlinkedRelatedField(
help_text=_('A URI of the repository to be synchronized.'),
required=False,
label=_('Repository'),
queryset=models.Repository.objects.all(),
view_name='repositories-detail',
)

repository_version = NestedRelatedField(
help_text=_('A URI of the repository version to be published.'),
required=False,
label=_('Repository Version'),
queryset=models.RepositoryVersion.objects.all(),
view_name='versions-detail',
lookup_field='number',
parent_lookup_kwargs={'repository_pk': 'repository__pk'},
)

def validate(self, data):
if hasattr(self, 'initial_data'):
validate_unknown_fields(self.initial_data, self.fields)

repository = data.pop('repository', None)
repository_version = data.get('repository_version')
if not repository and not repository_version:
raise serializers.ValidationError(
_("Either the 'repository' or 'repository_version' need to be specified"))
elif not repository and repository_version:
return data
elif repository and not repository_version:
version = models.RepositoryVersion.latest(repository)
if version:
new_data = {'repository_version': version}
new_data.update(data)
return new_data
else:
raise serializers.ValidationError(
detail=_('Repository has no version available to publish'))
raise serializers.ValidationError(
_("Either the 'repository' or 'repository_version' need to be specified "
"but not both.")
)


class ExporterSerializer(MasterModelSerializer):
_href = DetailIdentityField()
name = serializers.CharField(
Expand Down
4 changes: 2 additions & 2 deletions pulpcore/tests/functional/api/using_plugin/constants.py
Expand Up @@ -17,10 +17,10 @@

FILE_REMOTE_PATH = urljoin(BASE_REMOTE_PATH, 'file/file/')

FILE_PUBLISHER_PATH = urljoin(BASE_PUBLISHER_PATH, 'file/file/')

FILE_PUBLICATION_PATH = urljoin(BASE_PUBLICATION_PATH, 'file/file/')

FILE_PUBLISHER_PATH = urljoin(BASE_PUBLISHER_PATH, 'file/file/')

FILE_FIXTURE_URL = urljoin(PULP_FIXTURES_BASE_URL, 'file/')
"""The URL to a file repository."""

Expand Down
Expand Up @@ -16,7 +16,6 @@
gen_repo,
get_added_content,
get_versions,
publish,
sync,
)

Expand All @@ -28,7 +27,7 @@
FILE_REMOTE_PATH,
FILE_URL
)
from pulpcore.tests.functional.api.using_plugin.utils import populate_pulp
from pulpcore.tests.functional.api.using_plugin.utils import populate_pulp, create_file_publication
from pulpcore.tests.functional.api.using_plugin.utils import ( # noqa:F401
set_up_module as setUpModule
)
Expand Down Expand Up @@ -99,7 +98,7 @@ def test_repo_auto_distribution(self):
self.addCleanup(self.client.delete, distribution['_href'])

last_version_href = get_versions(repo)[-1]['_href']
publication = publish(self.cfg, publisher, repo, last_version_href)
publication = create_file_publication(self.cfg, repo, last_version_href, publisher)

self.addCleanup(self.client.delete, publication['_href'])
distribution = self.client.get(distribution['_href'])
Expand All @@ -114,7 +113,7 @@ def test_repo_auto_distribution(self):
)
repo = self.client.get(repo['_href'])
last_version_href = get_versions(repo)[-1]['_href']
publication = publish(self.cfg, publisher, repo, last_version_href)
publication = create_file_publication(self.cfg, repo, last_version_href, publisher)

self.addCleanup(self.client.delete, publication['_href'])
distribution = self.client.get(distribution['_href'])
Expand Down Expand Up @@ -199,7 +198,7 @@ def test_all(self):

sync(self.cfg, remote, repo)

publication = publish(self.cfg, publisher, repo)
publication = create_file_publication(self.cfg, repo, publisher=publisher)
self.addCleanup(self.client.delete, publication['_href'])

distribution = self.client.get(distribution['_href'])
Expand Down
Expand Up @@ -13,14 +13,13 @@
gen_publisher,
gen_repo,
get_versions,
publish,
)

from pulpcore.tests.functional.api.using_plugin.constants import (
FILE_CONTENT_PATH,
FILE_PUBLISHER_PATH,
)
from pulpcore.tests.functional.api.using_plugin.utils import populate_pulp
from pulpcore.tests.functional.api.using_plugin.utils import populate_pulp, create_file_publication
from pulpcore.tests.functional.api.using_plugin.utils import ( # noqa:F401
set_up_module as setUpModule,
)
Expand Down Expand Up @@ -82,7 +81,7 @@ def test_content_app_returns_404(self):
self.addCleanup(self.client.delete, distribution['_href'])

last_version_href = get_versions(repo)[-1]['_href']
publication = publish(self.cfg, publisher, repo, last_version_href)
publication = create_file_publication(self.cfg, repo, last_version_href, publisher)

self.addCleanup(self.client.delete, publication['_href'])
distribution = self.client.get(distribution['_href'])
Expand Down
Expand Up @@ -20,7 +20,6 @@
gen_publisher,
gen_repo,
get_content,
publish,
sync,
)

Expand All @@ -32,6 +31,7 @@
)
from pulpcore.tests.functional.api.using_plugin.utils import (
gen_file_remote,
create_file_publication
)
from pulpcore.tests.functional.api.using_plugin.utils import ( # noqa:F401
set_up_module as setUpModule
Expand Down Expand Up @@ -75,7 +75,7 @@ def test_content_remote_delete(self):
publisher = client.post(FILE_PUBLISHER_PATH, gen_publisher())
self.addCleanup(client.delete, publisher['_href'])

publication = publish(cfg, publisher, repo)
publication = create_file_publication(cfg, repo, publisher=publisher)
self.addCleanup(client.delete, publication['_href'])

# Delete the remote.
Expand Down
Expand Up @@ -9,7 +9,6 @@
gen_publisher,
gen_remote,
gen_repo,
publish,
sync,
)

Expand All @@ -19,6 +18,7 @@
FILE_REMOTE_PATH,
)
from pulpcore.tests.functional.api.using_plugin.utils import ( # noqa:F401
create_file_publication,
set_up_module as setUpModule
)

Expand Down Expand Up @@ -70,4 +70,4 @@ def test_all(self):
for _ in range(2):
sync(cfg, remote, repo)
repo = client.get(repo['_href'])
publish(cfg, publisher, repo)
create_file_publication(cfg, repo, publisher=publisher)
Expand Up @@ -12,7 +12,6 @@
gen_remote,
gen_repo,
get_added_content,
publish,
sync,
)

Expand All @@ -23,6 +22,7 @@
FILE_REMOTE_PATH
)
from pulpcore.tests.functional.api.using_plugin.utils import ( # noqa:F401
create_file_publication,
set_up_module as setUpModule
)

Expand Down Expand Up @@ -67,7 +67,7 @@ def test_all(self):
publisher = client.post(FILE_PUBLISHER_PATH, gen_publisher())
self.addCleanup(client.delete, publisher['_href'])

publication = publish(cfg, publisher, repo)
publication = create_file_publication(cfg, repo, publisher=publisher)
self.addCleanup(client.delete, publication['_href'])

distributions = []
Expand Down
Expand Up @@ -14,7 +14,6 @@
gen_distribution,
gen_publisher,
gen_repo,
publish,
sync
)

Expand All @@ -26,6 +25,7 @@
)
from pulpcore.tests.functional.api.using_plugin.utils import (
gen_file_remote,
create_file_publication,
skip_if
)
from pulpcore.tests.functional.api.using_plugin.utils import set_up_module as setUpModule # noqa
Expand Down Expand Up @@ -62,10 +62,10 @@ def tearDownClass(cls):
if resource:
cls.client.delete(resource['_href'])

def test_01_create_publication(self):
def test_01_create_file_publication(self):
"""Create a publication."""
self.publication.update(
publish(self.cfg, self.publisher, self.repo)
create_file_publication(self.cfg, self.repo, publisher=self.publisher)
)

@skip_if(bool, 'publication', False)
Expand Down Expand Up @@ -165,7 +165,7 @@ def test_06_publication_create_order(self):
"""
# Create more 2 publications for the same repo
for _ in range(2):
publish(self.cfg, self.publisher, self.repo)
create_file_publication(self.cfg, self.repo, publisher=self.publisher)

# Read publications
publications = self.client.get(
Expand Down
Expand Up @@ -22,7 +22,6 @@
get_removed_content,
get_removed_content_summary,
get_versions,
publish,
sync,
)

Expand All @@ -39,6 +38,7 @@
from pulpcore.tests.functional.api.using_plugin.utils import (
gen_file_remote,
populate_pulp,
create_file_publication,
skip_if,
)
from pulpcore.tests.functional.api.using_plugin.utils import set_up_module as setUpModule # noqa
Expand Down Expand Up @@ -370,7 +370,7 @@ def test_delete_publication(self):
publisher = self.client.post(FILE_PUBLISHER_PATH, gen_publisher())
self.addCleanup(self.client.delete, publisher['_href'])

publication = publish(self.cfg, publisher, self.repo)
publication = create_file_publication(self.cfg, self.repo, publisher=publisher)
delete_version(self.repo)

with self.assertRaises(HTTPError):
Expand Down
Expand Up @@ -9,7 +9,6 @@
gen_publisher,
gen_repo,
get_content,
publish,
sync,
)

Expand All @@ -18,7 +17,7 @@
FILE_REMOTE_PATH,
FILE_PUBLISHER_PATH
)
from pulpcore.tests.functional.api.using_plugin.utils import gen_file_remote
from pulpcore.tests.functional.api.using_plugin.utils import gen_file_remote, create_file_publication
from pulpcore.tests.functional.api.using_plugin.utils import set_up_module as setUpModule # noqa


Expand Down Expand Up @@ -76,7 +75,7 @@ def test_all(self):
# Publish repositories.
publications = []
for repo in repos:
publications.append(publish(cfg, publisher, repo))
publications.append(create_file_publication(cfg, repo, publisher=publisher))
self.assertEqual(
publications[0]['publisher'],
publications[1]['publisher']
Expand Down

0 comments on commit 3886e53

Please sign in to comment.