Example #1
0
    def test_multiple_blog_entry_present_with_earliest_updated_and_another_created_after___the_latest_created_is_the_entry(
            self):
        Entry(
            title="Test Title",
            content="Test Content",
            owner=self.owner,
        ).save()

        Entry(
            title="Second Test Title",
            content="Second Test Content",
            owner=self.owner,
        ).save()

        entry = Entry.objects.get(title="Test Title")
        entry.title = "Modified Test Title"
        entry.save()

        Entry(
            title="Third Test Title",
            content="Third Test Content",
            owner=self.owner,
        ).save()

        self.driver.get(self.live_server_url)

        self.assertEqual("Third Test Title",
                         wait_for_element(self.driver, By.ID, "title").text)
Example #2
0
    def test_two_blog_entries_created_one_is_modified___both_entries_are_listed_in_the_correct_order_with_modified_first(
            self):
        Entry(
            title="First Test Entry",
            content="First Test Content",
            owner=self.owner,
        ).save()

        Entry(
            title="Second Test Entry",
            content="Second Test Content",
            owner=self.owner,
        ).save()

        entry = Entry.objects.get(title="First Test Entry")
        entry.title = "Modified Test Entry"
        entry.save()

        self.driver.get(self.live_server_url + "/browse")

        entries = wait_for_all_elements(self.driver, By.CLASS_NAME,
                                        "blog-listing-entry")
        num_entries = len(entries)
        titles = [
            entry.find_element(By.CLASS_NAME, "title").text
            for entry in entries
        ]

        self.assertEqual(2, num_entries)
        self.assertEqual("Modified Test Entry", titles[0])
        self.assertEqual("Second Test Entry", titles[1])
    def test_two_objects_created_accessed_in_reverse_order___result_is_second_created_object(self):
        Entry(
            title="First Title",
            content="First Content",
            owner=self.owner,
        ).save()

        Entry(
            title="Second Title",
            content="Second Content",
            owner=self.owner,
        ).save()

        self.assertEqual(Entry.objects.get(title="Second Title"), first_or_none(Entry.objects.all().order_by("-id")))
    def test_two_objects_created___result_is_first_created_object(self):
        Entry(
            title="First Title",
            content="First Content",
            owner=self.owner,
        ).save()

        Entry(
            title="Second Title",
            content="Second Content",
            owner=self.owner,
        ).save()

        self.assertEqual(Entry.objects.get(title="First Title"), first_or_none(Entry.objects.all()))
Example #5
0
    def test_single_blog_entry_created_and_modified___published_time_is_present_in_listing_entry(
            self, mock_now):
        def now_time():
            for date in (datetime(2013, 2, 3, 4, 5, 6, tzinfo=utc),
                         datetime(2014, 7, 8, 9, 10, 11, tzinfo=utc)):
                yield date

        mock_now.side_effect = now_time()

        Entry(
            title="Test Post Title",
            content="Test Post Content",
            owner=self.owner,
        ).save()

        entry = Entry.objects.all()[0]
        pk = entry.id
        entry.title = "Modified Title"
        entry.save()

        self.driver.get(self.live_server_url + "/browse")
        publish_time = wait_for_element(
            self.driver, By.CSS_SELECTOR,
            ".blog-listing-entry .publish-time").text

        self.assertEqual(
            "Published: 03 Feb 2013 04:05:06 (Edit: 08 Jul 2014 09:10:11)",
            publish_time)
Example #6
0
def create_update(entry_id=None):
    errors = None
    if entry_id != None:
        entry = Entry.query.filter_by(id=entry_id).first_or_404()
        form = EntryForm(obj=entry)
        if request.method == 'POST':
            if form.validate_on_submit():
                form.populate_obj(entry)
                db.session.commit()
            else:
                errors = form.errors
    else:
        form = EntryForm()
        if request.method == 'POST':
            if form.validate_on_submit():
                entry = Entry(
                    title=form.title.data,
                    body=form.body.data,
                    is_published=form.is_published.data
                )
                db.session.add(entry)
                db.session.commit()
            else:
                errors = form.errors
    return form, errors
