def test_autovouch_email(self): """Users with emails in AUTO_VOUCH_DOMAINS should be vouched.""" auto_user = user(email="*****@*****.**") auto_profile = auto_user.get_profile() auto_profile.save() assert auto_profile.is_vouched, "Profile should be vouched." assert auto_profile.vouched_by is None, "Profile should not have a voucher." non_auto_user = user() non_auto_profile = non_auto_user.get_profile() non_auto_profile.save() assert not non_auto_profile.is_vouched, "Profile should not be vouched."
def test_autovouch_email(self): """Users with emails in AUTO_VOUCH_DOMAINS should be vouched.""" auto_user = user(email='*****@*****.**') auto_profile = auto_user.get_profile() auto_profile.save() assert auto_profile.is_vouched, 'Profile should be vouched.' assert auto_profile.vouched_by is None, ( 'Profile should not have a voucher.') non_auto_user = user() non_auto_profile = non_auto_user.get_profile() non_auto_profile.save() assert not non_auto_profile.is_vouched, ( 'Profile should not be vouched.')
def test_invalid_country(self): """Not every country is a real country.""" u = user() self.client.login(email=u.email, password="******") data = {"country": "xyz", "last_name": "Foobar"} response = self.client.post(reverse("profile.edit"), data) eq_(400, response.status_code)
def test_invalid_country(self): """Not every country is a real country.""" u = user() self.client.login(email=u.email, password='******') data = {'country': 'xyz', 'last_name': 'Foobar'} response = self.client.post(reverse('profile.edit'), data) eq_(400, response.status_code)
def setUp(self): """Setup API Testing.""" # create an APP self.auto_user = user() up = self.auto_user.userprofile up.set_membership(Group, 'nice guy') up.set_membership(Skill, 'python') up.set_membership(Language, 'Greek') up.ircname = 'foobar' up.country = 'gr' up.region = 'Attika' up.city = 'Athens' up.save() self.auto_user.first_name = 'Foo' self.auto_user.last_name = 'Bar' self.auto_user.save() self.app = APIApp.objects.create(name='test_app', description='Foo', owner=self.mozillian, is_mozilla_app=False, is_active=False) index_all_profiles() get_es().flush(refresh=True)
def test_has_country(self): u = user(username='******') p = u.get_profile() p.country = 'us' p.save() assert self.client.login(email=u.email) r = self.client.get(reverse('profile', args=[u.username]), follow=True) self.assertContains(r, '<dt>Location</dt>')
def test_non_vouched_api_key(self): """Assert that non-vouched users don't have an API key.""" u = user(email='*****@*****.**', is_vouched=False) assert self.client.login(email=u.email) r = self.client.get(reverse('profile.edit'), follow=True) eq_(200, r.status_code) doc = pq(r.content) eq_(0, len(doc('#api-key')))
def test_username_redirection_middleware(self): """Test the username redirection middleware.""" auto_user = user(username='******') self.client.login(username=auto_user.username, password='******') response = self.client.get('/%s' % auto_user.username, follow=True) self.assertTemplateUsed(response, 'phonebook/profile.html') response = self.client.get('/%s' % 'invaliduser', follow=True) self.assertTemplateUsed(response, '404.html')
def test_username_redirection_middleware(self): """Test the username redirection middleware.""" auto_user = user(username="******") self.client.login(username=auto_user.username, password="******") response = self.client.get("/%s" % auto_user.username, follow=True) self.assertTemplateUsed(response, "phonebook/profile.html") response = self.client.get("/%s" % "invaliduser", follow=True) self.assertTemplateUsed(response, "404.html")
def test_only_autovouch_in_staff(self): """Restrict the staff group to emails in AUTO_VOUCH_DOMAINS.""" staff = Group.objects.get_or_create(name="staff", system=True)[0] staff_user = user(email="*****@*****.**") staff_profile = staff_user.get_profile() staff_profile.save() assert staff in staff_profile.groups.all(), "Auto-vouched email in staff group by default." staff_profile.groups.remove(staff) staff_profile.save() assert staff in staff_profile.groups.all(), "Auto-vouched email cannot be removed from staff group." community_user = user() community_profile = community_user.get_profile() community_profile.save() assert staff not in community_profile.groups.all(), "Non-auto-vouched email not automatically in staff group." community_profile.groups.add(staff) community_profile.save() assert staff not in community_profile.groups.all(), "Non-auto-vouched email cannot be added to staff group."
def test_api_key(self): """Assert that the Api key will be created and displayed.""" u = user(email='*****@*****.**') assert self.client.login(email=u.email) r = self.client.get(reverse('profile.edit'), follow=True) eq_(200, r.status_code) doc = pq(r.content) api_key = doc('#api-key').attr('value') p = u.get_profile() assert p.get_api_key() == api_key
def setUp(self): self.data = {'country': 'us', 'region': 'California', 'city': 'Mountain View', 'ircname': 'hax0r', 'bio': 'I love ice cream. I code. I tweet.', 'full_name': 'Nikos Koukos'} self.auto_user = user() self.up = self.auto_user.userprofile for key, value in self.data.iteritems(): setattr(self.up, key, value) self.up.save()
def test_api_key(self): """Assert that the Api key will be created and displayed""" u = user(email='*****@*****.**') assert self.client.login(email=u.email) r = self.client.get(reverse('profile.edit'), follow=True) eq_(200, r.status_code) doc = pq(r.content) api_key = doc('#api-key').attr('value') p = u.get_profile() assert p.get_api_key() == api_key
def test_apikey(self): """Test that get_api_key() will create a key if missing.""" # A new user will not have a key created. u = user() p = u.get_profile() from tastypie.models import ApiKey # A new key is not generated automatically on a user. self.assertRaises(ApiKey.DoesNotExist, lambda: u.api_key) # get_api_key will always return a key, creating one if needed. eq_(p.get_api_key(), u.api_key.key)
def test_username_filled_in(self): """The username field should have a type and value.""" newbie = user(username='******', email='*****@*****.**') url = reverse('profile.edit') assert self.client.login(email=newbie.email) response = self.client.get(url, follow=True) eq_(200, response.status_code) doc = pq(response.content) field = doc('#id_username')[0] eq_('input', field.tag) assert 'value' in field.attrib eq_('text', field.attrib['type']) eq_(newbie.username, field.attrib['value'])
def setUp(self): self.data = {'country': 'us', 'region': 'California', 'city': 'Mountain View', 'ircname': 'hax0r', 'bio': 'I love ice cream. I code. I tweet.', 'website': 'http://www.example.com'} self.auto_user = user() self.auto_user.first_name = 'Nikos' self.auto_user.last_name = 'Koukos' self.auto_user.save() up = self.auto_user.userprofile for key, value in self.data.iteritems(): setattr(up, key, value) up.save()
def test_only_autovouch_in_staff(self): """Restrict the staff group to emails in AUTO_VOUCH_DOMAINS.""" staff = Group.objects.get_or_create(name='staff', system=True)[0] staff_user = user(email='*****@*****.**') staff_profile = staff_user.get_profile() staff_profile.save() assert staff in staff_profile.groups.all(), ( 'Auto-vouched email in staff group by default.') staff_profile.groups.remove(staff) staff_profile.save() assert staff in staff_profile.groups.all(), ( 'Auto-vouched email cannot be removed from staff group.') community_user = user() community_profile = community_user.get_profile() community_profile.save() assert staff not in community_profile.groups.all(), ( 'Non-auto-vouched email not automatically in staff group.') community_profile.groups.add(staff) community_profile.save() assert staff not in community_profile.groups.all(), ( 'Non-auto-vouched email cannot be added to staff group.')
def test_reset_api_key(self): """Assert that resetingthe aPI key changes it.""" u = user(email='*****@*****.**') assert self.client.login(email=u.email) r = self.client.get(reverse('profile.edit'), follow=True) eq_(200, r.status_code) doc = pq(r.content) original_api_key = doc('#api-key').attr('value') data = {'reset_api_key': True} r = self.client.post(reverse('profile.edit'), data, follow=True) doc = pq(r.content) new_api_key = doc('#api-key').attr('value') assert original_api_key != new_api_key
def test_reset_api_key(self): """Assert that resetting the API key changes it.""" u = user(email='*****@*****.**') assert self.client.login(email=u.email) r = self.client.get(reverse('profile.edit'), follow=True) eq_(200, r.status_code) doc = pq(r.content) original_api_key = doc('#api-key').attr('value') data = {'reset_api_key': True} r = self.client.post(reverse('profile.edit'), data, follow=True) doc = pq(r.content) new_api_key = doc('#api-key').attr('value') assert original_api_key != new_api_key
def test_userprofile(self): u = user() UserProfile.objects.all().delete() # Somehow the User lacks a UserProfile # Note that u.get_profile() caches in memory. self.assertRaises(UserProfile.DoesNotExist, lambda: u.userprofile) # Sign in with browserid_mock.mock_browserid(u.email): d = dict(assertion='qwer') self.client.post(reverse('browserid_verify'), d, follow=True) # Good to go assert u.get_profile()
def test_userprofile(self): u = user() UserProfile.objects.all().delete() # Somehow the User lacks a UserProfile # Note that u.get_profile() caches in memory. self.assertRaises(UserProfile.DoesNotExist, lambda: u.userprofile) # Sign in with browserid_mock.mock_browserid(u.email): d = dict(assertion="qwer") self.client.post(reverse("browserid_verify"), d, follow=True) # Good to go assert u.get_profile()
def setUp(self): self.data = { 'country': 'us', 'region': 'California', 'city': 'Mountain View', 'ircname': 'hax0r', 'bio': 'I love ice cream. I code. I tweet.', 'website': 'http://www.example.com' } self.auto_user = user() self.auto_user.first_name = 'Nikos' self.auto_user.last_name = 'Koukos' self.auto_user.save() up = self.auto_user.userprofile for key, value in self.data.iteritems(): setattr(up, key, value) up.save()
def test_geographic_fields_increasing(self): """Geographic fields exist and require increasing specificity.""" u = user() self.client.login(email=u.email, password="******") # For some reason last_name is a required field. data = {"city": "New York", "last_name": "Foobar"} url = reverse("profile.edit") response = self.client.post(url, data) eq_(400, response.status_code) data.update({"region": "New York"}) response = self.client.post(url, data) eq_(400, response.status_code) data.update({"country": "us"}) response = self.client.post(url, data, follow=True) eq_(200, response.status_code)
def test_geographic_fields_increasing(self): """Geographic fields exist and require increasing specificity.""" u = user() self.client.login(email=u.email, password='******') # For some reason last_name is a required field. data = {'city': 'New York', 'last_name': 'Foobar'} url = reverse('profile.edit') response = self.client.post(url, data) eq_(400, response.status_code) data.update({'region': 'New York'}) response = self.client.post(url, data) eq_(400, response.status_code) data.update({'country': 'United States'}) response = self.client.post(url, data, follow=True) eq_(200, response.status_code)
def test_geographic_fields_increasing(self): """Geographic fields exist and require increasing specificity.""" u = user() self.client.login(email=u.email, password='******') # For some reason last_name is a required field. data = {'city': 'New York', 'last_name': 'Foobar'} url = reverse('profile.edit') response = self.client.post(url, data) eq_(400, response.status_code) data.update({'region': 'New York'}) response = self.client.post(url, data) eq_(400, response.status_code) data.update({'country': 'us'}) response = self.client.post(url, data, follow=True) eq_(200, response.status_code)
def setUp(self): self.data = { "country": "United States", "region": "California", "city": "Mountain View", "ircname": "hax0r", "bio": "I love ice cream. I code. I tweet.", "website": "http://www.example.com", } self.auto_user = user() self.auto_user.first_name = "Nikos" self.auto_user.last_name = "Koukos" self.auto_user.save() up = self.auto_user.userprofile for key, value in self.data.iteritems(): setattr(up, key, value) up.save()