레이블이 테스트고트님인 게시물을 표시합니다. 모든 게시물 표시
레이블이 테스트고트님인 게시물을 표시합니다. 모든 게시물 표시

2016년 3월 19일 토요일

클린코드를 위한 테스트 주도 개발 실습을 잠시 중단 3/20

잠시 중단 합니다. 

어느 부분까지 진행되었냐면 운명의시간? 기능테스트 실행중에 퍼소나 로그인 에서

홈페이지 로그인 부분에서 {{if user.email }} 여기서 로그인 되면 사용자 정보가 navbar에 변경이
되면서 로그아웃 이라는 글자로 바뀌고 로그인이 정상 완료 되어야되는데

세션에 로그인정보만 있고해당 if 분기에서 항상 false가 된다.


콘솔에서의 기능테스트후 로그를 보자

kyungtai@kyungtai-W65-67SF:~/workspace/python/second/superlists$ python3 manage.py test functional_tests.test_login

Creating test database for alias 'default'...
ETraceback (most recent call last):
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 138, in run
    self.finish_response()
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 180, in finish_response
    self.write(data)
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 274, in write
    self.send_headers()
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 332, in send_headers
    self.send_preamble()
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 255, in send_preamble
    ('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 453, in _write
    self.stdout.write(data)
  File "/usr/lib/python3.4/socket.py", line 394, in write
    return self._sock.send(b)
BrokenPipeError: [Errno 32] Broken pipe
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 57140)
Traceback (most recent call last):
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 138, in run
    self.finish_response()
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 180, in finish_response
    self.write(data)
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 274, in write
    self.send_headers()
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 332, in send_headers
    self.send_preamble()
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 255, in send_preamble
    ('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 453, in _write
    self.stdout.write(data)
  File "/usr/lib/python3.4/socket.py", line 394, in write
    return self._sock.send(b)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 141, in run
    self.handle_error()
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 368, in handle_error
    self.finish_response()
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 180, in finish_response
    self.write(data)
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 274, in write
    self.send_headers()
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 331, in send_headers
    if not self.origin_server or self.client_is_modern():
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 344, in client_is_modern
    return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/socketserver.py", line 305, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python3.4/socketserver.py", line 331, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.4/socketserver.py", line 344, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/local/lib/python3.4/dist-packages/django/core/servers/basehttp.py", line 129, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File "/usr/lib/python3.4/socketserver.py", line 673, in __init__
    self.handle()
  File "/usr/lib/python3.4/wsgiref/simple_server.py", line 133, in handle
    handler.run(self.server.get_app())
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 144, in run
    self.close()
  File "/usr/lib/python3.4/wsgiref/simple_server.py", line 35, in close
    self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------

======================================================================
ERROR: test_login_with_persona (functional_tests.test_login.LoginTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kyungtai/workspace/python/second/superlists/functional_tests/test_login.py", line 25, in test_login_with_persona
    self.wait_for_element_with_id('id_logout')
  File "/home/kyungtai/workspace/python/second/superlists/functional_tests/test_login.py", line 42, in wait_for_element_with_id
    lambda b: b.find_element_by_id(element_id)
  File "/usr/local/lib/python3.4/dist-packages/selenium/webdriver/support/wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Stacktrace:
    at FirefoxDriver.prototype.findElementInternal_ (file:///tmp/tmpu0bpg4xr/extensions/fxdriver@googlecode.com/components/driver-component.js:10723)
    at fxdriver.Timer.prototype.setTimeout/<.notify (file:///tmp/tmpu0bpg4xr/extensions/fxdriver@googlecode.com/components/driver-component.js:623)



2016년 3월 17일 목요일

클린코드를위한 테스트 주도개발 3/18

책 330페이지의

authenticate 모킹을 통한 뷰테스트

에서 (앞에서 __init__.py를 이용해서 test폴더를 만들었으리라 믿는다. 기본 tests.py를 지우는 것도 잊지말자)

라고 써있다. 한 5분 고민이 되었다 (난 그걸 이용해서 만드는게 뭔지 모르겠는데?)

예전  기능테스트를 3가지로 분류한것처럼 유닛테스트를 3가지로 분류한적이있다.

그때 mv 명령어를 사용해서 lists/tests/test_views, test_models,test_forms)

이렇게 나누었었다.  그때 제일먼저 lists/tests/__init__.py 파일부터 touch명령어로 만들어
줬었다. 그걸말하는듯하다.

그렇게 해주고 accounts/tests/test_views.py,__init__.py를 만들고 나서 테스트를 실행해보면

ImportError: 'tests' module incorrectly imported from '/home/kyungtai/workspace/python/second/superlists/accounts/tests'. Expected '/home/kyungtai/workspace/python/second/superlists/accounts'. Is this module globally installed?

이런 에러가 나온다. 뭐지? 모듈을 잘못 임포트했다거?

한참을 검색해보면 저 괄호속 내용이 무얼말하는건지 감이온다. 기본 tests.py를 지우지 않으면 에러가 발생한다.

왜냐하면 기본 tests.py 안에는 

from django.test import TestCase

# Create your tests here.

라는 내용이 있다. 내가 테스트하려는 test_views.py 에도 django.test에서 TestCase를 임포트 한다  어?;; 똑같은데?

http://stackoverflow.com/questions/25775185/django-test-runner-fails-in-virtualenv-on-ubuntu
의 마지막 3줄을 읽어보니 알거같다.

역시 아침에 일어나면 머리가 상쾌해져서 문제 파악이 쉽다 ^^



추가
requirements.txt에 pip 내용을 추가해야할땐
pip freeze > requirements.txt
빼먹으면 다음 배포처리가 동작 안한다는...


+ 덧

아 제가 +1 해버렸네요 G+1 버튼이 작성자인 제가 눌러도 올라가는군요 :)
제가 작성한 글을 제가 추천하다니 아침부터 몹시 부끄러운 하루입니다 ㅋㅋ

2016년 3월 15일 화요일

클린코드를위한 테스트 주도개발 3/16


전에 클린코드를위한 테스트 주도개발 의 내용 2부까지 실습했었다.

superlist.gq 이쪽 도메인에 올렸고 깃에도 작업한것을 착실히? 올려뒀었다.

그. 런. 데

운영서버 메인 페이지의 무엇이 문제인지 input 텍스트가 안보였던거다
소스내용도 보고 깃에 문제가 있는게 분명할거라고 ..(그때 이해가 안되서 checkout 몇번 해서 책에있는 내용 그대로 다시 코딩하고 날리고 몇번을 반복했다 )

뭐가 문제인지 정확히 몰라 그래 다시하자 그래서 오늘이 수요일이니까 지난주 토요일부터 오늘까지 다시 또 했던짓 또했다.

그리고 staging서버에 올렸는데 잘 올라간다 문제가 없다

그리고 다시 운영서버에 올렸는데 또 텍스트 박스가 없다

또없다...

또 input text 이게 없는거다

뭐지 ㅋ 뭐가문제지?

스테이징서버에는 잘되고 운영서버에는 안되는 무엇 ㅋㅋ

알고보니 sudo restart gunicorn-superlist.gq 이걸 안했다

구니콘 ? (그린 유니콘이랜다) 을 재실행 안했다.

설정 다해두고 서버를 재시작 안하니 인풋박스가 안보이는 그런 문제였다.

명령한줄 안하면 책의 280페이지에 달하는 내용을 아무리 다시 코딩해도 안되는거지

응 그런거지!

2016년 3월 10일 목요일

클린코드를위한 테스트 주도개발

12장 마지막 장에서  뭔가 계속 오류가 나기도 하고 이해가 안가서
git checkout 이전 두챕터정도 돌아가서 다시작성하고 그렇게 2~3번 했더니
깃이 꼬여버렸는지 detached head  라고 계속 나온다.

보니까 브랜치명을 안달아주고 체크아웃 하고나서 커밋 커밋 하니까 뭔가 꼬인듯 하다

http://pcottle.github.io/learnGitBranching/

여기 사이트를 보니까 깃에대해 실습을 할수 있는 좋은 곳이 있더라.

이미 물은 엎질러졌고 답답한 마음에 실습하고 있으니 왠지 더답답 ㅠ

서버에 올린 사이트에는 텍스트 박스가 안나온다. 그런데 로컬에서 테스트하면
정상 작동된다. 로컬에 있는 내용을 깃에 올렸고 깃에 있는 내용이 서버로 들어간다

로컬 -> 깃 -> 서버

로컬에서는 텍스트 박스가 정상적으로 보이며 기능테스트, 유닛테스트 정상 동작하는 소스이다.
그내용을 깃으로 올렸고 서버에 소스를 배포 했는데
서버에서는 텍스트 박스가 안나온다 form 안에 있어야되는데 왜안나오는지 알수가 없다.

git 주소는 https://github.com/sharpscar/python_tdd

서버 주소는 superlist.gq




===================================================


3/12

github 리파지토리를 날려버리고 다시 실습한다.
처음부터 다시 읽으면서 실습하는데 잦은 에러가 나를 반긴다

제일 처음 만난 에러는 장고 1.7과 1.9.1 ?  최근 쟝고 프레임웤에서는
render_to_string() 이 템플릿의 내용중에 csrf_token 내용까지 비교하는 문제가 있는듯하다.
여기에 시간을 많이 투자하는것은 낭비 과감히 1.7로 돌아간다 ~>

우선 인코딩 에러
Unicodwarning: Unicode equal comparison failed to convert both arguments to Unicode -...

usr/lib/python2.7/unittest/case.py:503: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if not first == second:

FE..
======================================================================
ERROR: test_home_page_returns_correct_html (lists.tests.HomePageTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kyungtai/workspace/python/second/superlists/lists/tests.py", line 43, in test_home_page_returns_correct_html
    self.assertEqual(response.content.decode(), expected_html)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xec in position 226: ordinal not in range(128)

======================================================================
FAIL: test_home_page_can_save_a_POST_request (lists.tests.HomePageTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kyungtai/workspace/python/second/superlists/lists/tests.py", line 55, in test_home_page_can_save_a_POST_request
    self.assertEqual(new_item.text, '신규 작업 아이템')
AssertionError: u'\uc2e0\uaddc \uc791\uc5c5 \uc544\uc774\ud15c' != '\xec\x8b\xa0\xea\xb7\x9c \xec\x9e\x91\xec\x97\x85 \xec\x95\x84\xec\x9d\xb4\xed\x85\x9c'

----------------------------------------------------------------------
Ran 4 tests in 0.005s

FAILED (failures=1, errors=1)
Destroying test database for alias 'default'...


이유는 한글은 UTF-8을 사용해서 코딩하는데 비교하면서 이게 오류가 나는듯하다

# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf8')

테스트 코드 상단에 붙여넣었더니 된다.


참고할만한 구글 그룹스
https://groups.google.com/forum/#!forum/obey-the-testing-goat-book

django template 한글 문서
https://django-document-korean.readthedocs.org/en/old_master/topics/templates.html


추가적으로 기능테스트 중.. 전에는 없었던 당혹스러운 버그? 라고 해야하나?
python3 functional_test.py 를 실행하면 전에는 쟝고 튜토리얼을 한번 해보고 가상환경으로 실행해서 몰랐는데 지금은 파이어폭스가 실행되지 않으면서

kyungtai@kyungtai-W65-67SF:~/workspace/python/second/superlists$ python3 functional_test.py
kyungtai@kyungtai-W65-67SF:~/workspace/python/second/superlists$ python3 functional_test.py 


이런식으로 명령 콘솔로 툭 떨어지는 상황이 나온다.. 지금은 별다른 해결방법을 못찾았다.  

2016년 3월 3일 목요일

파이썬을 이용한 클린코드를 위한 테스트 주도 개발 (참고)

연습중입니다 BJ퍼블릭에서 출판되었구요

난이도는 어렵지 않습니다. 파이썬을 모르는 상태에서 django girl 튜토리얼을 한번 쭈욱 따라한 후에 책 내용을 처음 ~ 113페이지까지 두번정도 따라해보았습니다.

기능테스트
 - 단위테스트
   - 최소 소스 변경

이런식으로 접근합니다. 기능테스트 테두리를 마련해놓고 테스트 성공시 리펙토링 (기능은 그대로 소스 내용만 변경) 다시 단위테스트 성공시 리펙토링 (기능은 그대로 소스만 변경)

한번에 하나씩 변경해 나갑니다. 테스트 고트님이 지켜보고 있으므로 ㅋㅋ




여기에 책의 내용을 실습하다가 변경된 사항이나 나중에 다시 찾아볼수도 있는 내용을 적어 볼까 합니다.



144페이지의  LiveServerTest ->  StaticLiveServerTestCAse로 교체하는 내용이 있습니다만

ImportError: cannot import name 'StaticLiveServerCase'

임포트 할수 없다고 나옵니다


 This was renamed to StaticLiveServerTestCase just before the 1.7 release (see #23374). Sorry for the confusion.

이름이 변경되었거든요; 
'StaticLiveServerCase ->  StaticLiveServerTestCase


3/7일 추가

간단히 만들어진 일정 어플리 케이션을 호스팅 서비스에 올리고 (저는 aws의 ec2 와 도메인은
my.freenom.com/ 여기를 활용했습니다.)

사이트는  메인/스테이징 서버 두개로 구성됩니다.

메인 :http://superlist.gq/
스테이징: http://superlist-staging.gq/

작년 프론트엔드 수업시에 팀프로젝트이후로 호스팅관련 설정(닷홈, 카페24)은
처음 해보는 작업이라 주말 이틀을 헤맸네요
aws인스턴스 3개정도 터미네이트 시키고 ㅋㅋ 다시만들었어요

요즘 나오는 프로비저닝? 배포?는 이렇게 번거롭게 하지 않는다고 그러는데 부딫쳐 봐야 약간 느낌이 오는듯 합니다

작업하면서 장애물이 많았어요 낯선툴들이 많네요( fabric, gunicorn )

에러가많아 힘들었지만 오늘 아침 일어나서 다시 해보니까 잘되네요 ^^



gemini 를 쓰면서 느끼는점