def test_bug_709938_interests(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True testuser = self.user_model.objects.get(username='******') self.client.login(username=testuser.username, password=TESTUSER_PASSWORD) url = reverse('users.profile_edit', args=(testuser.username,)) response = self.client.get(url, follow=True) doc = pq(response.content) test_tags = [u'science,Technology,paradox,knowledge,modeling,big data,' u'vector,meme,heuristics,harmony,mathesis universalis,' u'symmetry,mathematics,computer graphics,field,chemistry,' u'religion,astronomy,physics,biology,literature,' u'spirituality,Art,Philosophy,Psychology,Business,Music,' u'Computer Science'] form = self._get_current_form_field_values(doc) form['profile-interests'] = test_tags response = self.client.post(url, form, follow=True) eq_(200, response.status_code) doc = pq(response.content) eq_(1, doc.find('ul.errorlist li').length) assert ('Ensure this value has at most 255 characters' in doc.find('ul.errorlist li').text())
def test_bug_709938_interests(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True testuser = User.objects.get(username='******') self.client.login(username=testuser.username, password=TESTUSER_PASSWORD) url = reverse('users.profile_edit', args=(testuser.username, )) r = self.client.get(url, follow=True) doc = pq(r.content) test_tags = [ u'science,Technology,paradox,knowledge,modeling,big data,' u'vector,meme,heuristics,harmony,mathesis universalis,' u'symmetry,mathematics,computer graphics,field,chemistry,' u'religion,astronomy,physics,biology,literature,' u'spirituality,Art,Philosophy,Psychology,Business,Music,' u'Computer Science' ] form = self._get_current_form_field_values(doc) form['profile-interests'] = test_tags r = self.client.post(url, form, follow=True) eq_(200, r.status_code) doc = pq(r.content) eq_(1, doc.find('ul.errorlist li').length) assert ('Ensure this value has at most 255 characters' in doc.find('ul.errorlist li').text())
def test_user_edit(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True testuser = self.user_model.objects.get(username='******') url = reverse('users.user_detail', args=(testuser.username,)) response = self.client.get(url, follow=True) doc = pq(response.content) eq_(0, doc.find('#user-head .edit .button').length) self.client.login(username=testuser.username, password=TESTUSER_PASSWORD) url = reverse('users.user_detail', args=(testuser.username,)) response = self.client.get(url, follow=True) doc = pq(response.content) edit_button = doc.find('#user-head .user-buttons #edit-user') eq_(1, edit_button.length) url = edit_button.attr('href') response = self.client.get(url, follow=True) doc = pq(response.content) eq_(testuser.fullname, doc.find('#user-edit input[name="user-fullname"]').val()) eq_(testuser.title, doc.find('#user-edit input[name="user-title"]').val()) eq_(testuser.organization, doc.find('#user-edit input[name="user-organization"]').val()) eq_(testuser.location, doc.find('#user-edit input[name="user-location"]').val()) eq_(testuser.irc_nickname, doc.find('#user-edit input[name="user-irc_nickname"]').val()) new_attrs = { 'user-username': testuser.username, 'user-email': '*****@*****.**', 'user-fullname': "Another Name", 'user-title': "Another title", 'user-organization': "Another org", 'user-country': "us", 'user-format': "html" } response = self.client.post(url, new_attrs, follow=True) doc = pq(response.content) eq_(1, doc.find('#user-head').length) eq_(new_attrs['user-fullname'], doc.find('#user-head .fn').text()) eq_(new_attrs['user-title'], doc.find('#user-head .user-info .title').text()) eq_(new_attrs['user-organization'], doc.find('#user-head .user-info .org').text()) testuser = self.user_model.objects.get(username=testuser.username) eq_(new_attrs['user-fullname'], testuser.fullname) eq_(new_attrs['user-title'], testuser.title) eq_(new_attrs['user-organization'], testuser.organization)
def test_user_edit(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True testuser = self.user_model.objects.get(username='******') url = reverse('users.user_detail', args=(testuser.username, )) response = self.client.get(url, follow=True) doc = pq(response.content) eq_(0, doc.find('#user-head .edit .button').length) self.client.login(username=testuser.username, password=TESTUSER_PASSWORD) url = reverse('users.user_detail', args=(testuser.username, )) response = self.client.get(url, follow=True) doc = pq(response.content) edit_button = doc.find('#user-head .user-buttons #edit-user') eq_(1, edit_button.length) url = edit_button.attr('href') response = self.client.get(url, follow=True) doc = pq(response.content) eq_(testuser.fullname, doc.find('#user-edit input[name="user-fullname"]').val()) eq_(testuser.title, doc.find('#user-edit input[name="user-title"]').val()) eq_(testuser.organization, doc.find('#user-edit input[name="user-organization"]').val()) eq_(testuser.location, doc.find('#user-edit input[name="user-location"]').val()) eq_(testuser.irc_nickname, doc.find('#user-edit input[name="user-irc_nickname"]').val()) new_attrs = { 'user-username': testuser.username, 'user-email': '*****@*****.**', 'user-fullname': "Another Name", 'user-title': "Another title", 'user-organization': "Another org", 'user-country': "us", 'user-format': "html" } response = self.client.post(url, new_attrs, follow=True) doc = pq(response.content) eq_(1, doc.find('#user-head').length) eq_(new_attrs['user-fullname'], doc.find('#user-head .fn').text()) eq_(new_attrs['user-title'], doc.find('#user-head .user-info .title').text()) eq_(new_attrs['user-organization'], doc.find('#user-head .user-info .org').text()) testuser = self.user_model.objects.get(username=testuser.username) eq_(new_attrs['user-fullname'], testuser.fullname) eq_(new_attrs['user-title'], testuser.title) eq_(new_attrs['user-organization'], testuser.organization)
def test_profile_edit(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True profile = UserProfile.objects.get(user__username='******') url = reverse('users.profile', args=(profile.user.username,)) r = self.client.get(url, follow=True) doc = pq(r.content) eq_(0, doc.find('#profile-head .edit .button').length) self.client.login(username=profile.user.username, password=TESTUSER_PASSWORD) url = reverse('users.profile', args=(profile.user.username,)) r = self.client.get(url, follow=True) doc = pq(r.content) edit_button = doc.find('#profile-head .profile-buttons #edit-profile') eq_(1, edit_button.length) url = edit_button.attr('href') r = self.client.get(url, follow=True) doc = pq(r.content) eq_(profile.fullname, doc.find('#profile-edit input[name="profile-fullname"]').val()) eq_(profile.title, doc.find('#profile-edit input[name="profile-title"]').val()) eq_(profile.organization, doc.find('#profile-edit input[name="profile-organization"]').val()) eq_(profile.location, doc.find('#profile-edit input[name="profile-location"]').val()) eq_(profile.irc_nickname, doc.find('#profile-edit input[name="profile-irc_nickname"]').val()) new_attrs = { 'profile-email': '*****@*****.**', 'profile-fullname': "Another Name", 'profile-title': "Another title", 'profile-organization': "Another org", 'profile-country': "us", 'profile-format': "html" } r = self.client.post(url, new_attrs, follow=True) doc = pq(r.content) eq_(1, doc.find('#profile-head').length) eq_(new_attrs['profile-fullname'], doc.find('#profile-head .fn').text()) eq_(new_attrs['profile-title'], doc.find('#profile-head .profile-info .title').text()) eq_(new_attrs['profile-organization'], doc.find('#profile-head .profile-info .org').text()) profile = UserProfile.objects.get(user__username=profile.user.username) eq_(new_attrs['profile-fullname'], profile.fullname) eq_(new_attrs['profile-title'], profile.title) eq_(new_attrs['profile-organization'], profile.organization)
def test_profile_edit(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True profile = UserProfile.objects.get(user__username='******') url = reverse('users.profile', args=(profile.user.username, )) r = self.client.get(url, follow=True) doc = pq(r.content) eq_(0, doc.find('#profile-head .edit .button').length) self.client.login(username=profile.user.username, password=TESTUSER_PASSWORD) url = reverse('users.profile', args=(profile.user.username, )) r = self.client.get(url, follow=True) doc = pq(r.content) edit_button = doc.find('#profile-head .profile-buttons #edit-profile') eq_(1, edit_button.length) url = edit_button.attr('href') r = self.client.get(url, follow=True) doc = pq(r.content) eq_(profile.fullname, doc.find('#profile-edit input[name="profile-fullname"]').val()) eq_(profile.title, doc.find('#profile-edit input[name="profile-title"]').val()) eq_(profile.organization, doc.find('#profile-edit input[name="profile-organization"]').val()) eq_(profile.location, doc.find('#profile-edit input[name="profile-location"]').val()) eq_(profile.irc_nickname, doc.find('#profile-edit input[name="profile-irc_nickname"]').val()) new_attrs = { 'profile-email': '*****@*****.**', 'profile-fullname': "Another Name", 'profile-title': "Another title", 'profile-organization': "Another org", 'profile-country': "us", 'profile-format': "html" } r = self.client.post(url, new_attrs, follow=True) doc = pq(r.content) eq_(1, doc.find('#profile-head').length) eq_(new_attrs['profile-fullname'], doc.find('#profile-head .fn').text()) eq_(new_attrs['profile-title'], doc.find('#profile-head .profile-info .title').text()) eq_(new_attrs['profile-organization'], doc.find('#profile-head .profile-info .org').text()) profile = UserProfile.objects.get(user__username=profile.user.username) eq_(new_attrs['profile-fullname'], profile.fullname) eq_(new_attrs['profile-title'], profile.title) eq_(new_attrs['profile-organization'], profile.organization)
def test_profile_edit_websites(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True testuser = self.user_model.objects.get(username="******") self.client.login(username=testuser.username, password=TESTUSER_PASSWORD) url = reverse("users.profile_edit", args=(testuser.username,)) response = self.client.get(url, follow=True) doc = pq(response.content) test_sites = { u"website": u"http://example.com/", u"twitter": u"http://twitter.com/lmorchard", u"github": u"http://github.com/lmorchard", u"stackoverflow": u"http://stackoverflow.com/users/lmorchard", u"linkedin": u"https://www.linkedin.com/in/testuser", u"mozillians": u"https://mozillians.org/u/testuser", u"facebook": u"https://www.facebook.com/test.user", } form = self._get_current_form_field_values(doc) # Fill out the form with websites. form.update(dict(("profile-websites_%s" % k, v) for k, v in test_sites.items())) # Submit the form, verify redirect to profile detail response = self.client.post(url, form, follow=True) doc = pq(response.content) eq_(1, doc.find("#profile-head").length) profile = UserProfile.objects.get(user=testuser) # Verify the websites are saved in the profile. eq_(test_sites, profile.websites) # Verify the saved websites appear in the editing form url = reverse("users.profile_edit", args=(testuser.username,)) response = self.client.get(url, follow=True) doc = pq(response.content) for k, v in test_sites.items(): eq_(v, doc.find('#profile-edit *[name="profile-websites_%s"]' % k).val()) # Come up with some bad sites, either invalid URL or bad URL prefix bad_sites = { u"website": u"HAHAHA WHAT IS A WEBSITE", u"twitter": u"http://facebook.com/lmorchard", u"stackoverflow": u"http://overqueueblah.com/users/lmorchard", } form.update(dict(("profile-websites_%s" % k, v) for k, v in bad_sites.items())) # Submit the form, verify errors for all of the bad sites response = self.client.post(url, form, follow=True) doc = pq(response.content) eq_(1, doc.find("#profile-edit").length) tmpl = "#profile-edit #profiles .%s .errorlist" for n in ("website", "twitter", "stackoverflow"): eq_(1, doc.find(tmpl % n).length)
def test_profile_edit_interests(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True testuser = User.objects.get(username='******') self.client.login(username=testuser.username, password=TESTUSER_PASSWORD) url = reverse('users.profile_edit', args=(testuser.username, )) r = self.client.get(url, follow=True) doc = pq(r.content) test_tags = ['javascript', 'css', 'canvas', 'html', 'homebrewing'] form = self._get_current_form_field_values(doc) form['profile-interests'] = ', '.join(test_tags) r = self.client.post(url, form, follow=True) doc = pq(r.content) eq_(1, doc.find('#profile-head').length) profile = UserProfile.objects.get(user=testuser) result_tags = [ t.name.replace('profile:interest:', '') for t in profile.tags.all_ns('profile:interest:') ] result_tags.sort() test_tags.sort() eq_(test_tags, result_tags) test_expertise = ['css', 'canvas'] form['profile-expertise'] = ', '.join(test_expertise) r = self.client.post(url, form, follow=True) doc = pq(r.content) eq_(1, doc.find('#profile-head').length) profile = UserProfile.objects.get(user=testuser) result_tags = [ t.name.replace('profile:expertise:', '') for t in profile.tags.all_ns('profile:expertise') ] result_tags.sort() test_expertise.sort() eq_(test_expertise, result_tags) # Now, try some expertise tags not covered in interests test_expertise = ['css', 'canvas', 'mobile', 'movies'] form['profile-expertise'] = ', '.join(test_expertise) r = self.client.post(url, form, follow=True) doc = pq(r.content) eq_(1, doc.find('.error #id_profile-expertise').length)
def test_profile_edit_interests(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True testuser = self.user_model.objects.get(username='******') self.client.login(username=testuser.username, password=TESTUSER_PASSWORD) url = reverse('users.profile_edit', args=(testuser.username,)) response = self.client.get(url, follow=True) doc = pq(response.content) test_tags = ['javascript', 'css', 'canvas', 'html', 'homebrewing'] form = self._get_current_form_field_values(doc) form['profile-interests'] = ', '.join(test_tags) response = self.client.post(url, form, follow=True) doc = pq(response.content) eq_(1, doc.find('#profile-head').length) profile = UserProfile.objects.get(user=testuser) result_tags = [t.name.replace('profile:interest:', '') for t in profile.tags.all_ns('profile:interest:')] result_tags.sort() test_tags.sort() eq_(test_tags, result_tags) test_expertise = ['css', 'canvas'] form['profile-expertise'] = ', '.join(test_expertise) response = self.client.post(url, form, follow=True) doc = pq(response.content) eq_(1, doc.find('#profile-head').length) profile = UserProfile.objects.get(user=testuser) result_tags = [t.name.replace('profile:expertise:', '') for t in profile.tags.all_ns('profile:expertise')] result_tags.sort() test_expertise.sort() eq_(test_expertise, result_tags) # Now, try some expertise tags not covered in interests test_expertise = ['css', 'canvas', 'mobile', 'movies'] form['profile-expertise'] = ', '.join(test_expertise) response = self.client.post(url, form, follow=True) doc = pq(response.content) eq_(1, doc.find('.error #id_profile-expertise').length)
def test_profile_edit(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True profile = UserProfile.objects.get(user__username="******") url = reverse("users.profile", args=(profile.user.username,)) response = self.client.get(url, follow=True) doc = pq(response.content) eq_(0, doc.find("#profile-head .edit .button").length) self.client.login(username=profile.user.username, password=TESTUSER_PASSWORD) url = reverse("users.profile", args=(profile.user.username,)) response = self.client.get(url, follow=True) doc = pq(response.content) edit_button = doc.find("#profile-head .profile-buttons #edit-profile") eq_(1, edit_button.length) url = edit_button.attr("href") response = self.client.get(url, follow=True) doc = pq(response.content) eq_(profile.fullname, doc.find('#profile-edit input[name="profile-fullname"]').val()) eq_(profile.title, doc.find('#profile-edit input[name="profile-title"]').val()) eq_(profile.organization, doc.find('#profile-edit input[name="profile-organization"]').val()) eq_(profile.location, doc.find('#profile-edit input[name="profile-location"]').val()) eq_(profile.irc_nickname, doc.find('#profile-edit input[name="profile-irc_nickname"]').val()) new_attrs = { "profile-email": "*****@*****.**", "profile-fullname": "Another Name", "profile-title": "Another title", "profile-organization": "Another org", "profile-country": "us", "profile-format": "html", } response = self.client.post(url, new_attrs, follow=True) doc = pq(response.content) eq_(1, doc.find("#profile-head").length) eq_(new_attrs["profile-fullname"], doc.find("#profile-head .fn").text()) eq_(new_attrs["profile-title"], doc.find("#profile-head .profile-info .title").text()) eq_(new_attrs["profile-organization"], doc.find("#profile-head .profile-info .org").text()) profile = UserProfile.objects.get(user__username=profile.user.username) eq_(new_attrs["profile-fullname"], profile.fullname) eq_(new_attrs["profile-title"], profile.title) eq_(new_attrs["profile-organization"], profile.organization)
def test_profile_edit_interests(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True testuser = self.user_model.objects.get(username="******") self.client.login(username=testuser.username, password=TESTUSER_PASSWORD) url = reverse("users.profile_edit", args=(testuser.username,)) response = self.client.get(url, follow=True) doc = pq(response.content) test_tags = ["javascript", "css", "canvas", "html", "homebrewing"] form = self._get_current_form_field_values(doc) form["profile-interests"] = ", ".join(test_tags) response = self.client.post(url, form, follow=True) doc = pq(response.content) eq_(1, doc.find("#profile-head").length) profile = UserProfile.objects.get(user=testuser) result_tags = [t.name.replace("profile:interest:", "") for t in profile.tags.all_ns("profile:interest:")] result_tags.sort() test_tags.sort() eq_(test_tags, result_tags) test_expertise = ["css", "canvas"] form["profile-expertise"] = ", ".join(test_expertise) response = self.client.post(url, form, follow=True) doc = pq(response.content) eq_(1, doc.find("#profile-head").length) profile = UserProfile.objects.get(user=testuser) result_tags = [t.name.replace("profile:expertise:", "") for t in profile.tags.all_ns("profile:expertise")] result_tags.sort() test_expertise.sort() eq_(test_expertise, result_tags) # Now, try some expertise tags not covered in interests test_expertise = ["css", "canvas", "mobile", "movies"] form["profile-expertise"] = ", ".join(test_expertise) response = self.client.post(url, form, follow=True) doc = pq(response.content) eq_(1, doc.find(".error #id_profile-expertise").length)
def test_bug_698126_l10n(self, unsubscribe, subscribe, lookup_user): """Test that the form field names are localized""" lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True testuser = User.objects.get(username='******') self.client.login(username=testuser.username, password=TESTUSER_PASSWORD) url = reverse('users.profile_edit', args=(testuser.username, )) r = self.client.get(url, follow=True) for field in r.context['profile_form'].fields: # if label is localized it's a lazy proxy object ok_( not isinstance(r.context['profile_form'].fields[field].label, basestring), 'Field %s is a string!' % field)
def test_bug_698126_l10n(self, unsubscribe, subscribe, lookup_user): """Test that the form field names are localized""" lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True testuser = self.user_model.objects.get(username="******") self.client.login(username=testuser.username, password=TESTUSER_PASSWORD) url = reverse("users.profile_edit", args=(testuser.username,)) response = self.client.get(url, follow=True) for field in response.context["profile_form"].fields: # if label is localized it's a lazy proxy object ok_( not isinstance(response.context["profile_form"].fields[field].label, basestring), "Field %s is a string!" % field, )
def test_profile_edit_beta(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True testuser = self.user_model.objects.get(username="******") self.client.login(username=testuser.username, password=TESTUSER_PASSWORD) url = reverse("users.profile_edit", args=(testuser.username,)) response = self.client.get(url, follow=True) doc = pq(response.content) eq_(None, doc.find("input#id_profile-beta").attr("checked")) form = self._get_current_form_field_values(doc) form["profile-beta"] = True self.client.post(url, form, follow=True) url = reverse("users.profile_edit", args=(testuser.username,)) response = self.client.get(url, follow=True) doc = pq(response.content) eq_("checked", doc.find("input#id_profile-beta").attr("checked"))
def test_profile_edit_beta(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True testuser = User.objects.get(username='******') self.client.login(username=testuser.username, password=TESTUSER_PASSWORD) url = reverse('users.profile_edit', args=(testuser.username, )) r = self.client.get(url, follow=True) doc = pq(r.content) eq_(None, doc.find('input#id_profile-beta').attr('checked')) form = self._get_current_form_field_values(doc) form['profile-beta'] = True r = self.client.post(url, form, follow=True) url = reverse('users.profile_edit', args=(testuser.username, )) r = self.client.get(url, follow=True) doc = pq(r.content) eq_('checked', doc.find('input#id_profile-beta').attr('checked'))
def test_user_edit_beta(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True testuser = self.user_model.objects.get(username='******') self.client.login(username=testuser.username, password=TESTUSER_PASSWORD) url = reverse('users.user_edit', args=(testuser.username,)) response = self.client.get(url, follow=True) doc = pq(response.content) eq_(None, doc.find('input#id_user-beta').attr('checked')) form = self._get_current_form_field_values(doc) form['user-beta'] = True self.client.post(url, form, follow=True) url = reverse('users.user_edit', args=(testuser.username,)) response = self.client.get(url, follow=True) doc = pq(response.content) eq_('checked', doc.find('input#id_user-beta').attr('checked'))
def test_user_edit_websites(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True testuser = self.user_model.objects.get(username='******') self.client.login(username=testuser.username, password=TESTUSER_PASSWORD) url = reverse('users.user_edit', args=(testuser.username,)) response = self.client.get(url, follow=True) doc = pq(response.content) test_sites = { 'website': 'http://example.com/', 'twitter': 'http://twitter.com/lmorchard', 'github': 'http://github.com/lmorchard', 'stackoverflow': 'http://stackoverflow.com/users/lmorchard', 'linkedin': 'https://www.linkedin.com/in/testuser', 'mozillians': 'https://mozillians.org/u/testuser', 'facebook': 'https://www.facebook.com/test.user' } form = self._get_current_form_field_values(doc) # Fill out the form with websites. form.update(dict(('user-%s_url' % k, v) for k, v in test_sites.items())) # Submit the form, verify redirect to user detail response = self.client.post(url, form, follow=True) doc = pq(response.content) eq_(1, doc.find('#user-head').length) testuser = self.user_model.objects.get(pk=testuser.pk) # Verify the websites are saved in the user. for site, url in test_sites.items(): url_attr_name = '%s_url' % site eq_(getattr(testuser, url_attr_name), url) # Verify the saved websites appear in the editing form url = reverse('users.user_edit', args=(testuser.username,)) response = self.client.get(url, follow=True) doc = pq(response.content) for k, v in test_sites.items(): eq_(v, doc.find('#user-edit *[name="user-%s_url"]' % k).val()) # Come up with some bad sites, either invalid URL or bad URL prefix bad_sites = { 'website': 'HAHAHA WHAT IS A WEBSITE', 'twitter': 'http://facebook.com/lmorchard', 'stackoverflow': 'http://overqueueblah.com/users/lmorchard', } form.update(dict(('user-%s_url' % k, v) for k, v in bad_sites.items())) # Submit the form, verify errors for all of the bad sites response = self.client.post(url, form, follow=True) doc = pq(response.content) eq_(1, doc.find('#user-edit').length) tmpl = '#user-edit #users .%s .errorlist' for n in ('website', 'twitter', 'stackoverflow'): eq_(1, doc.find(tmpl % n).length)
def test_profile_edit_websites(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True testuser = User.objects.get(username='******') self.client.login(username=testuser.username, password=TESTUSER_PASSWORD) url = reverse('users.profile_edit', args=(testuser.username, )) r = self.client.get(url, follow=True) doc = pq(r.content) test_sites = { u'website': u'http://example.com/', u'twitter': u'http://twitter.com/lmorchard', u'github': u'http://github.com/lmorchard', u'stackoverflow': u'http://stackoverflow.com/users/lmorchard', u'linkedin': u'https://www.linkedin.com/in/testuser', u'mozillians': u'https://mozillians.org/u/testuser', u'facebook': u'https://www.facebook.com/test.user' } form = self._get_current_form_field_values(doc) # Fill out the form with websites. form.update( dict( ('profile-websites_%s' % k, v) for k, v in test_sites.items())) # Submit the form, verify redirect to profile detail r = self.client.post(url, form, follow=True) doc = pq(r.content) eq_(1, doc.find('#profile-head').length) profile = UserProfile.objects.get(user=testuser) # Verify the websites are saved in the profile. eq_(test_sites, profile.websites) # Verify the saved websites appear in the editing form url = reverse('users.profile_edit', args=(testuser.username, )) r = self.client.get(url, follow=True) doc = pq(r.content) for k, v in test_sites.items(): eq_( v, doc.find('#profile-edit *[name="profile-websites_%s"]' % k).val()) # Come up with some bad sites, either invalid URL or bad URL prefix bad_sites = { u'website': u'HAHAHA WHAT IS A WEBSITE', u'twitter': u'http://facebook.com/lmorchard', u'stackoverflow': u'http://overqueueblah.com/users/lmorchard', } form.update( dict(('profile-websites_%s' % k, v) for k, v in bad_sites.items())) # Submit the form, verify errors for all of the bad sites r = self.client.post(url, form, follow=True) doc = pq(r.content) eq_(1, doc.find('#profile-edit').length) tmpl = '#profile-edit #profiles .%s .errorlist' for n in ('website', 'twitter', 'stackoverflow'): eq_(1, doc.find(tmpl % n).length)
def test_user_edit_websites(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True testuser = self.user_model.objects.get(username='******') self.client.login(username=testuser.username, password=TESTUSER_PASSWORD) url = reverse('users.user_edit', args=(testuser.username, )) response = self.client.get(url, follow=True) doc = pq(response.content) test_sites = { 'website': 'http://example.com/', 'twitter': 'http://twitter.com/lmorchard', 'github': 'http://github.com/lmorchard', 'stackoverflow': 'http://stackoverflow.com/users/lmorchard', 'linkedin': 'https://www.linkedin.com/in/testuser', 'mozillians': 'https://mozillians.org/u/testuser', 'facebook': 'https://www.facebook.com/test.user' } form = self._get_current_form_field_values(doc) # Fill out the form with websites. form.update(dict( ('user-%s_url' % k, v) for k, v in test_sites.items())) # Submit the form, verify redirect to user detail response = self.client.post(url, form, follow=True) doc = pq(response.content) eq_(1, doc.find('#user-head').length) testuser = self.user_model.objects.get(pk=testuser.pk) # Verify the websites are saved in the user. for site, url in test_sites.items(): url_attr_name = '%s_url' % site eq_(getattr(testuser, url_attr_name), url) # Verify the saved websites appear in the editing form url = reverse('users.user_edit', args=(testuser.username, )) response = self.client.get(url, follow=True) doc = pq(response.content) for k, v in test_sites.items(): eq_(v, doc.find('#user-edit *[name="user-%s_url"]' % k).val()) # Come up with some bad sites, either invalid URL or bad URL prefix bad_sites = { 'website': 'HAHAHA WHAT IS A WEBSITE', 'twitter': 'http://facebook.com/lmorchard', 'stackoverflow': 'http://overqueueblah.com/users/lmorchard', } form.update(dict(('user-%s_url' % k, v) for k, v in bad_sites.items())) # Submit the form, verify errors for all of the bad sites response = self.client.post(url, form, follow=True) doc = pq(response.content) eq_(1, doc.find('#user-edit').length) tmpl = '#user-edit #users .%s .errorlist' for n in ('website', 'twitter', 'stackoverflow'): eq_(1, doc.find(tmpl % n).length)
def test_profile_edit_websites(self, unsubscribe, subscribe, lookup_user): lookup_user.return_value = mock_lookup_user() subscribe.return_value = True unsubscribe.return_value = True testuser = User.objects.get(username='******') self.client.login(username=testuser.username, password=TESTUSER_PASSWORD) url = reverse('users.profile_edit', args=(testuser.username,)) r = self.client.get(url, follow=True) doc = pq(r.content) test_sites = { u'website': u'http://example.com/', u'twitter': u'http://twitter.com/lmorchard', u'github': u'http://github.com/lmorchard', u'stackoverflow': u'http://stackoverflow.com/users/lmorchard', u'linkedin': u'https://www.linkedin.com/in/testuser', u'mozillians': u'https://mozillians.org/u/testuser', u'facebook': u'https://www.facebook.com/test.user' } form = self._get_current_form_field_values(doc) # Fill out the form with websites. form.update(dict(('profile-websites_%s' % k, v) for k, v in test_sites.items())) # Submit the form, verify redirect to profile detail r = self.client.post(url, form, follow=True) doc = pq(r.content) eq_(1, doc.find('#profile-head').length) profile = UserProfile.objects.get(user=testuser) # Verify the websites are saved in the profile. eq_(test_sites, profile.websites) # Verify the saved websites appear in the editing form url = reverse('users.profile_edit', args=(testuser.username,)) r = self.client.get(url, follow=True) doc = pq(r.content) for k, v in test_sites.items(): eq_(v, doc.find('#profile-edit *[name="profile-websites_%s"]' % k).val()) # Come up with some bad sites, either invalid URL or bad URL prefix bad_sites = { u'website': u'HAHAHA WHAT IS A WEBSITE', u'twitter': u'http://facebook.com/lmorchard', u'stackoverflow': u'http://overqueueblah.com/users/lmorchard', } form.update(dict(('profile-websites_%s' % k, v) for k, v in bad_sites.items())) # Submit the form, verify errors for all of the bad sites r = self.client.post(url, form, follow=True) doc = pq(r.content) eq_(1, doc.find('#profile-edit').length) tmpl = '#profile-edit #profiles .%s .errorlist' for n in ('website', 'twitter', 'stackoverflow'): eq_(1, doc.find(tmpl % n).length)