Mercurial > public > sg101
changeset 1219:f354554afb6e modernize tip
Add more bio unit tests.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 22 Feb 2025 17:17:09 -0600 |
parents | 54a26351c74b |
children | |
files | bio/tests/test_badges.py bio/tests/test_flags.py bio/tests/test_views.py requirements.txt |
diffstat | 4 files changed, 137 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bio/tests/test_badges.py Sat Feb 22 17:17:09 2025 -0600 @@ -0,0 +1,35 @@ +""" +Unit tests for the bio application badge utilities. + +""" +from django.test import TestCase +from django.contrib.auth.models import User + +from bio.badges import award_badge, NEWS_PIN +from bio.models import Badge, BadgeOwnership + + +class AwardBadgeTestCase(TestCase): + fixtures = ['badges.json'] + + def setUp(self): + self.user = User.objects.create_user('user', 'user@example.com', 'pw') + + def test_unknown_badge(self): + award_badge(4096, self.user) + self.assertEqual(BadgeOwnership.objects.count(), 0) + + def test_user_has_the_badge(self): + badge = Badge.objects.get(numeric_id=NEWS_PIN) + bo = BadgeOwnership(profile=self.user.profile, badge=badge, count=7) + bo.save() + + award_badge(badge.numeric_id, self.user) + bo = BadgeOwnership.objects.get(profile=self.user.profile, badge=badge) + self.assertEqual(bo.count, 8) + + def test_user_does_not_have_the_badge(self): + badge = Badge.objects.get(numeric_id=NEWS_PIN) + award_badge(badge.numeric_id, self.user) + bo = BadgeOwnership.objects.get(profile=self.user.profile, badge=badge) + self.assertEqual(bo.count, 1)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bio/tests/test_flags.py Sat Feb 22 17:17:09 2025 -0600 @@ -0,0 +1,16 @@ +""" +Unit tests for the bio flag utility. + +""" +from django.test import TestCase + + +class FlagsTestCase(TestCase): + def test_flag_loading(self): + import bio.flags + + # Just make sure we have data and didn't blow up. + self.assertNotEqual(len(bio.flags.FLAG_DATA), 0) + self.assertNotEqual(len(bio.flags.FLAG_CHOICES), 0) + self.assertEqual(len(bio.flags.FLAG_DATA), len(bio.flags.FLAG_CHOICES)) +
--- a/bio/tests/test_views.py Sat Feb 22 17:16:40 2025 -0600 +++ b/bio/tests/test_views.py Sat Feb 22 17:17:09 2025 -0600 @@ -14,6 +14,9 @@ from bio.models import UserProfile, UserProfileFlag +from elsewhere.models import (SocialNetworkProfile, InstantMessengerProfile, + WebsiteProfile) + class MemberSearchTest(TestCase): @@ -258,3 +261,85 @@ self.assertEqual(len(mail.outbox), 1) self.assertTrue('A Profile Has Been Flagged' in mail.outbox[0].subject) + + +class EditElsewhereTestCase(TestCase): + def setUp(self): + self.user = User.objects.create_user('paul', '', 'pw') + self.user.save() + self.client.login(username='paul', password='pw') + self.url = reverse('bio-edit_elsewhere') + + def test_get_view(self): + response = self.client.get(reverse('bio-edit_elsewhere')) + self.assertEqual(response.status_code, 200) + + def test_add_social_network(self): + response = self.client.post(self.url, { + 'network_id': 'catster', + 'username': 'pjmoto', + 'sn-form': 'Add Social Network', + }) + self.assertRedirects(response, self.url) + user_networks = self.user.social_network_profiles.all() + self.assertEquals(user_networks.count(), 1) + self.assertEquals(user_networks[0].network_id, 'catster') + + def test_add_instant_messenger(self): + response = self.client.post(self.url, { + 'network_id': 'aim', + 'username': 'pjmoto', + 'im-form': 'Add Instant Messenger', + }) + self.assertRedirects(response, self.url) + user_networks = self.user.instant_messenger_profiles.all() + self.assertEquals(user_networks.count(), 1) + self.assertEquals(user_networks[0].network_id, 'aim') + + def test_add_website(self): + response = self.client.post(self.url, { + 'name': 'pjmoto.com', + 'url': 'https://example.com/pjmoto', + 'w-form': 'Add Website', + }) + self.assertRedirects(response, self.url) + websites = self.user.website_profiles.all() + self.assertEquals(websites.count(), 1) + self.assertEquals(websites[0].name, 'pjmoto.com') + self.assertEquals(websites[0].url, 'https://example.com/pjmoto') + + def test_delete_social_network(self): + profile = SocialNetworkProfile(user=self.user, network_id='catster', + username='pjmoto') + profile.save() + self.assertEquals(self.user.social_network_profiles.count(), 1) + response = self.client.post(self.url, { + 'delete_id': profile.id, + 'delete-sn-form': 'Delete', + }) + self.assertRedirects(response, self.url) + self.assertEquals(self.user.social_network_profiles.count(), 0) + + def test_delete_instant_messenger(self): + profile = InstantMessengerProfile(user=self.user, network_id='aim', + username='pjmoto') + profile.save() + self.assertEquals(self.user.instant_messenger_profiles.count(), 1) + response = self.client.post(self.url, { + 'delete_id': profile.id, + 'delete-im-form': 'Delete', + }) + self.assertRedirects(response, self.url) + self.assertEquals(self.user.instant_messenger_profiles.count(), 0) + + def test_delete_website(self): + profile = WebsiteProfile(user=self.user, name='pjmoto.com', + url='https://example.com/pjmoto') + profile.save() + self.assertEquals(self.user.website_profiles.count(), 1) + response = self.client.post(self.url, { + 'delete_id': profile.id, + 'delete-w-form': 'Delete', + }) + self.assertRedirects(response, self.url) + self.assertEquals(self.user.website_profiles.count(), 0)
--- a/requirements.txt Sat Feb 22 17:16:40 2025 -0600 +++ b/requirements.txt Sat Feb 22 17:17:09 2025 -0600 @@ -32,6 +32,6 @@ simplejson==3.6.5 six==1.8.0 uritemplate==0.6 --e git+https://github.com/gremmie/django-elsewhere.git@42503b48cb770cca77c2757d26a6bee9bc10c9da#egg=django_elsewhere +-e git+https://github.com/gremmie/django-elsewhere.git@c8c6f5e60b4b36c79bf544e654a88b9e4345142b#egg=django_elsewhere -e hg+ssh://brian@bobcat//svr/dvcs/hg/repos/public/queues@862e8846f7e5f5a0df7f08bfe4b4e5283acb4614#egg=queues -e git+https://github.com/notanumber/xapian-haystack.git@a3a3a4e7cfba3e2e1be3a42abf59edd29ea03c05#egg=xapian_haystack