def tearDown(self): print "clearing groups..." G.objects.all().delete() print "clearning social tags..." ST.objects.all().delete() #TODO:St seems not cleared T = getT('unittest') T.objects.all().delete() T2 = getT('unittest2') T2.objects.all().delete()
def testAddGroupTags(self): g1 = G.objects.get(name='test_maniacs') self.testJoinGroup() add_tags(g1, ['functional test', 'performance test']) assert_in('functional test', g1.get_tag_names()) assert_in('performance test', g1.get_tag_names()) T1 = getT('unittest') T2 = getT('unittest2') for T in [T1, T2]: T.objects.get(name='functional test') T.objects.get(name='performance test')
def cleanup_tags(): users = User.objects.all() for user in users: N = getNote(user.username, 'notebook') T = getT(user.username) print 'Cleaning up tags for user:'******'untagged') for note in notes: #t = T.objects.get(name='untagged') if note.tags.count() > 1: print 'removing the tag untagged for note:', note.id note.remove_tags(['untagged']) #note.save() try: t = T.objects.get(name="") except ObjectDoesNotExist: print 'raise ObjectDoesNotExist when finding the empty string tag for user:'******'removing the empty tag for note:', note.id note.tags.remove(t) #note.save() print "removing the empty tag itself" t.delete() except ConnectionDoesNotExist: print 'raised ConnectionDoesNotExist for user:' + user.username
def testJoinGroup(self): username2 = 'unittest2' m, created = Member.objects.get_or_create(username=username2) join_group('test_maniacs', username2) g = G.objects.get(name='test_maniacs') assert_in(m, g.members.all()) sts = g.tags.all() T = getT('unittest2') for st in sts: T.objects.get(name=st.name)
def remove_untagged(users): for user in users: print 'For user', user try: T = getT(user) if T.objects.filter(name='untagged').exists(): t = T.objects.get(name='untagged') t.delete() if T.objects.filter(name='').exists(): t1 = T.objects.get(name='') t1.delete() except: print sys.exc_info()
def testCreatePrivateGroup(self): g = G.objects.get(name='my_private_group') eq_(g.name, 'my_private_group') eq_(g.private, True) eq_(g.get_tag_names(), ['my_private_group', 'sharinggroup:' + g.name]) T = getT('unittest') W = getW('unittest') w1 = W.objects.get(name='snippetbook') eq_(w1.name, 'snippetbook') w2 = W.objects.get(name='bookmarkbook') eq_(w2.name, 'bookmarkbook') w3 = W.objects.get(name='scrapbook') eq_(w3.name, 'scrapbook') w = W.objects.get(name="sharinggroup:" + g.name) eq_(w.name, "sharinggroup:" + g.name) for st in ['my_private_group', 'sharinggroup:' + g.name]: t = T.objects.get(name=st) eq_(t.name, st) eq_(t.private, True) eq_(t.name in w1.display_tags().split(','), True)
def testCreatePrivateGroup(self): g = G.objects.get(name='my_private_group') eq_(g.name, 'my_private_group') eq_(g.private, True) eq_(g.get_tag_names(), ['my_private_group', 'sharinggroup:'+g.name]) T = getT('unittest') W = getW('unittest') w1 = W.objects.get(name='snippetbook') eq_(w1.name, 'snippetbook') w2 = W.objects.get(name='bookmarkbook') eq_(w2.name, 'bookmarkbook') w3 = W.objects.get(name='scrapbook') eq_(w3.name, 'scrapbook') w = W.objects.get(name="sharinggroup:"+g.name) eq_(w.name, "sharinggroup:"+g.name) for st in ['my_private_group', 'sharinggroup:'+g.name]: t = T.objects.get(name=st) eq_(t.name, st) eq_(t.private, True) eq_(t.name in w1.display_tags().split(','), True)
def testCreateGroup(self): g = G.objects.get(name='test_maniacs') eq_(g.name, 'test_maniacs') eq_(g.private, False) eq_(g.get_tag_names(), ['framework', 'philosophy', 'sharinggroup:test_maniacs', 'testing']) T = getT(self.name) W = getW(self.name) w1 = W.objects.get(name='snippetbook') eq_(w1.name, 'snippetbook') w2 = W.objects.get(name='bookmarkbook') eq_(w2.name, 'bookmarkbook') w3 = W.objects.get(name='scrapbook') eq_(w3.name, 'scrapbook') w = W.objects.get(name="sharinggroup:"+g.name) eq_(w.name, "sharinggroup:"+g.name) for st in ['testing', 'framework', 'philosophy']: t = T.objects.get(name=st) eq_(t.name, st) eq_(t.private, False) eq_(t.name in w1.display_tags().split(','), True)
def testCreateGroup(self): g = G.objects.get(name='test_maniacs') eq_(g.name, 'test_maniacs') eq_(g.private, False) eq_(g.get_tag_names(), [ 'framework', 'philosophy', 'sharinggroup:test_maniacs', 'testing' ]) T = getT(self.name) W = getW(self.name) w1 = W.objects.get(name='snippetbook') eq_(w1.name, 'snippetbook') w2 = W.objects.get(name='bookmarkbook') eq_(w2.name, 'bookmarkbook') w3 = W.objects.get(name='scrapbook') eq_(w3.name, 'scrapbook') w = W.objects.get(name="sharinggroup:" + g.name) eq_(w.name, "sharinggroup:" + g.name) for st in ['testing', 'framework', 'philosophy']: t = T.objects.get(name=st) eq_(t.name, st) eq_(t.private, False) eq_(t.name in w1.display_tags().split(','), True)
def add_tags(g, new_tags): #need to push new tags to every group member's database all_members = list(g.members.values_list('username', flat=True)) all_members.extend(list(g.admins.values_list('username', flat=True))) all_members.append(g.creator.username) all_members = list(set(all_members)) for tag_name in new_tags: if tag_name not in g.get_tag_names(): t, created = ST.objects.get_or_create(name=tag_name) g.tags.add(t) for m in all_members: T = getT(m) t, created = T.objects.get_or_create(name=t.name) W = getW(m) w1 = W.objects.get(name='snippetbook') w2 = W.objects.get(name='bookmarkbook') w3 = W.objects.get(name='scrapbook') w = W.objects.get(name="sharinggroup:" + g.name) w1.tags.add(t) w2.tags.add(t) w3.tags.add(t) w.tags.add(t)
def add_tags(g, new_tags): #need to push new tags to every group member's database all_members = list(g.members.values_list('username', flat=True)) all_members.extend(list(g.admins.values_list('username', flat=True))) all_members.append(g.creator.username) all_members = list(set(all_members)) for tag_name in new_tags: if tag_name not in g.get_tag_names(): t, created = ST.objects.get_or_create(name=tag_name) g.tags.add(t) for m in all_members: T = getT(m) t, created = T.objects.get_or_create(name=t.name) W = getW(m) w1 = W.objects.get(name='snippetbook') w2 = W.objects.get(name='bookmarkbook') w3 = W.objects.get(name='scrapbook') w = W.objects.get(name="sharinggroup:"+g.name) w1.tags.add(t) w2.tags.add(t) w3.tags.add(t) w.tags.add(t)
def push_group_tags_back(g, username): T = getT(username) sts = g.tags.all() W = getW(username) w1, created = W.objects.get_or_create(name='snippetbook') w2, created = W.objects.get_or_create(name='bookmarkbook') w3, created = W.objects.get_or_create(name='scrapbook') w, created = W.objects.get_or_create(name="sharinggroup:" + g.name) for st in sts: t, created = T.objects.get_or_create(name=st.name) if created: t.private = st.private #It is a little messy here. The logic here is that for private #group, the tags it pushes back to the use space should be private #as well. Then when user save their notes with that tag, the social #note will be private. if g.private: t.private = True t.save() w1.tags.add(t) w2.tags.add(t) w3.tags.add(t) w.tags.add(t) return g
def push_group_tags_back(g, username): T = getT(username) sts = g.tags.all() W = getW(username) w1, created = W.objects.get_or_create(name='snippetbook') w2, created = W.objects.get_or_create(name='bookmarkbook') w3, created = W.objects.get_or_create(name='scrapbook') w, created = W.objects.get_or_create(name="sharinggroup:"+g.name) for st in sts: t, created = T.objects.get_or_create(name=st.name) if created: t.private = st.private #It is a little messy here. The logic here is that for private #group, the tags it pushes back to the use space should be private #as well. Then when user save their notes with that tag, the social #note will be private. if g.private: t.private = True t.save() w1.tags.add(t) w2.tags.add(t) w3.tags.add(t) w.tags.add(t) return g