-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
fix #1527, more tests #1532
fix #1527, more tests #1532
Conversation
The test failed? |
That's odd, all the tests passed locally. |
I don't understand https://travis-ci.org/divio/django-cms/builds/3339563. The tests pass sometimes. What is the difference between all those jobs, and how can I do the same locally to test before I commit? |
OK, I see, it fails in Python 2.5 and 2.6, but is OK in Python 2.7. I will check that out. |
Tests pass now. The issue was: in earlier Pythons (pre 2.7) there was a different implementation of assertItemsEqual, which would take a list like:
and re-order it arbitrarily (in fact pretty much at random) because when it got hold of a model, it was like a monkey with a typewriter and really had no idea what to do with it. Many thanks to @apollo13 and #django. |
@@ -310,7 +311,7 @@ def copy_page(self, target, site, position='first-child', | |||
|
|||
# copy the placeholders (and plugins on those placeholders!) | |||
for ph in placeholders: | |||
plugins = list(ph.cmsplugin_set.all().order_by('tree_id', '-rght')) | |||
plugins = list(ph.cmsplugin_set.all()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about this line.... i think an ordering is needed here. If you want the same order as you inserted it in the test try: order_by('tree_id', 'lft')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But according to the tests, this does get the ordering right, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No because the test build the tree in a optimal way... from the ground up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test deliberately builds the tree in the 'wrong' order, to simulate things being added over time, not optimally - the nodes go: 1 2 4 10 8 3 9 5 6 7.
But perhaps it should be made even more difficult than that, to be a proper test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, all my attempts to make this break fail - it seems OK to me.
However, I would like to test moving plugins around as well, but as far as I can tell the CMS doesn't use CMSPlugin.move_to()
at all, and I haven't been able to use it successfully to move a plugin. How does the CMS move plugins, if not using that? Surely it has to at some level, if it's using the MPTT base class for them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, if the CMS never moves a plugin around in its tree, why should any of the tests? In which case, I don't see a need to make these tests do that.
OK, apologies for the excess of commits. What this latest patch (912803f is the important commit) does is:
|
tests pass with Python 2.5 and Django 1.3 on my local machine |
merge? |
reviewing the actual code now |
as noted on IRC: the current test tests the full page copy mechanism, not just |
Having just tried to avoid the full page create/copy routine, I remember why I didn't do it that way in the first place - I can't get it to work.
What happens is that |
that sounds like a huge problem that needs to be fixed first. placeholders need to work if not bound to pages. |
Now deep-nested plugin copy tests don't bother messing about with pages, and just work on placeholders. Simpler, and we save 0.8s in the tests. |
I'd appreciate a review before this is merged.
Fixes #1527 - when plugin trees were copied, their new structure was not always an accurate copy. In most cases this didn't actually have any effects, which is why this escaped so long.
It's likely relevant to #1463 also; one failure I had there was with copied plugin tree problems.
The problem was that in a copy, a plugin could be given the wrong parent - it would become the child of its sibling instead.
New test, test_plugin_deep_nesting_and_copying
Creates a structure that wouldn't be copied accurately before, and tests it thoroughly. It's a long test, but I can't see how to get around that, especially as it tests properties of the tree incrementally as more nodes are added, until finally it's copied.
CMSPlugin.copy_plugin()
This is where the heart of the problem was. The routine maintains a kind of breadcrumb trail though the plugin tree to work out a new plugin's parent, but would sometimes lose its way.
Some variables have been renamed to make it easier to understand their purpose; also lots of comments because I think the logic is not easy to follow unless you already know it.
Should be of interest to @adaptivelogic.