Skip to content

Commit e34d281

Browse files
committed
Don't substitute primary key when impersonating the control page
This causes the wrong inline child objects to be picked up. Fixes #11
1 parent bc59913 commit e34d281

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

CHANGELOG.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Changelog
66

77
* Remove detection of bots by user-agent, as this directly contravenes Google's guidelines
88
(https://webmasters.googleblog.com/2012/08/website-testing-google-search.html)
9+
* Fix: Page ID is no longer switched when rendering alternative pages, so that the correct inline child objects are displayed
910

1011

1112
0.1.1 (01.11.2016)

experiments/utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ def percentage(fraction, population):
1616

1717
def impersonate_other_page(page, other):
1818
"""Modify the title and tree location data of `page` to resemble `other`"""
19-
page.id = other.id
20-
page.pk = other.pk
2119
page.path = other.path
2220
page.depth = other.depth
2321
page.url_path = other.url_path

tests/templates/tests/simple_page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<h1>{{ page.title }}</h1>
88
<ul class="breadcrumb">
99
{% for p in breadcrumb %}
10-
<li {% if p.pk == page.pk %}class="current"{% endif %}>{{ p.title }}</li>
10+
<li {% if p.url_path == page.url_path %}class="current"{% endif %}>{{ p.title }}</li>
1111
{% endfor %}
1212
</ul>
1313
<p>{{ page.body }}</p>

tests/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def test_selected_variation_depends_on_user_id(self):
4141
response = self.client.get('/')
4242
self.assertEqual(response.status_code, 200)
4343
self.assertContains(response, '<p>Welcome to our site!</p>')
44+
self.assertContains(response, '<a href="http://boring.example.com/">a boring link</a>')
4445

4546
session.clear()
4647
session['experiment_user_id'] = '33333333-3333-3333-3333-333333333333'
@@ -50,6 +51,7 @@ def test_selected_variation_depends_on_user_id(self):
5051
response = self.client.get('/')
5152
self.assertEqual(response.status_code, 200)
5253
self.assertContains(response, '<p>Welcome to our site! It&#39;s lovely to meet you.</p>')
54+
self.assertContains(response, '<a href="http://lovely.example.com/">a lovely link</a>')
5355

5456
def test_participant_is_logged(self):
5557
# initially there should be no experiment history
@@ -197,6 +199,7 @@ def test_draft_status(self):
197199
# but should get the standard homepage when it's draft
198200
self.assertEqual(response.status_code, 200)
199201
self.assertContains(response, '<p>Welcome to our site!</p>')
202+
self.assertContains(response, '<a href="http://boring.example.com/">a boring link</a>')
200203

201204
# no participant record should be logged
202205
self.assertEqual(ExperimentHistory.objects.filter(experiment=self.experiment).count(), 0)

0 commit comments

Comments
 (0)