def test_success(self): user = UserProfile.objects.get(email="*****@*****.**") self.client.login(username=user.email, password="******") r = self.client.get("/", follow=True) eq_(pq(r.content.decode("utf-8"))(".account .user").text(), user.display_name) eq_(pq(r.content)(".account .user").attr("title"), user.email) r = self.client.get("/users/logout", follow=True) assert not pq(r.content)(".account .user")
def test_success(self): user = UserProfile.objects.get(email='*****@*****.**') self.client.login(username=user.email, password='******') r = self.client.get('/', follow=True) eq_(pq(r.content.decode('utf-8'))('.account .user').text(), user.display_name) eq_(pq(r.content)('.account .user').attr('title'), user.email) r = self.client.get('/users/logout', follow=True) assert not pq(r.content)('.account .user')
def test_legacy_confirm(self): # User doesn't have a valid confirmation code. url = reverse("users.confirm", args=[self.user.id, "blah"]) r = self.client.get(url, follow=True) # Ensure we don't show django messages for registrations via Remora. eq_(pq(r.content)(".notification-box").length, 0) self.user_profile.update(confirmationcode="code") url = reverse("users.confirm", args=[self.user.id, "code"]) r = self.client.get(url, follow=True) eq_(pq(r.content)(".notification-box").length, 0)
def test_success(self): res = self.client.get('/developers/', follow=True) data = pq(res.content.decode('utf-8'))('body').attr('data-user') data = json.loads(data) eq_(data['email'], self.user.email) eq_(data['anonymous'], False) res = self.client.get(reverse('users.logout'), follow=True) data = pq(res.content.decode('utf-8'))('body').attr('data-user') data = json.loads(data) eq_(data['email'], '') eq_(data['anonymous'], True)
def test_my_personas(self): eq_(pq(self.client.get(self.url).content)(".num-addons a").length, 0) a = amo.tests.addon_factory(type=amo.ADDON_PERSONA) AddonUser.objects.create(user=self.user, addon=a) r = self.client.get(self.url) doc = pq(r.content) items = doc("#my-themes .persona") eq_(items.length, 1) eq_(items('a[href="%s"]' % a.get_url_path()).length, 1)
def test_my_personas(self): eq_(pq(self.client.get(self.url).content)('.num-addons a').length, 0) a = amo.tests.addon_factory(type=amo.ADDON_PERSONA) AddonUser.objects.create(user=self.user, addon=a) r = self.client.get(self.url) doc = pq(r.content) items = doc('#my-themes .persona') eq_(items.length, 1) eq_(items('a[href="%s"]' % a.get_url_path()).length, 1)
def test_loggedout_purchased(self): # "Buy" the add-on self.addon.addonpurchase_set.create(user=self.user.get_profile()) # Make sure we get a log in field r = self.client.get_ajax(self.url) eq_(r.status_code, 200) assert pq(r.content).find('#id_username').length # Now, let's log in. res = self.client.post_ajax(self.url, data=self.data) eq_(res.status_code, 200) # Are we presented with a link to the download? assert pq(res.content).find('.trigger_download').length
def test_loggedout_notpurchased(self): # We don't want any purchases. AddonPurchase.objects.all().delete() # Make sure we're presented with a log in form. r = self.client.get_ajax(self.url) eq_(r.status_code, 200) assert pq(r.content).find('#id_username').length # Now, let's log in. res = self.client.post_ajax(self.url, data=self.data) eq_(res.status_code, 200) # Make sure we get a link to paypal assert pq(res.content).find('.paypal.button').length
def test_my_unlisted_addons(self): """I can't see my own unlisted addons on my profile page.""" eq_(pq(self.client.get(self.url).content)(".num-addons a").length, 0) AddonUser.objects.create(user=self.user, addon_id=3615) Addon.objects.get(pk=5299).update(is_listed=False) AddonUser.objects.create(user=self.user, addon_id=5299) r = self.client.get(self.url) assert list(r.context["addons"].object_list) == [Addon.objects.get(pk=3615)] doc = pq(r.content) items = doc("#my-addons .item") eq_(items.length, 1) eq_(items(".install[data-addon=3615]").length, 1)
def test_email_cant_change(self): data = {"username": "******", "email": "*****@*****.**", "display_name": "DJ SurfNTurf"} res = self.client.post(self.url, data, follow=True) eq_(res.status_code, 200) eq_(len(pq(res.content)("div.error")), 1) eq_(len(mail.outbox), 0)
def test_my_reviews_pagination(self): for i in xrange(20): AddonUser.objects.create(user=self.user, addon_id=3615) assert len(self.user.addons_listed) > 10, ( 'This user should have way more than 10 add-ons.') r = self.client.get(self.url) eq_(pq(r.content)('#my-addons .paginator').length, 1)
def test_no_self_abuse(self): self.client.login(username='******', password='******') r = self.client.get(self.url) doc = pq(r.content) eq_(doc('#profile-actions #report-user-abuse').length, 0) eq_(doc('#popup-staging #report-user-modal.modal').length, 0) self.assertTemplateNotUsed(r, 'users/report_abuse.html')
def test_mobile_login_apps_preview(self): r = self.client.get(self.url) eq_(r.status_code, 200) doc = pq(r.content)('header') eq_(doc('nav').length, 1) eq_(doc('#home').length, 0) eq_(doc('#auth-nav li.login').length, 0)
def test_no_my_collections(self): Collection.objects.filter(author=self.user).delete() r = self.client.get(self.url) self.assertTemplateNotUsed(r, 'bandwagon/users/collection_list.html') doc = pq(r.content) eq_(doc('#my-collections').length, 0) eq_(doc('#reviews.full').length, 1)
def test_correct_url_update_notification(self): # Make sure the user is subscribed perm_setting = email.NOTIFICATIONS[0] un = UserNotification.objects.create(notification_id=perm_setting.id, user=self.user_profile, enabled=True) # Create a URL token, hash = UnsubscribeCode.create(self.user.email) url = reverse('users.unsubscribe', args=[token, hash, perm_setting.short]) # Load the URL r = self.client.get(url) doc = pq(r.content) # Check that it was successful assert doc('#unsubscribe-success').length assert doc('#standalone').length eq_(doc('#standalone ul li').length, 1) # Make sure the user is unsubscribed un = UserNotification.objects.filter(notification_id=perm_setting.id, user=self.user) eq_(un.count(), 1) eq_(un.all()[0].enabled, False)
def test_my_addons(self): eq_(pq(self.client.get(self.url).content)(".num-addons a").length, 0) AddonUser.objects.create(user=self.user, addon_id=3615) AddonUser.objects.create(user=self.user, addon_id=5299) r = self.client.get(self.url) a = r.context["addons"].object_list eq_(list(a), sorted(a, key=lambda x: x.weekly_downloads, reverse=True)) doc = pq(r.content) eq_(doc('.num-addons a[href="#my-submissions"]').length, 1) items = doc("#my-addons .item") eq_(items.length, 2) eq_(items(".install[data-addon=3615]").length, 1) eq_(items(".install[data-addon=5299]").length, 1)
def test_collections_toggles(self): r = self.client.get(self.url) eq_(r.status_code, 200) doc = pq(r.content) eq_( doc('#profile-misc').length, 1, 'Collections options should be visible.')
def test_mobile_login(self): r = self.client.get(self.url) eq_(r.status_code, 200) doc = pq(r.content)("header") eq_(doc("nav").length, 1) eq_(doc("#home").length, 1) eq_(doc("#auth-nav li.login").length, 0)
def test_no_self_abuse(self): self.client.login(username="******", password="******") r = self.client.get(self.url) doc = pq(r.content) eq_(doc("#profile-actions #report-user-abuse").length, 0) eq_(doc("#popup-staging #report-user-modal.modal").length, 0) self.assertTemplateNotUsed(r, "users/report_abuse.html")
def test_my_addons(self): eq_(pq(self.client.get(self.url).content)('.num-addons a').length, 0) AddonUser.objects.create(user=self.user, addon_id=3615) AddonUser.objects.create(user=self.user, addon_id=5299) r = self.client.get(self.url) a = r.context['addons'].object_list eq_(list(a), sorted(a, key=lambda x: x.weekly_downloads, reverse=True)) doc = pq(r.content) eq_(doc('.num-addons a[href="#my-submissions"]').length, 1) items = doc('#my-addons .item') eq_(items.length, 2) eq_(items('.install[data-addon=3615]').length, 1) eq_(items('.install[data-addon=5299]').length, 1)
def test_no_my_collections(self): Collection.objects.filter(author=self.user).delete() r = self.client.get(self.url) self.assertTemplateNotUsed(r, "bandwagon/users/collection_list.html") doc = pq(r.content) eq_(doc("#my-collections").length, 0) eq_(doc("#reviews.full").length, 1)
def test_my_unlisted_addons(self): """I can't see my own unlisted addons on my profile page.""" eq_(pq(self.client.get(self.url).content)('.num-addons a').length, 0) AddonUser.objects.create(user=self.user, addon_id=3615) Addon.objects.get(pk=5299).update(is_listed=False) AddonUser.objects.create(user=self.user, addon_id=5299) r = self.client.get(self.url) assert list( r.context['addons'].object_list) == [Addon.objects.get(pk=3615)] doc = pq(r.content) items = doc('#my-addons .item') eq_(items.length, 1) eq_(items('.install[data-addon=3615]').length, 1)
def test_not_my_unlisted_addons(self): """I can't see others' unlisted addons on their profile pages.""" res = self.client.get("/user/999/", follow=True) eq_(pq(res.content)(".num-addons a").length, 0) user = UserProfile.objects.get(pk=999) AddonUser.objects.create(user=user, addon_id=3615) Addon.objects.get(pk=5299).update(is_listed=False) AddonUser.objects.create(user=user, addon_id=5299) r = self.client.get("/user/999/", follow=True) assert list(r.context["addons"].object_list) == [Addon.objects.get(pk=3615)] doc = pq(r.content) items = doc("#my-addons .item") eq_(items.length, 1) eq_(items(".install[data-addon=3615]").length, 1)
def test_my_last_login_authenticated(self): self.user.update(last_login_ip='255.255.255.255') self.login(self.user) res = self.client.get(self.url) eq_(res.status_code, 200) doc = pq(res.content) assert doc('.last-login-time td').text() eq_(doc('.last-login-ip td').text(), '255.255.255.255')
def test_my_last_login_authenticated(self): self.user.update(last_login_ip="255.255.255.255") self.login(self.user) res = self.client.get(self.url) eq_(res.status_code, 200) doc = pq(res.content) assert doc(".last-login-time td").text() eq_(doc(".last-login-ip td").text(), "255.255.255.255")
def test_email_cant_change(self): data = {'username': '******', 'email': '*****@*****.**', 'display_name': 'DJ SurfNTurf', } res = self.client.post(self.url, data, follow=True) eq_(res.status_code, 200) eq_(len(pq(res.content)('div.error')), 1) eq_(len(mail.outbox), 0)
def test_confirm_resend(self): # User doesn't have a confirmation code url = reverse('users.confirm.resend', args=[self.user.id]) r = self.client.get(url, follow=True) anon = pq(r.content)('body').attr('data-anonymous') self.assertTrue(anon) self.user_profile.confirmationcode = "code" self.user_profile.save()
def test_not_my_unlisted_addons(self): """I can't see others' unlisted addons on their profile pages.""" res = self.client.get('/user/999/', follow=True) eq_(pq(res.content)('.num-addons a').length, 0) user = UserProfile.objects.get(pk=999) AddonUser.objects.create(user=user, addon_id=3615) Addon.objects.get(pk=5299).update(is_listed=False) AddonUser.objects.create(user=user, addon_id=5299) r = self.client.get('/user/999/', follow=True) assert list( r.context['addons'].object_list) == [Addon.objects.get(pk=3615)] doc = pq(r.content) items = doc('#my-addons .item') eq_(items.length, 1) eq_(items('.install[data-addon=3615]').length, 1)
def test_loggedin_notpurchased(self): # No purchases; logged in. AddonPurchase.objects.all().delete() assert self.client.login(**self.data) r = self.client.get_ajax(self.url) eq_(r.status_code, 200) # Make sure we get a link to paypal. assert pq(r.content).find('.paypal.button').length
def test_wrong_url(self): perm_setting = email.NOTIFICATIONS[0] token, hash = UnsubscribeCode.create(self.user.email) hash = hash[::-1] # Reverse the hash, so it's wrong url = reverse("users.unsubscribe", args=[token, hash, perm_setting.short]) r = self.client.get(url) doc = pq(r.content) eq_(doc("#unsubscribe-fail").length, 1)
def test_abuse_logged_in(self): self.client.login(username="******", password="******") self.client.post(self.full_page, {"text": "spammy"}) eq_(len(mail.outbox), 1) assert "spammy" in mail.outbox[0].body report = AbuseReport.objects.get(user=10482) eq_(report.message, "spammy") eq_(report.reporter.email, "*****@*****.**") r = self.client.get(self.full_page) eq_(pq(r.content)(".notification-box h2").length, 1)
def test_wrong_url(self): perm_setting = email.NOTIFICATIONS[0] token, hash = UnsubscribeCode.create(self.user.email) hash = hash[::-1] # Reverse the hash, so it's wrong url = reverse('users.unsubscribe', args=[token, hash, perm_setting.short]) r = self.client.get(url) doc = pq(r.content) eq_(doc('#unsubscribe-fail').length, 1)
def test_abuse_logged_in(self): self.client.login(username='******', password='******') self.client.post(self.full_page, {'text': 'spammy'}) eq_(len(mail.outbox), 1) assert 'spammy' in mail.outbox[0].body report = AbuseReport.objects.get(user=10482) eq_(report.message, 'spammy') eq_(report.reporter.email, '*****@*****.**') r = self.client.get(self.full_page) eq_(pq(r.content)('.notification-box h2').length, 1)
def test_loggedin_purchased(self): # Log the user in assert self.client.login(**self.data) # "Buy" the add-on self.addon.addonpurchase_set.create(user=self.user.get_profile()) r = self.client.get_ajax(self.url) eq_(r.status_code, 200) # This only happens if we've bought it. assert pq(r.content).find('.trigger_download').length
def test_user_abuse_form(self): abuse_url = reverse('users.abuse', args=[self.user.id]) r = self.client.get(self.url) doc = pq(r.content) button = doc('#profile-actions #report-user-abuse') eq_(button.length, 1) eq_(button.attr('href'), abuse_url) modal = doc('#popup-staging #report-user-modal.modal') eq_(modal.length, 1) eq_(modal('form').attr('action'), abuse_url) eq_(modal('textarea[name=text]').length, 1) self.assertTemplateUsed(r, 'users/report_abuse.html')
def _test_good(self, res): eq_(res.status_code, 200) ids = res.context['addons'].object_list.values_list('id', flat=True) self.assertSetEqual(ids, [self.theme.id]) doc = pq(res.content) eq_(doc('.no-results').length, 0) results = doc('.personas-grid .persona-preview') eq_(results.length, 1) eq_(results.find('h6').text(), unicode(self.theme.name))
def _test_good(self, res): eq_(res.status_code, 200) ids = res.context["addons"].object_list.values_list("id", flat=True) self.assertSetEqual(ids, [self.theme.id]) doc = pq(res.content) eq_(doc(".no-results").length, 0) results = doc(".personas-grid .persona-preview") eq_(results.length, 1) eq_(results.find("h6").text(), unicode(self.theme.name))
def test_user_abuse_form(self): abuse_url = reverse("users.abuse", args=[self.user.id]) r = self.client.get(self.url) doc = pq(r.content) button = doc("#profile-actions #report-user-abuse") eq_(button.length, 1) eq_(button.attr("href"), abuse_url) modal = doc("#popup-staging #report-user-modal.modal") eq_(modal.length, 1) eq_(modal("form").attr("action"), abuse_url) eq_(modal("textarea[name=text]").length, 1) self.assertTemplateUsed(r, "users/report_abuse.html")
def check_default_choices(self, choices, checked=True): doc = pq(self.client.get(self.url).content) eq_(doc("input[name=notifications]:checkbox").length, len(choices)) for id, label in choices: box = doc("input[name=notifications][value=%s]" % id) if checked: eq_(box.filter(":checked").length, 1) else: eq_(box.length, 1) parent = box.parent("label") if checked: eq_(parent.find(".msg").length, 1) # Check for "NEW" message. eq_(parent.remove(".msg, .req").text(), label)
def check_default_choices(self, choices, checked=True): doc = pq(self.client.get(self.url).content) eq_(doc('input[name=notifications]:checkbox').length, len(choices)) for id, label in choices: box = doc('input[name=notifications][value=%s]' % id) if checked: eq_(box.filter(':checked').length, 1) else: eq_(box.length, 1) parent = box.parent('label') if checked: eq_(parent.find('.msg').length, 1) # Check for "NEW" message. eq_(parent.remove('.msg, .req').text(), label)
def test_confirm_resend(self): # User doesn't have a confirmation code url = reverse('users.confirm.resend', args=[self.user.id]) r = self.client.get(url, follow=True) anon = pq(r.content)('body').attr('data-anonymous') self.assertTrue(anon) self.user_profile.confirmationcode = "code" self.user_profile.save() # URL has the wrong confirmation code url = reverse('users.confirm.resend', args=[self.user.id]) r = self.client.get(url, follow=True) self.assertContains(r, 'An email has been sent to your address')
def test_my_reviews(self): r = Review.objects.filter(reply_to=None)[0] r.update(user=self.user) cache.clear() self.assertSetEqual(self.user.reviews, [r]) r = self.client.get(self.url) doc = pq(r.content)('#reviews') assert not doc.hasClass('full'), ( 'reviews should not have "full" class when there are collections') eq_(doc('.item').length, 1) eq_(doc('#review-218207').length, 1) # Edit Review form should be present. self.assertTemplateUsed(r, 'reviews/edit_review.html')
def test_new_confirm(self): # User doesn't have a confirmation code. url = reverse('users.confirm', args=[self.user.id, 'code']) r = self.client.get(url, follow=True) is_anonymous = pq(r.content)('body').attr('data-anonymous') eq_(json.loads(is_anonymous), True) self.user_profile.update(confirmationcode='code') # URL has the wrong confirmation code. url = reverse('users.confirm', args=[self.user.id, 'blah']) r = self.client.get(url, follow=True) self.assertContains(r, 'Invalid confirmation code!') # URL has the right confirmation code. url = reverse('users.confirm', args=[self.user.id, 'code']) r = self.client.get(url, follow=True) self.assertContains(r, 'Successfully verified!')
def test_confirm(self): # User doesn't have a confirmation code url = reverse('users.confirm', args=[self.user.id, 'code']) r = self.client.get(url, follow=True) anon = pq(r.content)('body').attr('data-anonymous') self.assertTrue(anon) self.user_profile.confirmationcode = "code" self.user_profile.save() # URL has the wrong confirmation code url = reverse('users.confirm', args=[self.user.id, 'blah']) r = self.client.get(url, follow=True) self.assertContains(r, 'Invalid confirmation code!') # URL has the right confirmation code url = reverse('users.confirm', args=[self.user.id, 'code']) r = self.client.get(url, follow=True) self.assertContains(r, 'Successfully verified!')
def test_my_collections_created(self): coll = Collection.objects.listed().filter(author=self.user) eq_(len(coll), 1) r = self.client.get(self.url) self.assertTemplateUsed(r, 'bandwagon/users/collection_list.html') self.assertSetEqual(r.context['own_coll'], coll) doc = pq(r.content) eq_(doc('#reviews.full').length, 0) ul = doc('#my-collections #my-created') eq_(ul.length, 1) li = ul.find('li') eq_(li.length, 1) a = li.find('a') eq_(a.attr('href'), coll[0].get_url_path()) eq_(a.text(), unicode(coll[0].name))
def test_my_collections_followed(self): coll = Collection.objects.all()[0] CollectionWatcher.objects.create(collection=coll, user=self.user) mine = Collection.objects.listed().filter(following__user=self.user) eq_(list(mine), [coll]) r = self.client.get(self.url) self.assertTemplateUsed(r, 'bandwagon/users/collection_list.html') eq_(list(r.context['fav_coll']), [coll]) doc = pq(r.content) eq_(doc('#reviews.full').length, 0) ul = doc('#my-collections #my-favorite') eq_(ul.length, 1) li = ul.find('li') eq_(li.length, 1) a = li.find('a') eq_(a.attr('href'), coll.get_url_path()) eq_(a.text(), unicode(coll.name))
def test_edit_notifications(self): post = self.correct.copy() post['notifications'] = [2, 4, 6] # Make jbalogh a developer addon = Addon.objects.create(type=amo.ADDON_EXTENSION) AddonUser.objects.create(user=self.user, addon=addon) res = self.client.post(self.url, post) eq_(res.status_code, 302) mandatory = [n.id for n in email.NOTIFICATIONS if n.mandatory] total = len(post['notifications'] + mandatory) eq_(UserNotification.objects.count(), len(email.NOTIFICATION)) eq_(UserNotification.objects.filter(enabled=True).count(), total) res = self.client.get(self.url, post) doc = pq(res.content) eq_(doc('[name=notifications]:checked').length, total) eq_(doc('.more-none').length, len(email.NOTIFICATION_GROUPS)) eq_(doc('.more-all').length, len(email.NOTIFICATION_GROUPS))
def test_edit_notifications(self): # Make jbalogh a developer. AddonUser.objects.create(user=self.user, addon=Addon.objects.create(type=amo.ADDON_EXTENSION)) choices = email.NOTIFICATIONS_CHOICES self.check_default_choices(choices) self.data['notifications'] = [2, 4, 6] r = self.client.post(self.url, self.data) self.assertRedirects(r, self.url, 302) mandatory = [n.id for n in email.NOTIFICATIONS if n.mandatory] total = len(self.data['notifications'] + mandatory) eq_(UserNotification.objects.count(), len(email.NOTIFICATIONS)) eq_(UserNotification.objects.filter(enabled=True).count(), total) doc = pq(self.client.get(self.url, self.data).content) eq_(doc('input[name=notifications]:checked').length, total) eq_(doc('.more-none').length, len(email.NOTIFICATION_GROUPS)) eq_(doc('.more-all').length, len(email.NOTIFICATION_GROUPS))