def test_comment_can_be_seen(self): j = User.objects.get(username='******') listing = Listing.objects.get(key='staff') p = Post(title='New Post 2', text='A sentence that is long enough to go to the digest', listing=listing, author=j, name='new-post-2') p.save() comment = self.new_comment(p, j) self.assertFalse(comment.can_be_seen_by(self.sooty))
def test_page_with_primary_category(self): c = Category(title="guides", slug="guides") c.save() c = Category.objects.get(pk=c.pk) p = Post(title="sample title", description="description", subtitle="subtitle", content="sample content") p.primary_category = c p.save() p = Post.objects.get(pk=p.pk) [git_p] = self.workspace.S(eg_models.Page).filter(uuid=p.uuid) self.assertEquals(git_p.primary_category, c.uuid)
def test_create_post(self): p = Post( title="sample title", description="description", subtitle="subtitle", content="sample content", position=3 ) p.save() self.assertEquals(p.featured_in_category, False) self.assertEquals(Post.objects.all().count(), 1) self.assertEquals(self.workspace.S(eg_models.Page).count(), 1) p = Post.objects.get(pk=p.pk) p.title = "changed title" p.save() self.assertEquals(self.workspace.S(eg_models.Page).count(), 1) [eg_page] = self.workspace.S(eg_models.Page).everything() self.assertEquals(eg_page.title, "changed title") self.assertEquals(eg_page.uuid, p.uuid) self.assertEquals(eg_page.subtitle, "subtitle") self.assertEquals(eg_page.description, "description") self.assertEquals(eg_page.featured_in_category, False) self.assertEquals(eg_page.position, 3) self.assertTrue(eg_page.created_at is not None) self.assertTrue(eg_page.modified_at is not None) p.delete() self.assertEquals(Post.objects.all().count(), 0) self.assertEquals(self.workspace.S(eg_models.Page).count(), 0)
def test_page_featured_in_category(self): with self.settings(GIT_REPO_PATH=self.workspace.working_dir): p = Post( title="sample title", description="description", subtitle="subtitle", content="sample content", localisation=Localisation._for("eng_UK"), featured_in_category=True, ) p.save() p = Post.objects.get(pk=p.pk) [git_p] = self.workspace.S(eg_models.Page).filter(uuid=p.uuid) self.assertTrue(git_p.featured_in_category)
def setUp(self): self.author = User.objects.get(username='******') self.sooty = User.objects.get(username='******') listing = Listing.objects.all()[0] self.p = Post(title='New Post', text='A sentence that is long enough to go to the digest', listing=listing, author=self.author, name='new-post') self.p.save() # Clear pigeon/mail created from adding a Post deploy_pigeons() mail.outbox = [] self.counter = 1
def test_page_get_featured(self): with self.settings(GIT_REPO_PATH=self.workspace.working_dir): post = Post( title="sample title", description="description", subtitle="subtitle", content="sample content", localisation=Localisation._for("eng_UK"), ) post.save() featured_post = Post( title="featured sample title", description="featured description", subtitle="featured subtitle", content="featured sample content", localisation=Localisation._for("eng_UK"), featured=True, ) featured_post.save() post = Post.objects.get(pk=post.pk) [git_post] = self.workspace.S(eg_models.Page).filter(uuid=post.uuid) featured_post = Post.objects.get(pk=featured_post.pk) [featured_git_post] = self.workspace.S(eg_models.Page).filter(uuid=featured_post.uuid) self.assertEqual(post.featured, False) self.assertEquals(git_post.featured, False) self.assertEqual(featured_post.featured, True) self.assertEquals(featured_git_post.featured, True)
def handle(self, *args, **options): categories = list(Category.objects.all()) posts = [] for i in range(0, 100): posts.append( Post( title=lorem.sentence(), slug=str(uuid.uuid4()), body=f"{lorem.text()} \n {lorem.text()} \n {lorem.text()}", )) return_posts = Post.objects.bulk_create(posts) for post in return_posts: category = categories[random.randint(0, len(categories) - 1)] post.categories.set([category]) post.save()
def home(): ''' Retrives all the posts present in the database and sends along with pagination :return: posts data and pagination object ''' page = request.args.get('page', 1, type=int) posts = DB.retrieve_posts(page, 5) data = [] for post in posts: data.append(Post(post)) pagination = Pagination(page=page, total=len([d for d in posts]), per_page=5, offset=page, css_framework='bootstrap4') return render_template('home.html', posts=data, pagination=pagination)
def test_page_recreated_if_not_in_git(self): with self.settings(GIT_REPO_PATH=self.workspace.working_dir): p = Post( title="sample test title", description="description", subtitle="subtitle", content="sample content" ) p.save() p = Post.objects.get(pk=p.pk) # Manually delete the git page [git_page] = self.workspace.S(eg_models.Page).filter(uuid=p.uuid) self.workspace.delete(git_page.get_object(), "Removing: %s" % p.uuid) self.workspace.refresh_index() self.assertEquals(self.workspace.S(eg_models.Page).filter(uuid=p.uuid).count(), 0) p.title = "new title" p.save() p = Post.objects.get(pk=p.pk) [git_p] = self.workspace.S(eg_models.Page).filter(uuid=p.uuid) self.assertEquals(git_p.title, "new title")
def handle(self, *args, **options): lorem = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.""" categories = [ { 'name': 'About', 'slug': 'about' }, { 'name': 'Events', 'slug': 'events' }, { 'name': 'Projects', 'slug': 'projects' }, { 'name': 'Comp Sci Guide', 'slug': 'comp-sci-guide' }, ] posts = { 'About': [ { 'title': 'General', 'slug': 'general', 'content': lorem }, { 'title': 'Exec', 'slug': 'exec', 'content': lorem }, { 'title': 'Photos', 'slug': 'photos', 'content': lorem }, { 'title': 'Docs', 'slug': 'docs', 'content': lorem }, { 'title': 'Contact', 'slug': 'contact', 'content': lorem }, ], 'Events': [ { 'title': 'Upcoming', 'slug': 'upcoming', 'content': lorem }, { 'title': 'Frosh Week', 'slug': 'frosh-week', 'content': lorem }, { 'title': 'Workshops', 'slug': 'workshops', 'content': lorem }, ], 'Projects': [ { 'title': 'Hack Time', 'slug': 'hack-time', 'content': lorem }, { 'title': 'Dev Tools', 'slug': 'dev-tools', 'content': lorem }, { 'title': 'Team Names', 'slug': 'team-names', 'content': lorem }, { 'title': 'CSSS Github', 'slug': 'csss-github', 'content': lorem }, ], 'Comp Sci Guide': [ { 'title': 'Course Map', 'slug': 'course-map', 'content': lorem }, { 'title': 'Software', 'slug': 'software', 'content': lorem }, { 'title': 'Co-op', 'slug': 'co-op', 'content': lorem }, ], } announcements = [ { 'title': 'First Thing', 'author': 'Corbettron9000', 'slug': 'first-thing', 'content': lorem, 'created': datetime.now() }, { 'title': 'Second Thing', 'author': 'Colintron9000', 'slug': 'second-thing', 'content': lorem, 'created': datetime.now() }, { 'title': 'Third Thing', 'author': 'Sidtron9000', 'slug': 'third-thing', 'content': lorem, 'created': datetime.now() }, { 'title': 'Fourth Thing', 'author': 'Kennethtron9000', 'slug': 'fourth-thing', 'content': lorem, 'created': datetime.now() }, { 'title': 'Fifth Thing', 'author': 'Jordantron9000', 'slug': 'fifth-thing', 'content': lorem, 'created': datetime.now() }, ] # Create the Categories for category in categories: try: c = Category(**category) c.save() self.stdout.write(category['name'] + ' category created') # Create the Posts for post in posts[category['name']]: try: p = Post(**post) p.category = c p.save() self.stdout.write(post['title'] + ' post created') except IntegrityError: self.stdout.write(post['title'] + ' post skipped') except IntegrityError: self.stdout.write(category['name'] + ' category skipped') self.stdout.write('Skipping all Posts in ' + category['name']) # Create the Announcements for announcement in announcements: try: a = Announcement(**announcement) a.save() self.stdout.write(announcement['title'] + ' announcement created') except IntegrityError: self.stdout.write(announcement['title'] + ' announcement skipped')
def test_page_with_source(self): with self.settings(GIT_REPO_PATH=self.workspace.working_dir): c = Category(title="guides", slug="guides") c.save() c = Category.objects.get(pk=c.pk) p = Post( title="sample title", description="description", subtitle="subtitle", content="sample content", localisation=Localisation._for("eng_UK"), ) p.save() p = Post.objects.get(pk=p.pk) p2 = Post( title="sample title", description="description", subtitle="subtitle", content="sample content", localisation=Localisation._for("eng_US"), ) p2.primary_category = c p2.source = p p2.save() p2 = Post.objects.get(pk=p2.pk) [git_p2] = self.workspace.S(eg_models.Page).filter(uuid=p2.uuid) [git_p2_source] = self.workspace.S(eg_models.Page).filter(uuid=p2.source.uuid) self.assertEquals(git_p2.language, "eng_US") self.assertEquals(git_p2_source.language, "eng_UK") p2.source = None p2.primary_category = None p2.save() [git_p2] = self.workspace.S(eg_models.Page).filter(uuid=p2.uuid) self.assertEquals(git_p2.source, None) self.assertEquals(git_p2.primary_category, None)
def handle(self, *args, **options): lorem = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.""" categories = [ {'name':'About', 'slug':'about'}, {'name':'Events', 'slug':'events'}, {'name':'Projects', 'slug':'projects'}, {'name':'Comp Sci Guide', 'slug':'comp-sci-guide'}, ] posts = { 'About':[ {'title':'General', 'slug':'general', 'content':lorem}, {'title':'Exec', 'slug':'exec', 'content':lorem}, {'title':'Photos', 'slug':'photos', 'content':lorem}, {'title':'Docs', 'slug':'docs', 'content':lorem}, {'title':'Contact', 'slug':'contact', 'content':lorem}, ], 'Events':[ {'title':'Upcoming', 'slug':'upcoming', 'content':lorem}, {'title':'Frosh Week', 'slug':'frosh-week', 'content':lorem}, {'title':'Workshops', 'slug':'workshops', 'content':lorem}, ], 'Projects':[ {'title':'Hack Time', 'slug':'hack-time', 'content':lorem}, {'title':'Dev Tools', 'slug':'dev-tools', 'content':lorem}, {'title':'Team Names', 'slug':'team-names', 'content':lorem}, {'title':'CSSS Github', 'slug':'csss-github', 'content':lorem}, ], 'Comp Sci Guide':[ {'title':'Course Map', 'slug':'course-map', 'content':lorem}, {'title':'Software', 'slug':'software', 'content':lorem}, {'title':'Co-op', 'slug':'co-op', 'content':lorem}, ], } announcements = [ {'title':'First Thing', 'author':'Corbettron9000','slug':'first-thing','content':lorem,'created':datetime.now()}, {'title':'Second Thing', 'author':'Colintron9000','slug':'second-thing','content':lorem,'created':datetime.now()}, {'title':'Third Thing', 'author':'Sidtron9000','slug':'third-thing','content':lorem,'created':datetime.now()}, {'title':'Fourth Thing', 'author':'Kennethtron9000','slug':'fourth-thing','content':lorem,'created':datetime.now()}, {'title':'Fifth Thing', 'author':'Jordantron9000','slug':'fifth-thing','content':lorem,'created':datetime.now()}, ] # Create the Categories for category in categories: try: c = Category(**category) c.save() self.stdout.write(category['name'] + ' category created') # Create the Posts for post in posts[category['name']]: try: p = Post(**post) p.category = c p.save() self.stdout.write(post['title'] + ' post created') except IntegrityError: self.stdout.write(post['title'] + ' post skipped') except IntegrityError: self.stdout.write(category['name'] + ' category skipped') self.stdout.write('Skipping all Posts in ' + category['name']) # Create the Announcements for announcement in announcements: try: a = Announcement(**announcement) a.save() self.stdout.write(announcement['title'] + ' announcement created') except IntegrityError: self.stdout.write(announcement['title'] + ' announcement skipped')
class CommentEmailTest(TestCase): fixtures = ['test-data/profile.json'] def setUp(self): self.author = User.objects.get(username='******') self.sooty = User.objects.get(username='******') listing = Listing.objects.all()[0] self.p = Post(title='New Post', text='A sentence that is long enough to go to the digest', listing=listing, author=self.author, name='new-post') self.p.save() # Clear pigeon/mail created from adding a Post deploy_pigeons() mail.outbox = [] self.counter = 1 def new_comment(self, target, user): comment = comments.get_model()() comment.content_object = target comment.site = Site.objects.get_current() comment.user = user comment.comment = strip_tags("A new comment %d" % self.counter) self.counter += 1 comment.submit_date = datetime.datetime.now() comment.is_public = True comment.is_removed = False comment.save() return comment def test_comment_can_be_seen(self): j = User.objects.get(username='******') listing = Listing.objects.get(key='staff') p = Post(title='New Post 2', text='A sentence that is long enough to go to the digest', listing=listing, author=j, name='new-post-2') p.save() comment = self.new_comment(p, j) self.assertFalse(comment.can_be_seen_by(self.sooty)) def test_author_comments_no_email(self): """ Comment by author sends no email to author """ self.new_comment(self.p, self.author) # process pigeon post queue and check django mail outbox deploy_pigeons() self.assertEqual(len(mail.outbox), 0) def test_other_comments_author_emailed(self): """ Comment by other user, sends email to author """ self.new_comment(self.p, self.sooty) # process pigeon post queue and check django mail outbox deploy_pigeons() self.assertEqual(len(mail.outbox), 1) def test_author_comments_after_b_comments(self): """ Comment by author, after sooty user has commented, sends email to sooty only """ self.new_comment(self.p, self.sooty) # clear pigeons and outbox deploy_pigeons() mail.outbox = [] self.new_comment(self.p, self.author) deploy_pigeons() self.assertEqual(len(mail.outbox), 1) self.assertTrue(self.sooty.email, mail.outbox[0].to)