Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite Entity.__init__, add sync plan tests #1969

Merged
merged 2 commits into from Mar 9, 2015
Merged

Rewrite Entity.__init__, add sync plan tests #1969

merged 2 commits into from Mar 9, 2015

Conversation

Ichimonji10
Copy link
Contributor

See individual commit messages for details.

The changes made in this PR are extensive, so I decided that it was appropriate to run the entire test suite. Here's the results:

Ran 971 tests in 1556.222s

FAILED (SKIP=196, errors=14, failures=9)

Twelve of the failures were due to my robottelo.properties file not containing docker configuration options. After updating my robottelo.properties files, I am convinced that they are fine. Several more failures are due to abrt-related permissions not being returned from the server. The remaining failures are due to the server rejecting the bogus manifest submitted during the test_subscription tests. All in all, the test results are completely sane.

).create_json()['id']
cls.prod2_id = entities.Product(
organization=cls.org_id
).create_json()['id']
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've dropped this because of BZ 1199150. Re-using these products for multiple tests causes unnecessary test failures. test_repeatedly_add_remove targets this issue.

@omaciel
Copy link
Member

omaciel commented Mar 5, 2015

ACK pending clarification of comments.

@Ichimonji10
Copy link
Contributor Author

This pull request has been completely updated to take care of this issue.

I tweaked SyncPlan.__init__ a little bit. The tests mentioned in the commit message still pass. I've made this tweak because of a bug I just discovered in Entity.__init__. The bug is the fact that when an entity is first created, this yields an integer:

SomeEntity(related_entity=1).related_entity

But when an entity is read back, this yields an Entity subclass:

SomeEntity(id=N).read().related_entity

The tweak I made will make that fix easier to implement in the future.

syncplan.add_products(product_ids)
self.assertEqual(len(syncplan.read_json()['products']), 2)
syncplan.remove_products([product_ids[0]])
self.assertEqual(len(syncplan.read_json()['products']), 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be too much to ask that you assert that the product 'left' is the one you did not delete? Just to be safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I'll do this.

@Ichimonji10 Ichimonji10 changed the title Add some sync plan tests [DONOTMERGE] Add some sync plan tests Mar 5, 2015
@Ichimonji10 Ichimonji10 changed the title [DONOTMERGE] Add some sync plan tests [DONOTMERGE] Rewrite Entity.__init__, add sync plan tests Mar 6, 2015
@Ichimonji10 Ichimonji10 changed the title [DONOTMERGE] Rewrite Entity.__init__, add sync plan tests Rewrite Entity.__init__, add sync plan tests Mar 6, 2015
@omaciel
Copy link
Member

omaciel commented Mar 6, 2015

ACK

@Ichimonji10
Copy link
Contributor Author

If anyone is confused by the changes in this pull request (and I don't blame you!), feel free to ask me for clarification. I'll walk you through all the changes I've made.

@@ -1321,7 +1330,8 @@ def create_missing(self, auth=None):
verify=False,
data={
u'name': u'Library',
u'organization_id': self.organization,
# pylint:disable=no-member
u'organization_id': self.organization.id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@elyezer
Copy link
Contributor

elyezer commented Mar 7, 2015

ACK, pending comments.

Method `Entity.__init__` is buggy. The bug lies in the fact that entity
creation behaves differently from entity reading. For example:

    >>> SomeEntity(related_entity=1).related_entity == 1
    True
    >>> SomeEntity(id=N).read().related_entity == 1
    False

This is problematic, because it is hard to know what type of object a foreign
key field is. Will a foreign key field be an integer? An `Entity` object? That's
hard to determine. Fix this issue by making `Entity.__init__` behave like
`EntityReadMixin.read`:

    >>> isinstance(SomeEntity(related_entity=1).related_entity, RelatedEntity)
    True
    >>> isinstance(SomeEntity(id=N).read().related_entity, RelatedEntity)
    True

Explain the new behaviour in `Entity`'s docstring.

Take advantage of this new behaviour and rewrite both the
`OperatingSystemEntity` and `SyncPlan` entity classes. Add a test for
`SyncPlan.read` to module `tests.foreman.api.test_multiple_paths`. Update a test
for `OperatingSystemParameter` in module
`tests.foreman.api.test_operatingsystem`.
Test that it is possible to add products to and remove products from a sync
plan. These tests target the following BZs:

* [1132914](https://bugzilla.redhat.com/show_bug.cgi?id=1132914): "Duplicate route sync plan"
* [1199150](https://bugzilla.redhat.com/show_bug.cgi?id=1199150): "Adding or removing products from a syncplan should return a task"

Also, fiddle with decorators. Remove unnecessary `@ddt` decorators from classes
and add `@stubbed` decorators to them. The addition of the `@stubbed` decorators
prevents unnecessary `setUpClass` methods from executing.
@Ichimonji10
Copy link
Contributor Author

@elyezer, I've %s/^@stubbed$/@stubbed() in test_syncplan.py.

Rebased.

@elyezer
Copy link
Contributor

elyezer commented Mar 9, 2015

ACK

elyezer added a commit that referenced this pull request Mar 9, 2015
Rewrite `Entity.__init__`, add sync plan tests
@elyezer elyezer merged commit 581acfb into SatelliteQE:master Mar 9, 2015
@elyezer
Copy link
Contributor

elyezer commented Mar 9, 2015

Karma given

@Ichimonji10 Ichimonji10 deleted the syncplan-tests branch March 9, 2015 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants