<s> import six <EOL> from st2common . models . system . common import ResourceReference <EOL> from st2tests . fixturesloader import FixturesLoader <EOL> from tests import FunctionalTest <EOL> http_client = six . moves . http_client <EOL> TEST_FIXTURES = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } <EOL> TEST_FIXTURES_RULES = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> } <EOL> FIXTURES_PACK = '<STR_LIT>' <EOL> class TestRuleViewController ( FunctionalTest ) : <EOL> fixtures_loader = FixturesLoader ( ) <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> super ( TestRuleViewController , cls ) . setUpClass ( ) <EOL> models = TestRuleViewController . fixtures_loader . save_fixtures_to_db ( <EOL> fixtures_pack = FIXTURES_PACK , fixtures_dict = TEST_FIXTURES ) <EOL> TestRuleViewController . ACTION_1 = models [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> TestRuleViewController . TRIGGER_TYPE_1 = models [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> file_name = '<STR_LIT>' <EOL> rules = TestRuleViewController . fixtures_loader . save_fixtures_to_db ( <EOL> fixtures_pack = FIXTURES_PACK , fixtures_dict = TEST_FIXTURES_RULES ) [ '<STR_LIT>' ] <EOL> TestRuleViewController . RULE_1 = rules [ file_name ] <EOL> def test_get_all ( self ) : <EOL> resp = self . app . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_int , http_client . OK ) <EOL> self . assertEqual ( len ( resp . json ) , <NUM_LIT:3> ) <EOL> def test_get_one_by_id ( self ) : <EOL> rule_id = str ( TestRuleViewController . RULE_1 . id ) <EOL> get_resp = self . __do_get_one ( rule_id ) <EOL> self . assertEqual ( get_resp . status_int , http_client . OK ) <EOL> self . assertEqual ( self . __get_rule_id ( get_resp ) , rule_id ) <EOL> self . assertEqual ( get_resp . json [ '<STR_LIT:action>' ] [ '<STR_LIT:description>' ] , <EOL> TestRuleViewController . ACTION_1 . description ) <EOL> self . assertEqual ( get_resp . json [ '<STR_LIT>' ] [ '<STR_LIT:description>' ] , <EOL> TestRuleViewController . TRIGGER_TYPE_1 . description ) <EOL> def test_get_one_by_ref ( self ) : <EOL> rule_name = TestRuleViewController . RULE_1 . name <EOL> rule_pack = TestRuleViewController . RULE_1 . pack <EOL> ref = ResourceReference . to_string_reference ( name = rule_name , pack = rule_pack ) <EOL> get_resp = self . __do_get_one ( ref ) <EOL> self . assertEqual ( get_resp . json [ '<STR_LIT:name>' ] , rule_name ) <EOL> self . assertEqual ( get_resp . status_int , http_client . OK ) <EOL> def test_get_one_fail ( self ) : <EOL> resp = self . app . get ( '<STR_LIT>' , expect_errors = True ) <EOL> self . assertEqual ( resp . status_int , http_client . NOT_FOUND ) <EOL> @ staticmethod <EOL> def __get_rule_id ( resp ) : <EOL> return resp . json [ '<STR_LIT:id>' ] <EOL> def __do_get_one ( self , rule_id ) : <EOL> return self . app . get ( '<STR_LIT>' % rule_id , expect_errors = True ) </s>