Example #7
0
def get_entries(entry_id):
    errors = None
    if entry_id != 0:
        entry = Entry.query.filter_by(id=entry_id).first_or_404()
        form = EntryForm(obj=entry)
        flash_mess = f'Edytowano post {entry.title} na blogu.'

    else:
        form = EntryForm()
        entry = Entry(
            title=form.title.data,
            body=form.body.data,
            is_published=form.is_published.data
            )
        flash_mess = f'Dodano post {entry.title} na bloga.'
        

    if request.method == 'POST':
        if form.validate_on_submit():
            if entry_id != 0:
                form.populate_obj(entry)
            else:
                db.session.add(entry)
            db.session.commit()
            flash(flash_mess)
            return redirect(url_for("index"))
        else:
            errors = form.errors

    return render_template("entry_form.html", form=form, errors=errors)
Example #8
0
def create_or_edit_entry(**kwargs):
    # GET
    entry_id = kwargs.pop('entry_id', None)
    form = EntryForm()
    entry = None
    errors = None
    if entry_id:
        entry = Entry.query.filter_by(id=entry_id).first_or_404()
        form = EntryForm(obj=entry)

    # POST
    if request.method == 'POST':
        if form.validate_on_submit():
            if entry_id:
                form.populate_obj(entry)
                db.session.commit()
                flash(
                    'Zmiany w poscie zostały zapisane. '
                    'Aby wyświetlić go na stronie głównej pamiętaj aby zaznaczyć "Wpis opublikowany"'
                )
            else:
                entry = Entry(title=form.title.data,
                              body=form.body.data,
                              is_published=form.is_published.data)
                db.session.add(entry)
                db.session.commit()
                flash(
                    'Nowy post został dodany. '
                    'Aby wyświetlić go na stronie głównej pamiętaj aby zaznaczyć "Wpis opublikowany"'
                )
        else:
            errors = form.errors
    return render_template('entry_form.html', form=form, errors=errors)
Example #9
0
def create_update(entry_id=None):
    errors = None
    if entry_id is None:
        form = EntryForm()
        if request.method == 'POST':
            if form.validate_on_submit():
                entry = Entry(
                    title=form.title.data,
                    body=form.body.data,
                    is_published=form.is_published.data
                )
                db.session.add(entry)
                db.session.commit()
                flash('The post has been successfully added!')
                return redirect(url_for("index"))
            else:
                errors = form.errors
    elif entry_id != 0:
        entry = Entry.query.filter_by(id=entry_id).first_or_404()
        form = EntryForm(obj=entry)
        if request.method == 'POST':
            if form.validate_on_submit():
                form.populate_obj(entry)
                db.session.commit()
                flash('The post has been successfully changed!')
                return redirect(url_for("index"))
            else:
                errors = form.errors
    return render_template("entry_form.html", form=form, errors=errors)
Example #10
0
def seed():
    content = """Lorem ipsum dolor sit amet, consectetur adipisicing 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."""

    for i in range(25):
        entry = Entry(title="Test Entry #{}".format(i), content=content)
        session.add(entry)
    session.commit()
Example #11
0
def test_add2(req):
    #查询实体
    entry2 = Entry(id=7)
    blog1 = Blog.objects.create(name="博客aaa", entry=entry2)
    blog2 = Blog.objects.create(name="博客bbb", entry=entry2)

    return HttpResponse("<h2>创建成功 2</h2>")
Example #12
0
def create_edit_entry(entry_id=0):
    errors = None
    if entry_id == 0:
        entry_form = EntryForm()
    else:
        entry = Entry.query.filter_by(id=entry_id).first_or_404()
        entry_form = EntryForm(obj=entry)

    if request.method == "POST":
        if request.form["btn"] == "Save":
            if entry_form.validate_on_submit():
                if entry_id == 0:
                    entry = Entry(title=entry_form.title.data,
                                  body=entry_form.body.data,
                                  is_published=entry_form.is_published.data)
                    db.session.add(entry)
                else:
                    entry_form.populate_obj(entry)
            else:
                errors = entry_form.errors
                flash('Nie wpowadzono zmian', 'danger')

        if request.form["btn"] == "Cancel":
            return redirect(url_for("index"))

        db.session.commit()
        flash('Zmiany dodane pomyślnie', 'success')
        return redirect(url_for("index"))

    return render_template("entry_form.html",
                           entry_form=entry_form,
                           errors=errors)
