def test_update_basket_task_without_token(self, basket_mock, lookup_token_mock, request_mock): lookup_token_mock.return_value = "basket_token" user = UserFactory.create(userprofile={'is_vouched': True, 'country': 'gr', 'city': 'athens'}) group = GroupFactory.create( name='Web Development', steward=user.userprofile) GroupFactory.create(name='Marketing', steward=user.userprofile) group.members.add(user.userprofile) data = {'country': 'gr', 'city': 'athens', 'WEB_DEVELOPMENT': 'Y', 'MARKETING': 'N'} basket_mock.subscribe.return_value = {} update_basket_task(user.userprofile.id) basket_mock.subscribe.assert_called_with( user.email, 'newsletter', trigger_welcome='N') request_mock.assert_called_with( 'post', 'custom_update_phonebook', token='basket_token', data=data) ok_(UserProfile.objects.filter( basket_token='basket_token', id=user.userprofile.id).exists())
def test_set_membership_group_matches_alias(self): group_1 = GroupFactory.create(name='foo') group_2 = GroupFactory.create(name='lo') GroupAliasFactory.create(alias=group_2, name='bar') user = UserFactory.create() user.userprofile.set_membership(Group, ['foo', 'bar']) eq_(set(user.userprofile.groups.all()), set([group_1, group_2]))
def test_group_edit(self): # Curator can edit a group and change (some of) its properties data = { "name": u"Test Group", "accepting_new_members": u"by_request", "description": u"lorem ipsum and lah-dee-dah", "irc_channel": u"some text, this is not validated", "website": u"http://mozillians.org", "wiki": u"http://wiki.mozillians.org", "members_can_leave": True, "visible": True, "functional_area": False, } group = GroupFactory(**data) # Must be curator or superuser to edit group. Make user the curator. group.curator = self.user.userprofile group.save() url = reverse("groups:group_edit", prefix="/en-US/", kwargs={"url": group.url}) # Change some data data2 = data.copy() data2["description"] = u"A new description" data2["wiki"] = u"http://google.com/" # make like a form del data2["functional_area"] with self.login(self.user) as client: response = client.post(url, data=data2, follow=False) eq_(302, response.status_code) group = GroupAlias.objects.get(name=data["name"]).alias eq_(data2["description"], group.description) ok_(group.visible) ok_(group.members_can_leave) ok_(not group.functional_area)
def test_member_counts(self): # The Group admin computes how many vouched members there are # and how many overall # IMPORTANT: This test is expected to fail on Postgres, and # probably other databases where the Boolean type is not just # an alias for a small integer. Mozillians is currently # deployed on a database where this works. If we ever try # deploying it on another database where it doesn't work, this # test will alert us quickly that we'll need to take another # approach to this feature. # Create group with 1 vouched member and 1 unvouched member group = GroupFactory() user = UserFactory(userprofile={'is_vouched': False}) group.add_member(user.userprofile) user2 = UserFactory(userprofile={'is_vouched': True}) group.add_member(user2.userprofile) admin = GroupAdmin(model=Group, admin_site=site) mock_request = Mock(spec=HttpRequest) qset = admin.queryset(mock_request) g = qset.get(name=group.name) eq_(2, g.member_count) eq_(1, g.vouched_member_count)
def test_cis_groups_highest(self): user = UserFactory.create() group1 = GroupFactory.create(name='nda', is_access_group=True) group2 = GroupFactory.create(name='cis_whitelist', is_access_group=True) group3 = GroupFactory.create(name='open innovation + reps council', is_access_group=True) group4 = GroupFactory.create(name='group4') group1.add_member(user.userprofile) group2.add_member(user.userprofile) group3.add_member(user.userprofile) group4.add_member(user.userprofile, status='PENDING') IdpProfile.objects.create( profile=user.userprofile, auth0_user_id='github|[email protected]', primary=False, email='*****@*****.**' ) idp = IdpProfile.objects.create( profile=user.userprofile, auth0_user_id='ad|[email protected]', primary=True, email='*****@*****.**' ) eq_(set(user.userprofile.get_cis_groups(idp)), set(['mozilliansorg_nda', 'mozilliansorg_cis_whitelist', 'mozilliansorg_open-innovation-reps-council']))
def test_set_membership_group_matches_alias(self): group_1 = GroupFactory.create(name="foo") group_2 = GroupFactory.create(name="lo") GroupAliasFactory.create(alias=group_2, name="bar") user = UserFactory.create() user.userprofile.set_membership(Group, ["foo", "bar"]) eq_(set(user.userprofile.groups.all()), set([group_1, group_2]))
def test_update_basket_task(self, mock_basket): # When a user is created or added to a group, the appropriate # calls to update basket are made email = '*****@*****.**' token = 'footoken' mock_basket.lookup_user.return_value = { 'email': email, } mock_basket.subscribe.return_value = { 'token': token, } user = UserFactory.create(email=email) mock_basket.subscribe.reset_mock() # forget that subscribe was called group = GroupFactory.create(name='Web Development', functional_area=True) GroupFactory.create(name='Marketing', functional_area=True) data = {'country': 'gr', 'city': 'Athens', 'WEB_DEVELOPMENT': 'Y', 'MARKETING': 'N'} group.add_member(user.userprofile) # We just added a group, we should not need to subscribe anything ok_(not mock_basket.subscribe.called) # But we do need to update their phonebook record mock_basket.request.assert_called_with( 'post', 'custom_update_phonebook', token=token, data=data)
def test_extract_document(self): user = UserFactory.create(userprofile={'allows_community_sites': False, 'allows_mozilla_sites': False, 'full_name': 'Nikos Koukos', 'bio': 'This is my bio'}) profile = user.userprofile group_1 = GroupFactory.create() group_2 = GroupFactory.create() skill_1 = SkillFactory.create() skill_2 = SkillFactory.create() LanguageFactory.create(code='fr', userprofile=profile) LanguageFactory.create(code='en', userprofile=profile) group_1.add_member(profile) group_2.add_member(profile) profile.skills.add(skill_1) profile.skills.add(skill_2) result = UserProfileMappingType.extract_document(profile.id) ok_(isinstance(result, dict)) eq_(result['id'], profile.id) eq_(result['is_vouched'], profile.is_vouched) eq_(result['region'], 'attika') eq_(result['city'], 'athens') eq_(result['allows_community_sites'], profile.allows_community_sites) eq_(result['allows_mozilla_sites'], profile.allows_mozilla_sites) eq_(set(result['country']), set(['gr', 'greece'])) eq_(result['fullname'], profile.full_name.lower()) eq_(result['name'], profile.full_name.lower()) eq_(result['bio'], profile.bio) eq_(result['has_photo'], False) eq_(result['groups'], [group_1.name, group_2.name]) eq_(result['skills'], [skill_1.name, skill_2.name]) eq_(set(result['languages']), set([u'en', u'fr', u'english', u'french', u'français']))
def test_group_edit(self): # Curator can edit a group and change (some of) its properties data = { 'name': u'Test Group', 'accepting_new_members': u'by_request', 'description': u'lorem ipsum and lah-dee-dah', 'irc_channel': u'some text, this is not validated', 'website': u'http://mozillians.org', 'wiki': u'http://wiki.mozillians.org', 'members_can_leave': True, 'visible': True, 'functional_area': False, } group = GroupFactory(**data) # Must be curator or superuser to edit group. Make user the curator. group.curator = self.user.userprofile group.save() url = reverse('groups:group_edit', prefix='/en-US/', kwargs={'url': group.url}) # Change some data data2 = data.copy() data2['description'] = u'A new description' data2['wiki'] = u'http://google.com/' # make like a form del data2['functional_area'] with self.login(self.user) as client: response = client.post(url, data=data2, follow=False) eq_(302, response.status_code) group = GroupAlias.objects.get(name=data['name']).alias eq_(data2['description'], group.description) ok_(group.visible) ok_(group.members_can_leave) ok_(not group.functional_area)
def test_export_view_post(self): user = UserFactory.create(is_superuser=True, is_staff=True) export_url = reverse('admin:users_userprofile_export') # NDA group required for admin response rendering GroupFactory.create(name=settings.NDA_GROUP) mock_bucket = MagicMock() mock_connection = MagicMock() mock_connection.get_bucket.return_value = mock_bucket with patch('mozillians.common.mixins.S3ExportMixin.get_export_filename') as mock_filename: with patch('mozillians.common.mixins.boto') as mock_boto: mock_boto.connect_s3.return_value = mock_connection mock_filename.return_value = 'example_filename.format' with self.login(user) as client: data = { 'file_format': '0' } client.post(export_url, data=data) kwargs = { 'calling_format': ANY, 'aws_access_key_id': 'foo', 'aws_secret_access_key': 'bar' } calling_format = mock_boto.connect_s3.call_args[1]['calling_format'] mock_boto.connect_s3.assert_called_with(**kwargs) ok_(isinstance(calling_format, boto.s3.connection.OrdinaryCallingFormat)) mock_connection.get_bucket.assert_called_with('s3-bucket') mock_bucket.new_key.assert_called_with('example_filename.format')
def test_valid_name(self): """Valid group with name that matches the old group regex doens't redirect.""" group = GroupFactory.create(name='111-foo') GroupFactory.create(name='foo') url = reverse('groups:show', kwargs={'url': group.url}) with self.login(self.user) as client: response = client.get(url, follow=True) eq_(response.status_code, 200) eq_(response.context['group'], group)
def test_member_counts(self): group = GroupFactory() user = UserFactory.create() group.add_member(user.userprofile) admin = GroupAdmin(model=Group, admin_site=site) mock_request = Mock(spec=HttpRequest) qset = admin.queryset(mock_request) g = qset.get(name=group.name) eq_(1, g.member_count)
def setUp(self): self.user = UserFactory.create() self.group_1 = GroupFactory.create(name='abc') self.group_2 = GroupFactory.create(name='def') self.group_2.add_member(self.user.userprofile) self.query = Group.objects.filter(pk__in=[self.group_1.pk, self.group_2.pk]) self.template = 'groups/index.html' self.request = RequestFactory() self.request.GET = {} self.request.user = self.user
def test_autocomplete_assign(self): user = UserFactory.create() group_1 = GroupFactory.create() group_2 = GroupFactory.create(auto_complete=False) group_1.members.add(user.userprofile) tasks.assign_autocomplete_to_groups() group_1 = Group.objects.get(pk=group_1.pk) group_2 = Group.objects.get(pk=group_2.pk) eq_(group_1.auto_complete, True) eq_(group_2.auto_complete, False)
def test_merge_groups(self): master_group = GroupFactory.create() merge_group_1 = GroupFactory.create() merge_group_2 = GroupFactory.create() nested_group = GroupFactory.create() merge_group_1.merge_groups([nested_group]) master_group.merge_groups([merge_group_1, merge_group_2]) eq_(master_group.aliases.count(), 4) for group in [merge_group_1, merge_group_2, nested_group]: ok_(master_group.aliases.filter(name=group.name, url=group.url).exists()) ok_(not Group.objects.filter(pk=group.pk).exists())
def test_distinct_results(self): user = UserFactory.create() group_1 = GroupFactory.create() group_2 = GroupFactory.create() group_1.add_member(user.userprofile) group_2.add_member(user.userprofile) client = Client() url = urlparams(self.mozilla_resource_url, groups=",".join([group_1.name, group_2.name])) response = client.get(url, follow=True) data = json.loads(response.content) eq_(response.status_code, 200) eq_(len(data["objects"]), 1)
def test_get_annotated_groups_only_visible(self): """ Test that get_annotated_groups() only returns visible groups """ group_1 = GroupFactory.create(visible=True) group_2 = GroupFactory.create(visible=False) profile = UserFactory.create().userprofile group_1.add_member(profile) group_2.add_member(profile) user_groups = profile.get_annotated_groups() eq_([group_1], user_groups)
def setUp(self): self.user = UserFactory.create(userprofile={'is_vouched': True}) self.group_1 = GroupFactory.create() self.group_2 = GroupFactory.create() self.group_2.members.add(self.user.userprofile) self.query = (Group.objects .filter(pk__in=[self.group_1.pk, self.group_2.pk]) .annotate(num_members=Count('members'))) self.template = 'groups/index.html' self.request = RequestFactory() self.request.GET = {} self.request.user = self.user
def test_search_existing_group(self): user = UserFactory.create() group_1 = GroupFactory.create(visible=True) GroupFactory.create() url = urlparams(reverse("groups:search_groups"), term=group_1.name) with self.login(user) as client: response = client.get(url, follow=True, **{"HTTP_X_REQUESTED_WITH": "XMLHttpRequest"}) eq_(response.status_code, 200) eq_(response.get("content-type"), "application/json") data = json.loads(response.content) eq_(len(data), 1, "Non autocomplete groups are included in search") eq_(data[0], group_1.name)
def test_index_functional_areas(self): user = UserFactory.create(userprofile={"is_vouched": True}) group_1 = GroupFactory.create(steward=user.userprofile) group_2 = GroupFactory.create() GroupFactory.create() group_1.members.add(user.userprofile) group_2.members.add(user.userprofile) with self.login(user) as client: response = client.get(self.url, follow=True) eq_(response.status_code, 200) self.assertTemplateUsed(response, "groups/index_areas.html") eq_(set(response.context["groups"].paginator.object_list), set([group_1]))
def test_search_groups(self): client = Client() group_1 = GroupFactory.create() group_2 = GroupFactory.create() user_1 = UserFactory.create(userprofile={'is_vouched': True}) user_1.userprofile.groups.add(group_1) user_2 = UserFactory.create(userprofile={'is_vouched': True}) user_2.userprofile.groups.add(group_2) url = urlparams(self.mozilla_resource_url, groups=group_1.name) response = client.get(url, follow=True) data = json.loads(response.content) eq_(len(data['objects']), 1) eq_(data['objects'][0]['id'], unicode(user_1.userprofile.id))
def test_search_groups(self): client = Client() group_1 = GroupFactory.create() group_2 = GroupFactory.create() user_1 = UserFactory.create() group_1.add_member(user_1.userprofile) user_2 = UserFactory.create() group_2.add_member(user_2.userprofile) url = urlparams(self.mozilla_resource_url, groups=group_1.name) response = client.get(url, follow=True) data = json.loads(response.content) eq_(len(data["objects"]), 1) eq_(data["objects"][0]["id"], user_1.userprofile.id)
def test_search_existing_group(self): user = UserFactory.create(userprofile={'is_vouched': True}) group_1 = GroupFactory.create(auto_complete=True) GroupFactory.create() url = urlparams(reverse('groups:search_groups'), term=group_1.name) with self.login(user) as client: response = client.get(url, follow=True, **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'}) eq_(response.status_code, 200) eq_(response.get('content-type'), 'application/json') data = json.loads(response.content) eq_(len(data), 1, 'Non autocomplete groups are included in search') eq_(data[0], group_1.name)
def test_index_functional_areas(self): user = UserFactory.create() group_1 = GroupFactory.create(curator=user.userprofile, functional_area=True) group_2 = GroupFactory.create() GroupFactory.create() group_1.add_member(user.userprofile) group_2.add_member(user.userprofile) with self.login(user) as client: response = client.get(self.url, follow=True) eq_(response.status_code, 200) self.assertTemplateUsed(response, 'groups/index_areas.html') eq_(set(response.context['groups'].paginator.object_list), set([group_1]))
def test_index(self): user_1 = UserFactory.create(userprofile={"is_vouched": True}) user_2 = UserFactory.create() group_1 = GroupFactory.create() group_2 = GroupFactory.create() group_3 = GroupFactory.create() group_1.members.add(user_1.userprofile) group_2.members.add(user_1.userprofile) group_3.members.add(user_2.userprofile) with self.login(user_1) as client: response = client.get(self.url, follow=True) eq_(response.status_code, 200) self.assertTemplateUsed(response, "groups/index_groups.html") eq_(set(response.context["groups"].paginator.object_list), set([group_1, group_2]))
def test_set_membership_system_group(self): # a "system" group is invisible and cannot be joined or left group_1 = GroupFactory.create(visible=False, members_can_leave=False, accepting_new_members="no") user = UserFactory.create() user.userprofile.set_membership(Group, [group_1.name, "bar"]) ok_(user.userprofile.groups.filter(name="bar").exists()) eq_(user.userprofile.groups.count(), 1)
def test_search_distict_results(self): group_1 = GroupFactory.create(name='automation', visible=True) GroupAliasFactory.create(alias=group_1, name='automation development') GroupAliasFactory.create(alias=group_1, name='automation services') results = Group.search('automation') eq_(len(results), 1) eq_(results[0], group_1)
def test_edit_invalidation_invalid_data(self): group = GroupFactory.create() data = {'invalidation_days': 1000} form = self.validate_group_edit_forms(forms.GroupTermsExpirationForm, group, data, None, False) eq_(form.errors, {'invalidation_days': [u'The maximum expiration date for a group ' 'cannot exceed two years.']})
def setUp(self): voucher = UserFactory.create(userprofile={'is_vouched': True}) self.user = UserFactory.create( userprofile={'is_vouched': True, 'vouched_by': voucher.userprofile}) group = GroupFactory.create() self.user.userprofile.groups.add(group) skill = SkillFactory.create() self.user.userprofile.skills.add(skill) language = LanguageFactory.create() self.user.userprofile.languages.add(language) self.resource_url = reverse( 'api_dispatch_list', kwargs={'api_name': 'v1', 'resource_name': 'users'}) self.mozilla_app = APIAppFactory.create( owner=self.user, is_mozilla_app=True) self.mozilla_resource_url = urlparams( self.resource_url, app_name=self.mozilla_app.name, app_key=self.mozilla_app.key) self.community_app = APIAppFactory.create( owner=self.user, is_mozilla_app=False) self.community_resource_url = urlparams( self.resource_url, app_name=self.community_app.name, app_key=self.community_app.key)
def test_old_group_url_redirects(self): group = GroupFactory.create() url = '/group/111-{0}/'.format(group.url) with self.login(self.user) as client: response = client.get(url, follow=True) eq_(response.status_code, 200) eq_(response.context['group'], group)
def test_set_membership_system_group(self): # a "system" group is invisible and cannot be joined or left group_1 = GroupFactory.create(visible=False, members_can_leave=False, accepting_new_members='no') user = UserFactory.create() user.userprofile.set_membership(Group, [group_1.name, 'bar']) ok_(user.userprofile.groups.filter(name='bar').exists()) eq_(user.userprofile.groups.count(), 1)
def test_system_group(self): system_group = GroupFactory.create(system=True) url = reverse('groups:toggle_subscription', prefix='/en-US/', kwargs={'url': system_group.url}) with self.login(self.user) as client: client.post(url, follow=True) system_group = Group.objects.get(id=system_group.id) ok_(not system_group.members.filter(pk=self.user.pk).exists())
def test_unjoinable_group(self): group = GroupFactory.create(accepting_new_members='no') join_url = reverse('groups:join_group', prefix='/en-US/', kwargs={'url': group.url}) with self.login(self.user) as client: client.post(join_url, follow=True) group = Group.objects.get(id=group.id) ok_(not group.members.filter(pk=self.user.pk).exists())
def test_alias_redirection(self): user = UserFactory.create(userprofile={'is_vouched': True}) group = GroupFactory.create() group_alias = GroupAliasFactory.create(alias=group) url = reverse('groups:show', kwargs={'url': group_alias.url}) with self.login(user) as client: response = client.get(url, follow=True) eq_(response.status_code, 200) eq_(response.context['group'], group)
def test_filter_group_member(self): request = self.factory.get('/', {'group': 'bar'}) user = UserFactory.create() group = GroupFactory.create(name='bar') group.add_member(user.userprofile) f = UserProfileFilter(request.GET, queryset=UserProfile.objects.all()) eq_(f.qs.count(), 1) eq_(f.qs[0], user.userprofile)
def test_nda_access_scope(self): request = self.factory.get('/') user = UserFactory.create(vouched=True) request.user = user nda = GroupFactory.create(name='nda') GroupMembership.objects.create(userprofile=user.userprofile, group=nda, status=GroupMembership.MEMBER) eq_(UserAccessLevel.get_privacy(request), 'nda')
def test_get_functional_areas(self): GroupFactory.create() GroupFactory.create() UserFactory.create() UserFactory.create() cgroup_1 = GroupFactory.create(functional_area=True) GroupFactory.create(functional_area=False) eq_(set(Group.get_functional_areas()), set([cgroup_1]))
def test_send_renewal_notification_inviter_not_curator( self, mock_now, mock_send_mail): """Test renewal notification functionality for curators""" curator1 = UserFactory.create(email='*****@*****.**') curator2 = UserFactory.create(email='*****@*****.**') inviter = UserFactory.create(email='*****@*****.**') member = UserFactory.create(userprofile={'full_name': 'Example Name'}) group = GroupFactory.create(name='foobar', invalidation_days=365, accepting_new_members=Group.CLOSED) group.curators.add(curator1.userprofile) group.curators.add(curator2.userprofile) group.add_member(member.userprofile) InviteFactory.create(inviter=inviter.userprofile, redeemer=member.userprofile, group=group) datetime_now = now() + timedelta(days=351) mock_now.return_value = datetime_now notify_membership_renewal() ok_(mock_send_mail.called) eq_(3, len(mock_send_mail.mock_calls)) # Check email to mozillians name, args, kwargs = mock_send_mail.mock_calls[0] subject, body, from_addr, to_list = args eq_( subject, '[Mozillians] Your membership to Mozilla group "foobar" is about to expire' ) eq_(from_addr, settings.FROM_NOREPLY) eq_(to_list, [member.userprofile.email]) # Check email for curator1 name, args, kwargs = mock_send_mail.mock_calls[1] subject, body, from_addr, to_list = args eq_( subject, '[Mozillians][foobar] Membership of "Example Name" is about to expire' ) eq_(from_addr, settings.FROM_NOREPLY) eq_(list(to_list), [u'*****@*****.**']) # Check email for curator2 name, args, kwargs = mock_send_mail.mock_calls[2] subject, body, from_addr, to_list = args eq_( subject, '[Mozillians][foobar] Membership of "Example Name" is about to expire' ) eq_(from_addr, settings.FROM_NOREPLY) eq_(list(to_list), [u'*****@*****.**'])
def test_has_member(self): user = UserFactory.create() group = GroupFactory.create() ok_(not group.has_member(user.userprofile)) GroupMembership.objects.create(userprofile=user.userprofile, group=group, status=GroupMembership.MEMBER) ok_(group.has_member(user.userprofile)) group.remove_member(user.userprofile) ok_(not group.has_member(user.userprofile))
def test_edit_basic_form_with_data(self): group = GroupFactory.create() data = { 'name': 'test group', 'description': 'sample description', 'irc_channel': 'foobar', 'website': 'https://example.com', 'wiki': 'https://example-wiki.com' } self.validate_group_edit_forms(forms.GroupBasicForm, group, data)
def test_edit_invitation_without_curator(self): invitee = UserFactory.create() group = GroupFactory.create() request = RequestFactory().request() request.user = UserFactory.create() data = {'invites': [invitee.userprofile.id]} form = self.validate_group_edit_forms(forms.GroupInviteForm, group, data, request, False) eq_(form.errors, {'invites': [u'You need to be the curator of this group before ' 'inviting someone to join.']})
def test_remove_member_nda(self, unsubscribe_basket_mock): user = UserFactory.create(userprofile__email='*****@*****.**') group = GroupFactory.create(name='nda') GroupMembership.objects.create(userprofile=user.userprofile, group=group, status=GroupMembership.MEMBER) ok_(group.has_member(user.userprofile)) group.remove_member(user.userprofile) ok_(not group.has_member(user.userprofile)) ok_(unsubscribe_basket_mock.called_with('*****@*****.**', ['nda']))
def test_group_subscription_terms(self): group = GroupFactory.create(terms='Example terms') with override_script_prefix('/en-US/'): join_url = reverse('groups:join_group', kwargs={'url': group.url}) with self.login(self.user) as client: client.post(join_url, follow=True) membership = group.groupmembership_set.get( userprofile=self.user.userprofile) eq_(membership.status, GroupMembership.PENDING_TERMS)
def test_access_group_type_open(self): curator = UserFactory.create() group = GroupFactory.create(is_access_group=True) group.curators.add(curator.userprofile) request = RequestFactory().request() request.user = curator form_data = {'accepting_new_members': Group.OPEN} form = forms.GroupCriteriaForm(instance=group, data=form_data) ok_(not form.is_valid()) eq_(len(form.errors), 1)
def test_remove_member_nda_pending_status(self, unsubscribe_basket_mock): user = UserFactory.create(userprofile__email='*****@*****.**', userprofile__basket_token='basket_token') group = GroupFactory.create(name='nda') GroupMembership.objects.create(userprofile=user.userprofile, group=group, status=GroupMembership.PENDING_TERMS) group.remove_member(user.userprofile) ok_(not group.has_member(user.userprofile)) ok_(not unsubscribe_basket_mock.called)
def test_access_group_type_reviewed(self): curator = UserFactory.create() group = GroupFactory.create(is_access_group=True) group.curators.add(curator.userprofile) request = RequestFactory().request() request.user = curator form_data = {'accepting_new_members': Group.REVIEWED, 'new_member_criteria': 'Criteria'} form = forms.GroupCriteriaForm(data=form_data) ok_(form.is_valid())
def test_show_join_button_accepting_members_yes(self): group = GroupFactory.create(accepting_new_members='yes') user = UserFactory.create() url = reverse('groups:show_group', kwargs={'url': group.url}) with self.login(user) as client: response = client.get(url, follow=True) eq_(response.status_code, 200) eq_(response.context['show_join_button'], True) ok_(not response.context['is_pending'])
def test_show_join_button_accepting_members_by_request_member(self): group = GroupFactory.create(accepting_new_members='yes') user = UserFactory.create() group.add_member(user.userprofile) url = reverse('groups:show_group', kwargs={'url': group.url}) with self.login(user) as client: response = client.get(url, follow=True) eq_(response.status_code, 200) eq_(response.context['show_join_button'], False)
def test_extract_document(self): group_1 = GroupFactory.create() group_2 = GroupFactory.create() skill_1 = SkillFactory.create() skill_2 = SkillFactory.create() language_1 = LanguageFactory.create() language_2 = LanguageFactory.create() user = UserFactory.create( userprofile={ 'website': 'bestplaceonthenet.com', 'city': 'athens', 'region': 'attika', 'allows_community_sites': False, 'allows_mozilla_sites': False, 'country': 'gr', 'full_name': 'Nikos Koukos', 'bio': 'This is my bio' }) profile = user.userprofile profile.groups.add(group_1) profile.groups.add(group_2) profile.skills.add(skill_1) profile.skills.add(skill_2) profile.languages.add(language_1) profile.languages.add(language_2) result = UserProfile.extract_document(user.userprofile.id) ok_(isinstance(result, dict)) eq_(result['id'], profile.id) eq_(result['is_vouched'], profile.is_vouched) eq_(result['website'], profile.website) eq_(result['region'], profile.region) eq_(result['city'], profile.city) eq_(result['allows_community_sites'], profile.allows_community_sites) eq_(result['allows_mozilla_sites'], profile.allows_mozilla_sites) eq_(result['country'], ['gr', 'greece']) eq_(result['fullname'], profile.full_name.lower()) eq_(result['name'], profile.full_name.lower()) eq_(result['bio'], profile.bio) eq_(result['has_photo'], False) eq_(result['groups'], [group_1.name, group_2.name]) eq_(result['skills'], [skill_1.name, skill_2.name]) eq_(result['languages'], [language_1.name, language_2.name])
def setUp(self): self.group = GroupFactory.create() self.user = UserFactory.create() # We must request the full path, with language, or the # LanguageMiddleware will convert the request to GET. self.join_url = reverse('groups:join_group', prefix='/en-US/', kwargs={'url': self.group.url}) self.leave_url = reverse('groups:remove_member', prefix='/en-US/', kwargs={'url': self.group.url, 'user_pk': self.user.userprofile.pk})
def test_search_unvouched(self): user = UserFactory.create() group = GroupFactory.create(auto_complete=True) url = urlparams(reverse('groups:search_groups'), term=group.name) with self.login(user) as client: response = client.get( url, follow=True, **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'}) eq_(response.status_code, 200) eq_(response.get('content-type'), 'application/json')
def test_name_unique(self): group = GroupFactory.create() GroupAliasFactory.create(alias=group, name='bar') form = forms.GroupCreateForm({ 'name': 'bar', 'accepting_new_members': 'by_request' }) ok_(not form.is_valid()) ok_('name' in form.errors) msg = u'This name already exists.' ok_(msg in form.errors['name'])
def test_show_review_terms_pending(self): group = GroupFactory.create(terms='Example terms') user = UserFactory.create() group.add_member(user.userprofile, status=GroupMembership.PENDING_TERMS) url = reverse('groups:show_group', kwargs={'url': group.url}) with self.login(user) as client: response = client.get(url, follow=True) eq_(response.status_code, 200) self.assertTemplateUsed(response, 'groups/terms.html')
def test_annotated_groups_not_public(self): # Group member who wants their groups kept semi-private profile = UserFactory.create(userprofile={'privacy_groups': MOZILLIANS}).userprofile group = GroupFactory.create(name='group') group.add_member(profile) # Being accessed by a member of the general public profile.set_instance_privacy_level(PUBLIC) # no groups seen eq_(len(profile.get_annotated_groups()), 0)
def test_legacy_group_manager_edit_no_curators(self): user = UserFactory.create(manager=True) group = GroupFactory.create() url = reverse('groups:group_edit', prefix='/en-US/', kwargs={'url': group.url}) with self.login(user) as client: response = client.get(url, follow=True) eq_(response.status_code, 200) initial_curators = response.context['form'].initial['curators'] eq_(len(initial_curators), 0)
def test_invalidate_group_accepts_all(self): group = GroupFactory.create(invalidation_days=5) user = UserFactory.create() group.add_member(user.userprofile) membership = group.groupmembership_set.filter( userprofile=user.userprofile) membership.update(updated_on=datetime.now() - timedelta(days=10)) eq_(membership[0].status, GroupMembership.MEMBER) invalidate_group_membership() ok_(not group.groupmembership_set.filter( userprofile=user.userprofile).exists())
def test_add_member_nda(self, subscribe_user_mock): user = UserFactory.create() group = GroupFactory.create(name='nda') ok_(not group.has_member(user.userprofile)) group.add_member(user.userprofile) ok_( GroupMembership.objects.filter( userprofile=user.userprofile, group=group, status=GroupMembership.MEMBER).exists()) ok_(subscribe_user_mock.called_with(user.userprofile.id, ['nda']))
def test_edit_admin(self): group = GroupFactory.create() request = RequestFactory().request() request.user = UserFactory.create(is_superuser=True) data = { 'functional_area': True, 'visible': True, 'members_can_leave': True } self.validate_group_edit_forms(forms.GroupAdminForm, group, data, request)
def test_show_leave_button_value_without_curator(self): group = GroupFactory.create() user = UserFactory.create() group.add_member(user.userprofile) url = reverse('groups:show_group', kwargs={'url': group.url}) with self.login(user) as client: response = client.get(url, follow=True) eq_(response.status_code, 200) eq_(response.context['show_leave_button'], True) ok_(not response.context['is_pending'])
def test_cis_groups_not_highest(self): user = UserFactory.create() group1 = GroupFactory.create(name='nda') group2 = GroupFactory.create(name='cis_whitelist') group3 = GroupFactory.create(name='group3') group1.add_member(user.userprofile) group2.add_member(user.userprofile) group3.add_member(user.userprofile, status='PENDING') idp = IdpProfile.objects.create( profile=user.userprofile, auth0_user_id='github|[email protected]', primary=False, ) IdpProfile.objects.create( profile=user.userprofile, auth0_user_id='ad|[email protected]', primary=True, ) eq_(user.userprofile.get_cis_groups(idp), [])