Killer Web Development

by Marco Laspe

8.1 The Model for Tukker Posts

The model for Tukker posts is fairly simple; we defined it already in section 3.1. Let's recall the model

[bild]

The model has 3 fields:

an id that it created be web2py automaticly; no work for us here the actual message; the message has a max length of 300 chars long (remember: twice as good as Twitter) and has a minimum of 1 char the user_id of the user who wrote the Tukker message; the user must be present in the user table of our database Let's remember the relationships between the user and his messages: A user can write 0 to infinity message, but one message has (or ist owned by) exactly one user.

[bild]

With this information we can create our database conditions and our tests.

Testing the Message-Form

Again we will write test first. This time we will test the Tukker form, where you can write Tukker messages.

Luckily we don't need to build a new test file. We can build our tests on the fts/test_profile.py file.

Before the tearDown() method add the following code:

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
def test_user_can_create_message(self):
# John looks for the message form
message = self.browser.find_element_by_name("message")

# Then he enters a message 280 chars long
message.send_keys("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum ")

# He clicks the submit button
submit_button = self.browser.find_element_by_css_selector("#submit_record__row input")
register_button.click()

# John reads his message
message_one = self.find_element_by_id("message_1")
self.assertEqual('Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum ', message_one.text)

j
If you understand the last tests this test shouldn't challenge you either. It simply tests if you can submit a Tukker message, that is 280 chars long.

Wikipedia says

Lorem Ipsum

In publishing and graphic design, lorem ipsum is a placeholder text (filler text) commonly used to demonstrate the graphic elements of a document or visual presentation, such as font, typography, and layout, by removing the distraction of meaningful content. The lorem ipsum text is typically a section of a Latin text by Cicero with words altered, added, and removed that make it nonsensical and not proper Latin.

Now we need to enable the Tukker-App to pass this test. Therefore we must create the model and then we need to extend the profile function in the default.py controller.


Books often read by web2py and Python experts:

Comments

Leave a Reply

Required fields are marked *.