Example #13
0
def entry(entry_id=None):
    if entry_id is None:
        form = EntryForm()
        errors = None
        if request.method == "POST":
            if form.validate_on_submit():
                entry = Entry(
                    title = form.title.data,
                    body = form.body.data,
                    is_published = form.is_published.data
                )
                db.session.add(entry)
                db.session.commit()
                flash(f'Dodano wpis {form.title.data} do bloga!')
            else:
                errors = form.errors
        return render_template("entry_form.html", form=form, errors=errors)
    else:
        entry = Entry.query.filter_by(id=entry_id).first_or_404()
        form = EntryForm(obj=entry)
        errors = None
        if request.method == 'POST':
            if form.validate_on_submit():
                form.populate_obj(entry)
                db.session.commit()
                flash(f'Zmieniono wpis {form.title.data}')
            else:
                errors = form.errors
        return render_template("entry_form.html", form=form, errors=errors)
Example #14
0
def add_post(id=None):
    if id:
        post = Entry.query.filter_by(id=id).first()
        form = EntryForm(
            data={
                'title': post.title,
                'body': post.body,
                'is_published': post.is_published
            })
        post.title = form.title.data
        post.body = form.body.data
        post.is_published = form.is_published.data
        if form.is_published.data:
            flash(f'Post "{form.title.data.upper()}" updated!')
        else:
            flash('Required box not checked. Post not added.')
    else:
        form = EntryForm()
        new_post = Entry(title=form.title.data,
                         body=form.body.data,
                         is_published=form.is_published.data)
        db.session.add(new_post)
        if form.is_published.data:
            flash(f'New post "{form.title.data.upper()}" added!')
        else:
            flash('Required box not checked. Post not added.')
    db.session.commit()
Example #15
0
 def handle(self, *args, **options):
     Blog.objects.all().delete()
     blog = Blog.objects.create(**BLOG_KWARGS)
     Author.objects.all().delete()
     Author.objects.bulk_create((Author(name=author) for author in AUTHOR_LIST))
     Entry.objects.all().delete()
     Entry.objects.bulk_create((Entry(blog=blog, **entry) for entry in ENTRY_LIST))
Example #16
0
def fake_posts(quantity=10):
    fake = Faker()
    for i in range(quantity):
        new_post = Entry(title=fake.sentence(),
                         body='\n'.join(fake.paragraphs(15)),
                         is_published=True)
        db.session.add(new_post)
        db.session.commit()
Example #17
0
 def simulate_add_entry(self, title, content):
     """
     define this method to add test data for edit and delete workflow
     """
     entry = Entry(title=title, content=content)
     session.add(entry)
     session.commit()
     return entry.id
Example #18
0
    def test_multiple_blog_entry_present___the_latest_created_is_the_entry(
            self):
        Entry(
            title="Test Title",
            content="Test Content",
            owner=self.owner,
        ).save()

        Entry(
            title="Second Test Title",
            content="Second Test Content",
            owner=self.owner,
        ).save()

        self.driver.get(self.live_server_url)

        self.assertEqual("Second Test Title",
                         wait_for_element(self.driver, By.ID, "title").text)
Example #19
0
def create_entry():
    form = EntryForm()
    entry_id = None
    entry = Entry(
        title=form.title.data,
        body=form.body.data,
        is_published=form.is_published.data
        )
    return create_or_edit_entry(entry_id, entry, form)
Example #20
0
def generate_entries(how_many=3):
    fake = Faker()

    for i in range(how_many):
        post = Entry(title=fake.sentence(),
                     body='\n'.join(fake.paragraphs(15)),
                     is_published=True)
        db.session.add(post)
    db.session.commit()
