วันพฤหัสบดีที่ 29 มกราคม พ.ศ. 2558

Chapter 4 : What Are We Doing with All These Tests?

from Chapter 3 :

Using Selenium to Test User Interactions

tests[RUN SERVER FIRST]


output result

Open up functional_tests.py Change to same like this :


Run tests again :

Output Result

TIME TO GIT


Next , create template , run this command first

then Create directory in lists/templates/home.html and create home.html at lists/templates/home.html and in home.html has code

and change code in lists/views.py in same like this


RUN TESTS AGAIN

output result

" Django can't find the template "

and then fix INSTALLED_APPS area in superlists/settings.py and change to same like this


RUN TESTS AGAIN

output result

" self.assertTrue(response.content.endswith(b'</html>'))
AssertionError: False is not true "


Let's fix that [get pass] in lists/tests.py in method test_home_page_returns_correct_html

now RUN TESTS AGAIN

output result
OK !!

TIME TO GIT


A little more in lists/templates/home.html. change code to same like this :


Run functional_tests.py again :

output result
then Add method in functional_tests.py

run the FT again : output result

NOW TIME TO GIT


----------------------------
ABOUT TDD PROCESS?
pic credit

And about TDD process with functional and unit tests
pic credit

END Chapter 4





Chapter 3 : Testing a Simple Home Page with Unit Tests

"Our First Django App, and Our First Unit Test"

First time use command in "superlists" directory from Chapter 2



and it create a folder at superlists/lists
 
     superlists/
     ├── db.sqlite3
     ├── functional_tests.py
     ├── lists
     │   ├── admin.py
     │   ├── __init__.py
     │   ├── migrations
     │   │   └── __init__.py
     │   ├── models.py
     │   ├── tests.py
     │   └── views.py
     ├── manage.py
     └── superlists
         ├── __init__.py
         ├── __pycache__
         ├── settings.py
         ├── urls.py
         └── wsgi.py
 
and next Unit Testing in Django , Open up the new file at lists/tests.py then edit to this code 


and now let's to run manage.py with this command


Output Result

Then commit this git with this commands


and next , Django’s MVC, URLs, and View Functions
in Django’s workflow goes something like this:
  1. An HTTP request comes in for a particular URL.
  2. Django uses some rules to decide which view function should deal with the request (this is referred to as resolving the URL).
  3. The view function processes the request and returns an HTTP response
So we want to test two things:
  • Can we resolve the URL for the root of the site (“/”) to a particular view function we’ve made?
  • Can we make this view function return some HTML which will get the functional test to pass? 
At first Open up lists/tests.py, and change to something like this:



Output Result


" ImportError: cannot import name 'home_page' " 

Solution : We can’t import home_page from lists.views? OK, let’s fix that—and only that. In lists/views.py:


Let’s run the tests again with this command:


Output Result


 next , Django uses a file called urls.py to define how URLs map to view functions. and change it to same like this:


Then , Run the unit tests again, with


Output Result

the dot-notation superlists.views.home doesn’t point to a real view. Let’s fix that, by pointing it towards our placeholder home_page object, which is inside lists, not superlists (file : superlists/urls.py)
 

And run the tests again: Output Result

The unit tests have made the link between the URL / and the home_page = None in lists/views.py, and are now complaining that home_page isn’t a callable; ie, it’s not a function. Now we’ve got a justification for changing it from being None to being an actual function. Every single code change is driven by the tests. Back in lists/views.py:


and the last run with command :

Output Result


and TIME TO GIT


NEXT ,Unit Testing a View
Open up lists/tests.py, and add a new test method.


Let’s run the unit tests now and see how we get on ... with command :

Output Result

" TypeError: home_page() takes 0 positional arguments but 1 was given "

now,Change code in lists/views.py
 

Tests again: Output Result
" self.assertTrue(response.content.startswith(b'<html>')) AssertionError: False is not true "

Coding Again Fix return area:

 
Tests Again : Output Result


" AssertionError: b'<title>To-Do lists</title>' not found in b'<html>' "

AND Coding Again Fix return area:

 
Tests Again : Output Result

And Time to GIT


and the last : try to typing git log



Summary

  Useful Commands and Concepts

-----END-----
credit  :  http://chimera.labs.oreilly.com/books/1234000000754/ch03.html#_urls_py

วันพฤหัสบดีที่ 22 มกราคม พ.ศ. 2558

HTML Table from .csv file and Sorting with Python

: My Concept :
1. Import file in Local Directory

2. Split and Collect in each variables for showing in HTML table
3. User can choose menu , How to sorting? (by Number or By Student ID)
4. Show HTML table


-สามารถเลือกได้ว่า ต้องการให้โชว์ตารางการจัดเรียงแบบไหน (มีให้เลือก by Number,by Student ID) 

Result 

   Show Only
 

   Show Only: Source Code



---------------------------------------
  Show and Menu :




  Show and Menu : Source Code




Extend Link :
https://docs.python.org/2/library/functions.html
https://docs.python.org/2/tutorial/datastructures.html#more-on-lists
http://www.tutorialspoint.com/python/list_index.htm
http://stackoverflow.com/questions/1217251/python-sorting-a-dictionary-of-lists

and Tag for Google : List , Dictionary , csv in python , UTF-8 , Radio Button , Sorting , HTML Table , HTML Tag

วันจันทร์ที่ 19 มกราคม พ.ศ. 2558

Show Directory that you want

: My Concept :
1. Input some text ,path of directory that you want to see

2. Show any files and any directory in your path on your computer

-สามารถใส่ Directory ที่ต้องการ แล้วผลลัพธ์จะได้ว่า มีไฟล์อะไรบ้างอยู่ใน Directory นั้นๆ

Result 



Input name of path "/home/watsize/A"

Show all files and directory in the path that you input

If you input wrong path or something is not found


It's show you only path text (not have anymore)
Source Code "testDirectory.cgi"



Source Code "result.cgi"


:: Addition ::
Describe : Show path in any case

วันอาทิตย์ที่ 18 มกราคม พ.ศ. 2558

Writing CGI using Python

: My Concept :
1. Create first file .XXX (anything) in "cgi-bin" directory for Input Message Box to send message

2. Create second fiel .XXX (anything) in same directory for Show Result and Input Message Box to send message again

-สามารถส่งค่า text ไป และเรียกใช้งานอีกไฟล์ได้-

Result 
Show Text and Input Area



Input "Text 1"

The Result when press 'enter' it show message that you input

Then you can Insert another input in 'Input Next Box'

When you click 'Submit' it show Previous message that you insert

Source Code : File 1 "send_text1.xyz"

Source Code : File 2 "send_text2.cgi"

:: Addition ::
Describe : The page and the encoded information are separated by the ? character.

First is "first_name" variable
Second is "last_name" variable

and both use in print area

วันพุธที่ 14 มกราคม พ.ศ. 2558

Python Simple Web Server

How to test : I'm using command "python -m SimpleHTTPServer" via Terminal in Ubuntu  

and I create a simple html file "test.html" via VI Editor and go to 0.0.0.0:8000 and search that file for opening (shortcut is "0.0.0.0:8000/test.html")




The Result : 
 for some trick is using Tryit Editor v2.3 by w3scools.com for html virtual compile html code

Source Code : 

Test python in Terminal

Test create and compile and run Python file in Terminal

The Result  ! !

source code : 

วันจันทร์ที่ 12 มกราคม พ.ศ. 2558

Hello User

Hello ... Building Software II Blog




by : Chinnawat Chimdee
ID: 56-010126-3006-0 
contact : kills2war@gmail.com

สวัสดี...
pics credit : Link !