<s> import json <EOL> import unittest <EOL> from nose . tools import ( <EOL> assert_dict_contains_subset , <EOL> assert_equal , <EOL> assert_in , <EOL> assert_true , <EOL> ) <EOL> from _fixtures import PolarisUserFixture <EOL> _load_json = lambda rv : json . loads ( rv . data . decode ( rv . charset ) ) <EOL> class PolarisChartTest ( PolarisUserFixture ) : <EOL> basic_chart = { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:source>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : True <EOL> } <EOL> def new_basic_chart ( self ) : <EOL> data = json . dumps ( self . basic_chart ) <EOL> headers = { "<STR_LIT>" : self . csrf } <EOL> rv = self . app . post ( "<STR_LIT>" , data = data , <EOL> headers = headers , content_type = '<STR_LIT:application/json>' ) <EOL> return _load_json ( rv ) <EOL> def test_chart_list ( self ) : <EOL> res = _load_json ( self . app . get ( "<STR_LIT>" ) ) <EOL> assert_true ( isinstance ( res , dict ) ) <EOL> assert_true ( isinstance ( res [ "<STR_LIT>" ] , list ) ) <EOL> def test_chart_new ( self ) : <EOL> chart1 = self . new_basic_chart ( ) [ "<STR_LIT>" ] <EOL> assert_dict_contains_subset ( self . basic_chart , chart1 ) <EOL> rv = self . app . get ( "<STR_LIT>" . format ( chart1 [ "<STR_LIT:id>" ] ) ) <EOL> assert_equal ( rv . status_code , <NUM_LIT:200> ) <EOL> chart2 = _load_json ( rv ) [ "<STR_LIT>" ] <EOL> assert_equal ( chart1 , chart2 ) <EOL> charts = _load_json ( self . app . get ( "<STR_LIT>" ) ) [ "<STR_LIT>" ] <EOL> assert_in ( chart1 , charts ) <EOL> def test_chart_delete ( self ) : <EOL> chart = self . new_basic_chart ( ) [ "<STR_LIT>" ] <EOL> headers = { "<STR_LIT>" : self . csrf } <EOL> resource = "<STR_LIT>" . format ( chart [ "<STR_LIT:id>" ] ) <EOL> rv = self . app . delete ( resource , headers = headers ) <EOL> assert_equal ( rv . status_code , <NUM_LIT:200> ) <EOL> rv = self . app . get ( resource ) <EOL> assert_equal ( rv . status_code , <NUM_LIT> ) <EOL> def test_chart_edit ( self ) : <EOL> new_chart = { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : { "<STR_LIT:x>" : <NUM_LIT:10> } <EOL> } <EOL> chart = self . new_basic_chart ( ) [ "<STR_LIT>" ] <EOL> chart . update ( new_chart ) <EOL> headers = { "<STR_LIT>" : self . csrf } <EOL> resource = "<STR_LIT>" . format ( chart [ "<STR_LIT:id>" ] ) <EOL> rv = self . app . put ( resource , data = json . dumps ( chart ) , <EOL> headers = headers , content_type = '<STR_LIT:application/json>' ) <EOL> assert_equal ( rv . status_code , <NUM_LIT:200> ) <EOL> new_chart2 = _load_json ( rv ) [ "<STR_LIT>" ] <EOL> assert_equal ( chart , new_chart2 ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