Example #21
0
 def create(self, form):
     entry = Entry(parent=Service.to_key(form.category.data))
     entry.title = form.title.data
     entry.summary = form.summary.data
     entry.post = form.post.data
     entry.tags = [Key(urlsafe=tag) for tag in form.tags.data]
     entry.slug = Service.slugify(entry.title)
     # entry.user = users.get_current_user()
     return entry.put()
Example #22
0
def create_test_blog_entry(author, title="default title"):
    test_post = Entry(
        date_created=timezone.localtime(timezone.localtime()),
        author=author,
        title=title,
        html_content="Don't read this..",
    )
    test_post.save()
    return test_post
Example #23
0
def create():
    form = EntryForm()
    if request.method == 'POST' and form.validate_on_submit():
        entry = form.save_entry(Entry(author=g.user))
        db.session.add(entry)
        db.session.commit()
        flash('Enrty {} has been created successfully'.format(entry.title),
              'success')
        return redirect(url_for('.detail', slug=entry.slug))
    return render_template('entries/create.html', form=form)
Example #24
0
 def handle(self, *args, **options):
     """Clear old instances and create new ones."""
     Blog.objects.all().delete()
     blog = Blog.objects.create(**BLOG_KWARGS)
     Author.objects.all().delete()
     Author.objects.bulk_create(
         Author(name=author) for author in AUTHOR_LIST)
     Entry.objects.all().delete()
     Entry.objects.bulk_create(
         Entry(blog=blog, **entry) for entry in ENTRY_LIST)
    def test_entry_is_created___creation_time_is_updated_to_current_time(self):
        Entry(
            title="Title",
            content="Entry Content",
            owner=self.owner,
        ).save()

        entry = Entry.objects.get(title="Title")

        self.assertEqual(datetime(2014, 1, 1, tzinfo=utc), entry.creation_time)
    def test_navigate_to_existing_item_not_logged_in___delete_button_is_not_present(self):
        Entry(
            title="Test Post Title",
            content="Test Post Content",
            owner=self.owner,
        ).save()

        pk = Entry.objects.all()[0].id

        self.driver.get(self.live_server_url + "/blog_entry/" + str(pk))
        self.assertTrue(wait_for_no_element(self.driver, By.ID, "delete-button"))
Example #27
0
 def handle(self, *args, **options):
     Blog.objects.all().delete()
     blog = Blog.objects.create(
         name='Recettes', lang='french',
         tagline='Des recettes dans toutes les langues!')
     Author.objects.all().delete()
     Author.objects.bulk_create(
         (Author(name=author) for author in AUTHOR_LIST))
     Entry.objects.all().delete()
     Entry.objects.bulk_create(
         (Entry(blog=blog, **entry) for entry in ENTRY_LIST))
Example #28
0
def entrys(form, entry_id=None, entry=None):
    if form.validate_on_submit():
        if entry_id == None:
            entry = Entry(title=form.title.data,
                          body=form.body.data,
                          is_published=form.is_published.data)
            db.session.add(entry)
        else:
            form.populate_obj(entry)
        db.session.commit()
    else:
        errors = form.errors
    def test_navigate_to_existing_item___published_time_is_present(self):
        Entry(
            title="Test Post Title",
            content="Test Post Content",
            owner=self.owner,
        ).save()

        pk = Entry.objects.all()[0].id

        self.driver.get(self.live_server_url + "/blog_entry/" + str(pk))
        publish_time = wait_for_element(self.driver, By.CLASS_NAME, "publish-time").text
        self.assertEqual("Published: 02 Jan 2014 21:12:00", publish_time)
    def test_navigate_to_existing_item___correct_content_is_present(self):
        Entry(
            title="Test Post Title",
            content="Test Post Content",
            owner=self.owner,
        ).save()

        pk = Entry.objects.all()[0].id

        self.driver.get(self.live_server_url + "/blog_entry/" + str(pk))
        content_text = wait_for_element(self.driver, By.ID, "content").text
        self.assertEqual("Test Post Content", content_text)