How to use log_error method in fMBT

Best Python code snippet using fMBT_python

gordon_360_tests_member.py

Source:gordon_360_tests_member.py Github

copy

Full Screen

...65 self.token_payload = { 'username':username, 'password':password, 'grant_type':'password' }66 def test(self):67 response = api.post(self.session, self.url, self.token_payload)68 if not response.status_code == 200:69 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))70 try:71 response.json()72 except ValueError:73 self.log_error('Expected Json, got {0}.'.format(response.text))74 else:75 if not 'access_token' in response.json():76 self.log_error('Expected access token in response, got {0}.'.format(response.json()))77# # # # # # # # # # # #78# EVENTS & CLAW TESTS #79# # # # # # # # # # # #80class get_all_events___regular_member(TestCase):81 """ Verify that a regular member can get all events by type_ID82 83 Pre-Conditions:84 Valid Authentication header85 Expectaions:86 Endpoint -- api/events/25Live/type/:Event_OR_Type_ID87 Expected Status Code -- 200 OK88 Expected Respones Body -- list of all events resources89 """90 def __init__(self, session=None):91 super().__init__(session)92 self.url = hostURL + 'api/events/25Live/type/10'93 def test(self):94 response = api.get(self.session, self.url)95 if not response.status_code == 200:96 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))97 try:98 response.json()99 except ValueError:100 self.log_error('Expected Json response body, got {0}.'.format(response.text))101 else:102 if not (type(response.json()) is list):103 self.log_error('Expected list, got {0}.'.format(response.json()))104class get_all_events_multiple___regular_member(TestCase):105 """ Verify that a regular member can get all events by multiple type_ID106 107 Pre-Conditions:108 Valid Authentication header109 Expectaions:110 Endpoint -- api/events/25Live/type/:Event_OR_Type_ID111 Expected Status Code -- 200 OK112 Expected Respones Body -- list of all events resources113 """114 def __init__(self, session=None):115 super().__init__(session)116 self.url = hostURL + 'api/events/25Live/type/10$11$12$14'117 def test(self):118 response = api.get(self.session, self.url)119 if not response.status_code == 200:120 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))121 try:122 response.json()123 except ValueError:124 self.log_error('Expected Json response body, got {0}.'.format(response.text))125 else:126 if not (type(response.json()) is list):127 self.log_error('Expected list, got {0}.'.format(response.json()))128class get_all_claw___regular_member(TestCase):129 """ Verify that a regular member can get all upcoming chapel events (category_ID = 85)130 131 Pre-Conditions:132 Valid Authentication header133 Expectaions:134 Endpoint -- api/events/25Live/CLAW135 Expected Status Code -- 200 OK136 Expected Respones Body -- list of all events resources137 """138 def __init__(self, session=None):139 super().__init__(session)140 self.url = hostURL + 'api/events/25Live/CLAW'141 def test(self):142 response = api.get(self.session, self.url)143 if not response.status_code == 200:144 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))145 try:146 response.json()147 except ValueError:148 self.log_error('Expected Json response body, got {0}.'.format(response.text))149 else:150 if not (type(response.json()) is list):151 self.log_error('Expected list, got {0}.'.format(response.json()))152class get_all_25Live___regular_member(TestCase):153 """ Verify that a regular member can get all events in 25Live under predefined categories154 155 Pre-Conditions:156 Valid Authentication header157 Expectaions:158 Endpoint -- api/events/25Live/All159 Expected Status Code -- 200 OK160 Expected Respones Body -- list of all events resources161 """162 def __init__(self, session=None):163 super().__init__(session)164 self.url = hostURL + 'api/events/25Live/All'165 def test(self):166 response = api.get(self.session, self.url)167 if not response.status_code == 200:168 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))169 try:170 response.json()171 except ValueError:172 self.log_error('Expected Json response body, got {0}.'.format(response.text))173 else:174 if not (type(response.json()) is list):175 self.log_error('Expected list, got {0}.'.format(response.json()))176class get_all_25Live_by_event_id___regular_member(TestCase):177 """ Verify that a regular member can get information on specific event on 25Live178 179 Pre-Conditions:180 Valid Authentication header181 Expectaions:182 Endpoint -- api/events/25Live/All183 Expected Status Code -- 200 OK184 Expected Respones Body -- list of all events resources185 """186 def __init__(self, session=None):187 super().__init__(session)188 self.url = hostURL + 'api/events/25Live/2911'189 def test(self):190 response = api.get(self.session, self.url)191 if not response.status_code == 200:192 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))193 try:194 response.json()195 except ValueError:196 self.log_error('Expected Json response body, got {0}.'.format(response.text))197 else:198 if not (type(response.json()) is list):199 self.log_error('Expected list, got {0}.'.format(response.json()))200class get_all_25Live_by_multiple_event_id___regular_member(TestCase):201 """ Verify that a regular member can get information on specific event on 25Live202 203 Pre-Conditions:204 Valid Authentication header205 Expectaions:206 Endpoint -- api/events/25Live/All207 Expected Status Code -- 200 OK208 Expected Respones Body -- list of all events resources209 """210 def __init__(self, session=None):211 super().__init__(session)212 self.url = hostURL + 'api/events/25Live/2911$2964$3030'213 def test(self):214 response = api.get(self.session, self.url)215 if not response.status_code == 200:216 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))217 try:218 response.json()219 except ValueError:220 self.log_error('Expected Json response body, got {0}.'.format(response.text))221 else:222 if not (type(response.json()) is list):223 self.log_error('Expected list, got {0}.'.format(response.json()))224class get_all_chapel___regular_member(TestCase):225 """ Verify that a regular member can get information on chapel events attended226 227 Pre-Conditions:228 Valid Authentication header229 Expectaions:230 Endpoint -- api/events/chapel/:user_name231 Expected Status Code -- 200 OK232 Expected Respones Body -- list of all events resources233 """234 def __init__(self, session=None):235 super().__init__(session)236 self.url = hostURL + 'api/events/chapel/sam.nguyen/'237 def test(self):238 response = api.get(self.session, self.url)239 if not response.status_code == 200:240 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))241 try:242 response.json()243 except ValueError:244 self.log_error('Expected Json response body, got {0}.'.format(response.text))245 else:246 if not (type(response.json()) is list):247 self.log_error('Expected list, got {0}.'.format(response.json()))248class get_all_chapel_by_term___regular_member(TestCase):249 """ Verify that a regular member can get information on chapel events attended by specific school term250 251 Pre-Conditions:252 Valid Authentication header253 Expectaions:254 Endpoint -- api/events/chapel/:user_name255 Expected Status Code -- 200 OK256 Expected Respones Body -- list of all events resources257 """258 def __init__(self, session=None):259 super().__init__(session)260 self.url = hostURL + 'api/events/chapel/matthew.felgate/FA16'261 def test(self):262 response = api.get(self.session, self.url)263 if not response.status_code == 200:264 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))265 try:266 response.json()267 except ValueError:268 self.log_error('Expected Json response body, got {0}.'.format(response.text))269 else:270 if not (type(response.json()) is list):271 self.log_error('Expected list, got {0}.'.format(response.json()))272# # # # # # # # # # #273# MEMBERSHIP TESTS #274# # # # # # # # # # #275# class get_all_memberships___regular_member(TestCase):276# """ Verify that a regular member can retrieve all memberships277# Pre-conditions:278# Valid Authentication Header.279# Expectations:280# Endpoint -- memberships/281# Expected Status code -- 200 Ok282# Expected Content -- List283# """284# def __init__(self, session=None):285# super().__init__(session)286# self.url = hostURL + 'api/memberships/'287# def test(self):288# response = api.get(self.session, self.url)289# print (response)290# print (api.get(self.session, self.url))291# if not response.status_code == 401:292# self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))293 294# try:295# response.json()296# except ValueError:297# self.log_error('Expected Json response, got >{0}<.'.format(response.text))298# else:299# if not (type(response.json()) is list):300# self.log_error('Response was not a list')301 302# class get_one_membership___regular_member(TestCase):303# """ Retrieve a specific membership resource.304# Pre-conditions:305# Valid Authentication header306# Expectations:307# Endpoint -- api/memberships/:id308# Expected Status Code -- 200 OK309# Expected Content -- A Json Object with a MembershipID attribute.310# """311# def __init__(self , session=None):312# super().__init__(session)313# self.url = hostURL + 'api/memberships/'314# self.membershipID = -1315 316# def setup(self):317# # Find a valid membership id318# response = api.get(self.session, self.url)319# if not response.status_code == 200:320# self.log_error('Error in setup for {0}. Expected 200 OK, got {1}.'.format(self.test_name, response.status_code))321# try:322# response.json()323# except ValueError:324# self.log_error('Error in setup for {0}. Expected json response body, got {1}.'.format(self.test_name, response.text))325# else:326# try:327# self.membershipID = response.json()[0]['MembershipID']328# self.url = self.url + str(self.membershipID)329# except KeyError:330# self.log_error('Error in setup for {0}. Expected MembershipID in response body, got {1}.'.format(self.test_name, self.response.json()))331# #exit(1) 332# def test(self):333# response = api.get(self.session, self.url)334# if not response.status_code == 200:335# self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))336# try:337# response.json()338# except ValueError:339# self.log_error('Expected Json response body, got {0}.'.format(response.text))340# else:341# if not ('MembershipID' in response.json()):342# self.log_error('Expected MembershipID in jsob object, got {0}.'.format(response.json()))343# class get_all_my_memberships___regular_member(TestCase):344# """ Verify that a regular member cannot fetch memberships associated with them. 345# This is because they can only see the members if they are part of the group.346 347# Pre-Conditions:348# Valid Authentication Header.349# Expectations:350# Endpoints -- api/memberships/student/:id351# Expected Status Code -- 401 Server Error352# Expected Reponse Content -- A list of json objects353# """354# def __init__(self , session=None):355# super().__init__(session)356# self.url = hostURL + 'api/memberships/student/' + str(my_id_number)357# def test(self):358# response = api.get(self.session, self.url)359# if not response.status_code == 401:360# self.log_error('Expected 401, got {0}.'.format(response.status_code))361# try:362# response.json()363# except ValueError:364# self.log_error('Expected Json response body, got {0}.'.format(response.text))365# else:366# if not (type(response.json()) is list):367# self.log_error('Response was not a list.')368 369# class get_all_memberships_for_someone_else___regular_member(TestCase):370# """ Verify that regular member can fetch someone else's memberships.371 372# Pre-Conditions:373# Valid Authentication Header.374# Authenticated as regular member.375# Expectations376# Endpoint -- api/memberships/student/:id377# Expected Status Code -- 200 OK.378# Expected Response Content -- A list of json objects.379# """380# def __init__(self , session=None):381# super().__init__(session)382# self.url = hostURL + 'api/memberships/student/' + str(random_id_number)383# def test(self):384# response = api.get(self.session, self.url)385# if not response.status_code == 200:386# self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))387# try:388# response.json()389# except ValueError:390# self.log_error('Expected Json response body, got {0}.'.format(response.text))391# else:392# if not (type(response.json()) is list):393# self.log_error('Response was not a list')394 395# class get_memberships_for_an_activity___regular_member(TestCase):396# """ Verify that a regular member can fetch memberships for an activity.397# Pre-Conditions:398# Valid Authentication Header.399# Expectations:400# Endpoint -- api/memberships/activity/:id401# Expected Status Code -- 200 OK402# Expected Response Content -- A list of json Objects.403# """404# def __init__(self , session=None):405# super().__init__(session)406# self.url = hostURL + 'api/memberships/activity/' + activity_code407# def test(self):408# response = api.get(self.session, self.url)409# if not response.status_code == 200:410# self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))411# try:412# response.json()413# except ValueError:414# self.log_error('Expected Json response body, got {0}.'.format(response.text))415# else:416# if not (type(response.json()) is list):417# self.log_error('Response was not a list.')418 419 420class get_leader_memberships_for_an_activity___regular_member(TestCase):421 """ Verify that a regular member can fetch all leaders for a specific activity.422 Pre-Conditions:423 Valid Authentication Header.424 Authenticated as regular member.425 Expectations:426 Endpoint -- api/memberships/activity/:id/leaders427 Expected Status Code -- 200 OK428 Expected Response Content -- A list of json objects.429 """430 def __init__(self , session=None):431 super().__init__(session)432 self.url = hostURL + 'api/memberships/activity/' + activity_code + '/leaders'433 def test(self):434 response = api.get(self.session, self.url)435 if not response.status_code == 200:436 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))437 try:438 response.json()439 except ValueError:440 self.log_error('Expected Json response body, got {0}.'.format(response.text))441 else:442 if not (type(response.json()) is list):443 self.log_error('Response was not a list.')444 445# class post_valid_membership___regular_member(TestCase):446# """ Given valid membership, verify that post works.447# Pre-conditions:448# Valid Authentication Header.449# Expectations:450# Endpoints -- api/memberships/451# Expected Statis Cpde -- 201 Created.452# Expected Content -- A Json object with a MEMBERSHIP_ID attribute.453# """454# def __init__(self , session=None):455# super().__init__(session)456# self.url = hostURL + 'api/memberships/'457# self.data = {458# 'ACT_CDE': activity_code,459# 'SESS_CDE' : '201501',460# 'ID_NUM': my_id_number,461# 'PART_CDE':'GUEST',462# 'BEGIN_DTE':'06/10/2016',463# 'END_DTE':'07/16/2016',464# 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'465# }466# # We will get the actual id when we post.467# # Setting it -1 to check later that we got an id from the post.468# self.createdMembershipID = -1469# def test(self):470# response = api.postAsJson(self.session, self.url, self.data)471# if not response.status_code == 201:472# self.log_error('Expected 201 Created, got {0}.'.format(response.status_code))473# try:474# response.json()475# except ValueError:476# self.log_error('Expected Json response body, got {0}.'.format(response.text))477# else:478# try:479# self.createdMembershipID = response.json()['MEMBERSHIP_ID']480# except KeyError: 481# self.log_error('Expected MEMBERSHIP_ID in json response, got {0}.'.format(response.json()))482 483# def cleanup(self):484# # We try to delete the membership we created485# if self.createdMembershipID < 0: # The creation wasn't successful486# self.log_error('Expected valid membership ID, got {0}.'.format(self.createdMembershipID))487# else:488# d = api.delete(self.session, self.url + str(self.createdMembershipID))489# if not d.status_code == 200:490# self.log_error('Error in cleanup for {0}'.format(self.test_name))491# return492# class post_membership_with_id_that_is_not_you___regular_member(TestCase):493# """ Verify that regular member can't create a membership for someone else.494# Pre-Conditions:495# Valid Authentication Header.496# Authenticated as a regular member for this Activity.497# Expectations:498# Endpoint -- api/memberships/499# Expected Status Code -- 401 Unauthorized500# Expected Content -- No Content501# """502# def __init__(self , session=None):503# super().__init__(session)504# self.url = hostURL + 'api/memberships/'505# self.data = {506# 'ACT_CDE': activity_code,507# 'SESS_CDE' : '201501',508# 'ID_NUM': random_id_number,509# 'PART_CDE':'GUEST',510# 'BEGIN_DTE':'06/10/2016',511# 'END_DTE':'07/16/2016',512# 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'513# }514# self.membershipID = -1515# def setup(self):516# # Report if there any current memberships for the Club to avoid false negatives.517# # If I am currently a director of the club, this test should fail.518# response = api.get(self.session, self.url + 'student/' + str(my_id_number))519# try:520# for membership in response.json():521# if(membership['ActivityCode'] == activity_code and membership['Participation'] in LEADERSHIP_POSITIONS):522# self.log_error('False Negative: This user is a leader for the activity we are testing.')523# except (ValueError, KeyError):524# self.log_error('Error in setup for {0}'.format(self.test_name)) 525# def test(self):526# response = api.post(self.session, self.url, self.data)527# if not response.status_code == 401:528# self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))529# if response.text:530# self.log_error('Expected empty response body, got {0}.'.format(response.text))531# # If the unauthorized operation went through, try to recover.532# if response.status_code == 201:533# self.log_error('Expected 401 Unauthorized, got 201. Will try to delete the data ...')534# try:535# self.membershipID = response.json()['MEMBERSHIP_ID']536# except (KeyError, ValueError):537# self.log_error('Error in test for {0}'.format(self.test_name))538# def cleanup(self):539# if self.membershipID > 0: # The creation went through even though it wasn't supposed to.540# d = api.delete(self.session, self.url + str(self.membershipID))541# if d.status_code == 200:542# self.log_error('Unauthorized resource was deleted.')543# else:544# self.log_error('Error deleting unauthorized resource.')545 546# class post_non_guest_membership___regular_member(TestCase):547# """ Verify that regular member can not create a non-guest membership.548# Pre-Conditions:549# Authentication Header is Valid.550# Authenticated as a regular member for this Activity.551# Expectations:552# Endpoint -- apo/memberships553# Expected Status Code -- 401 Unauthorized554# Expected Content -- No Content555# """556# def __init__(self,557# SSLVerify=False,558# session=None):559# super().__init__(session)560# self.url = hostURL + 'api/memberships/'561# self.data = {562# 'ACT_CDE': activity_code,563# 'SESS_CDE' : '201501',564# 'ID_NUM': my_id_number,565# 'PART_CDE':'DIREC', #A regular user cannot do this directly.566# 'BEGIN_DTE':'06/10/2016',567# 'END_DTE':'07/16/2016',568# 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'569# }570# self.membershipID = -1571# def setup(self):572# # Report if there any current memberships for the Club to avoid false negatives.573# # If I am currently a director of the club, this test should fail.574# response = api.get(self.session, self.url + 'student/' + str(my_id_number))575# try:576# for membership in response.json():577# if(membership['ActivityCode'] == activity_code and membership['Participation'] in LEADERSHIP_POSITIONS):578# self.log_error('False Negative: This user is a leader for the activity we are testing.')579# except (KeyError, ValueError):580# self.log_error('Error in setup for {0}.'.format(self.test_name))581# def test(self):582# response = api.post(self.session, self.url, self.data)583# if not response.status_code == 401:584# self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))585# if response.text:586# self.log_error('Expected empty response body, got {0}.'.format(response.text))587# if response.status_code == 201:588# self.log_error('Expected 401 Unauthorized, got 201 Created. Will try to delete data ...')589# try:590# self.membershipID = response.json()['MEMBERSHIP_ID']591# except (KeyError, ValueError):592# self.log_error('Error in test for {0}.'.format(self.test_name))593# def cleanup(self):594# if self.membershipID > 0: # The creation went through even though it wasn't supposed to.595# d = api.delete(self.session, self.url + str(self.membershipID))596# if d.status_code == 200:597# self.log_error('Unauthorized resource was deleted.')598# else:599# self.log_error('Error deleting unauthorized resource.')600 601 602 603# class put_valid_membership___regular_member(TestCase):604# """ Verify that a membership can be updated by the owner.605# Pre-Conditions:606# Authenticated as Regular member.607# Expectations:608# Endpoint -- api/memberships/609# Expected Status Code -- 200 OK610# Expected Content -- A json object with a MEMBERSHIP_ID attribute.611# """612# def __init__(self , session=None):613# super().__init__(session)614# self.url = hostURL + 'api/memberships/'615# self.data = {}616# self.createdMembershipID = -1617# def setup(self):618# # The membership to modify619# self.predata = {620# 'ACT_CDE': activity_code,621# 'SESS_CDE' : '201501',622# 'ID_NUM': my_id_number,623# 'PART_CDE':'GUEST',624# 'BEGIN_DTE':'06/10/2016',625# 'END_DTE':'07/16/2016',626# 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'627# }628# r = api.post(self.session, self.url, self.predata)629# try: 630# self.createdMembershipID = r.json()["MEMBERSHIP_ID"]631# # Updated Data632# self.data = {633# 'MEMBERSHIP_ID' : self.createdMembershipID,634# 'ACT_CDE': activity_code,635# 'SESS_CDE' : '201501',636# 'ID_NUM': my_id_number,637# 'PART_CDE':'GUEST',638# 'BEGIN_DTE':'02/10/2016',639# 'END_DTE':'07/16/2016',640# 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'641# }642# except (KeyError, ValueError):643# self.log_error('Error in setup for {0}.'.format(self.test_name))644# def test(self):645# response = api.putAsJson(self.session, self.url + str(self.createdMembershipID), self.data)646# if not response.status_code == 200:647# self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))648# try:649# response.json()650# except ValueError:651# self.log_error('Expected Json response body, got {0}.'.format(response.text))652# else:653# if not ('MEMBERSHIP_ID' in response.json()):654# self.log_error('Expected MEMBERSHIP_ID in response body, got {0}.'.format(response.json()))655# def cleanup(self):656# # We try to delete the membership we created657# if self.createdMembershipID < 0: # The Creation wasn't successfull. ID is still -1.658# self.log_error('Expected valid membership ID, got {0}.'.format(self.createdMembershipID))659# else:660# d = api.delete(self.session, self.url + str(self.createdMembershipID))661# if not d.status_code == 200:662# self.log_error('Error in cleanup for {0}'.format(self.test_name))663# class put_non_guest_membership___regular_member(TestCase):664# """ Verify that regular member can't update their membership level.665# Pre-Conditions:666# Valid Authentication Header.667# Authenticated as a regular member for the activity.668# Expectations:669# Endpoint -- api/memberships/670# Expected Status Code -- 401 Unauthorized671# Expected Content -- No Content672# """673# def __init__(self , session=None):674# super().__init__(session)675# self.url = hostURL + 'api/memberships/'676# self.data = {}677# self.createdMembershipID = -1678# def setup(self):679# # Report if there any current leader memberships under my name to avoid false negatives.680# # If I am currently a director of the club, this test should fail.681# response = api.get(self.session, self.url + 'student/' + str(my_id_number))682# try:683# for membership in response.json():684# if(membership['ActivityCode'] == activity_code and membership['Participation'] in LEADERSHIP_POSITIONS):685# self.log_error('False Negative: This user is a leader for the activity we are testing.')686# except (KeyError, ValueError):687# self.log_error('Error in setup for {0}'.format(self.test_name)) 688# self.predata = {689# 'ACT_CDE': activity_code,690# 'SESS_CDE' : '201501',691# 'ID_NUM': my_id_number,692# 'PART_CDE':'GUEST',693# 'BEGIN_DTE':'06/10/2016',694# 'END_DTE':'07/16/2016',695# 'COMMENT_TXT':'Generated the Raymond Test Suite. IGNORE'696# }697# r = api.postAsJson(self.session, self.url, self.predata)698# try:699# self.createdMembershipID = r.json()['MEMBERSHIP_ID']700# self.data = {701# 'MEMBERSHIP_ID' : self.createdMembershipID,702# 'ACT_CDE': activity_code,703# 'SESS_CDE' : '201501',704# 'ID_NUM': my_id_number,705# 'PART_CDE':'DIREC', #This is not allowed706# 'BEGIN_DTE':'02/10/2016',707# 'END_DTE':'07/16/2016',708# 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'709# }710# except (KeyError, ValueError):711# self.log_error('Error in setup for {0}'.format(self.test_name))712# def test(self):713# response = api.putAsJson(self.session, self.url + str(self.createdMembershipID),self.data)714# if not response.status_code == 401:715# self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))716# if response.text:717# self.log_error('Expected empty response body, got {0}.'.format(response.text))718# def cleanup(self):719# if self.createdMembershipID < 0:720# self.log_error('Expected valid membership ID, got {0}.'.format(self.createdMembershipID))721# else:722# d = api.delete(self.session, self.url + str(self.createdMembershipID))723# if not d.status_code == 200:724# self.log_error('Error in cleanup for {0}'.format(self.test_name))725# class delete_membership_for_someone_else___regular_member(TestCase):726# """ Verify that a regular member cannot delete someone else's membership.727 728# Pre-Conditions:729# Valid Authentication Header730# Authenticated as Regular Member731# Expectations:732# Endpoint -- api/memberships/:id733# Expected Status Code -- 401 Unauthorized.734# Expected Response Body -- Empty.735# """736# def __init__(self, session=None):737# super().__init__(session)738# self.url = hostURL + 'api/memberships/'739# self.membershipID = -1740# def setup(self):741# # Get all memberships and pick first one that doesn't belong to me742# response = api.get(self.session, self.url)743# try:744# memberships = response.json()745# except ValueError:746# self.log_error('Error in setup for {0}. Expected a json response, got {1}.'.format(self.test_name, response.text))747# else:748# try:749# for membership in memberships:750# if not membership['IDNumber'] == str(my_id_number):751# self.membershipID = membership['MembershipID']752# break753# except KeyError:754# self.log_error('Error in setup for {0}. Expected MembershipID in json response, got {1}.'.format(self.test_name, response.json()))755# def test(self):756# response = api.delete(self.session, self.url + str(self.membershipID))757# if not response.status_code == 401:758# self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))759# if response.text:760# self.log_error('Expected empty response body, got {0}.'.format(response.text))761 762# class delete_valid_membership___regular_member(TestCase):763# """ Verify that a regular member can delete their membership.764# Pre-Conditions:765# Valid Authentication header.766# Authenticated as regular member for the activity.767# Expectations:768# Endpoint -- api/memberships/769# Expected Status Code -- 200 OK770# Expected Response Content -- The membership resource that wad delteed.771# """772# def __init__(self , session=None):773# super().__init__(session)774# self.url = hostURL + 'api/memberships/'775# self.createdMembershipID = -1776# def setup(self):777# # Create a Memerships that we'll eventually delete778# self.predata = {779# 'ACT_CDE': activity_code,780# 'SESS_CDE' : '201501',781# 'ID_NUM': my_id_number,782# 'PART_CDE':'GUEST',783# 'BEGIN_DTE':'06/10/2016',784# 'END_DTE':'07/16/2016',785# 'COMMENT_TXT':'Generated the Raymond Test Suite. IGNORE'786# }787# r = api.postAsJson(self.session, self.url, self.predata)788# try:789# self.createdMembershipID = r.json()['MEMBERSHIP_ID']790# except ValueError:791# self.log_error('Error doing setup for {0}'.format(self.test_name))792# def test(self):793# response = api.delete(self.session, self.url + str(self.createdMembershipID))794# if not response.status_code == 200:795# self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))796# try:797# response.json()798# except ValueError:799# self.log_error('Expected Json response body, got {0}.'.format(response.text))800# else:801# if not ('MEMBERSHIP_ID' in response.json()):802# self.log_error(self.log_error('Expected MEMBERSHIP_ID in response, got {0}.'.format(response.json())))803# # # # # # # # # # # # # # #804# # MEMBERSHIP REQUEST TESTS #805# # # # # # # # # # # # # # #806class get_all_membership_requests___regular_member(TestCase):807 """ Verify that a regular member cannot access all membership requests.808 Pre-Conditions:809 Valid Authentication Header.810 Authenticated as regular member.811 Expectations:812 Endpoint -- api/requests/813 Expected Status Code -- 401 Unauthorized814 Expected Response Content -- Empty response content.815 """816 def __init__(self , session=None):817 super().__init__(session)818 self.url = hostURL + 'api/requests/'819 def test(self):820 response = api.get(self.session, self.url)821 if not response.status_code == 401:822 self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))823 if response.text:824 self.log_error('Expected empty response body, got {0}.'.format(response.text))825# class get_my_membership_request___regular_member(TestCase):826# """ Verify that a member can create a request and view it.827# Pre-Conditions:828# Valid Authentication Header829# Authenticated as regular member830# Expectations:831# Endpoint -- api/requests/:id832# Expected Status Code -- 200 OK833# Expected Response Body -- Json with my membership Request.834# """835# def __init__(self,SSLVerify=False, session=None):836# super().__init__(session)837# self.url = hostURL + 'api/requests/'838# self.requestID = -1839# def setup(self):840# self.predata = {841# 'SESS_CDE' : '201501',842# 'ACT_CDE' : activity_code,843# 'ID_NUM' : random_id_number,844# 'DATE_SENT' : '07/06/2016',845# 'PART_CDE' : 'MEMBR',846# 'COMMENT_TXT' : 'Generated by the Raymond Test Suite. IGNORE'847# }848# r = api.postAsJson(self.session, self.url, self.predata)849# try:850# self.requestID = r.json()['REQUEST_ID']851# except (KeyError, ValueError):852# self.log_error('Error in setup for {0}.'.format(self.test_name))853# def test(self):854# response = api.get(self.session, self.url + str(self.requestID))855# if not response.status_code == 200:856# self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))857# try:858# response.json()859# except ValueError:860# self.log_error('Expected Json response body, got {0}.'.format(response.text))861# else:862# if not ('RequestID' in response.json()):863# self.log_error('Expected RequestID in response, got {0}.'.format(response.json()))864# def cleanup(self):865# if self.requestID < 0: # ID is still -1866# self.log_error('Expected valid request id, got {0}.'.format(self.requestID))867# else:868# d = api.delete(self.session, self.url + str(self.requestID))869# if not d.status_code == 200:870# self.log_error('Error in cleanup for {0}'.format(self.test_name))871# class get_all_my_membership_requests___regular_member(TestCase):872# """ Verify that a regular member can retrieve all requests belonging to them.873 874# Pre-Conditions:875# Valid Authentication Header.876# Authenticated as regular member.877# Expectations:878# Endpoint -- api/requests/student/:id879# Expected Status Code -- 200 OK880# Expected Response Body -- A list of membership requests 881# """882# def __init__(self , session=None):883# super().__init__(session)884# self.url = hostURL + 'api/requests/student/' + str(my_id_number)885# def test(self):886# response = api.get(self.session, self.url)887# if not response.status_code == 200:888# self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))889# try:890# response.json()891# except ValueError:892# self.log_error('Expected Json response body, got {0}.'.format(response.text))893# else:894# if not (type(response.json()) is list):895# self.log_error('Expected list, got {0}.'.format(response.json()))896 897class get_membership_requests_for_someone_else___regular_member(TestCase):898 """ Verify that a regular member cannot get the membership requests of somone else.899 900 Pre-Conditions:901 Valid Authentication Header902 Authenticated as regular member903 Expectations:904 Endpoint -- api/requests/student/:id905 Expected Status Code -- 401 Unauthorized906 Expected Response Body -- Empty907 """908 def __init__(self , session=None):909 super().__init__(session)910 self.url = hostURL + 'api/requests/student/' + str(random_id_number)911 def test(self):912 response = api.get(self.session, self.url)913 if not response.status_code == 401:914 self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))915 if response.text:916 self.log_error('Expected empty response bodty, got {0}.'.format(response.text))917class get_membership_requests_for_activity___regular_member(TestCase):918 """ Verify that a regular member can't access memberships requests for activity.919 Pre-Conditions:920 Valid Authentication Header921 Authenticated as regular member922 Expectations:923 Endpoint -- api/requests/activity/:id924 Expected Status Code -- 401 Unauthorized925 Expected Response Body -- Empty926 """927 def __init__(self , session=None):928 super().__init__(session)929 self.url = hostURL + 'api/requests/activity/' + activity_code930 def setup(self):931 # Report if there any current memberships for the Club to avoid false negatives.932 # If I am currently a director of the club, this test should fail.933 response = api.get(self.session, hostURL + 'api/memberships/student/' + str(my_id_number))934 try:935 for membership in response.json():936 if(membership['ActivityCode'] == activity_code and membership['Participation'] in LEADERSHIP_POSITIONS):937 self.log_error('False Negative: This user is a leader for the activity we are testing.')938 except ValueError:939 self.log_error('We did not get a json response back during setup.') 940 def test(self):941 response = api.get(self.session, self.url)942 if not response.status_code == 401:943 self.log_error('We did not get 401 Unauthorized.')944 if response.text:945 self.log_error('We got a non-empty response body.')946class post_valid_membership_request___regular_member(TestCase):947 """ Verify that we can create a membership request.948 Pre-conditions:949 Valid Authentication Header.950 Expectations:951 Endpoints -- api/requests/952 Expected Status Cpde -- 201 Created.953 Expected Content -- A Json object with a REQUEST_ID attribute.954 """955 def __init__(self , session=None):956 super().__init__(session)957 self.url = hostURL + 'api/requests/'958 self.data = {959 'ACT_CDE': activity_code,960 'SESS_CDE' : '201501',961 'ID_NUM': my_id_number,962 'PART_CDE':'MEMBR',963 'DATE_SENT' : '07/06/2016',964 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'965 }966 # We will get the actual id when we post.967 # Setting it -1 to check later that we got an id from the post.968 self.requestID = -1969 def test(self):970 response = api.postAsJson(self.session, self.url, self.data)971 if not response.status_code == 201:972 self.log_error('Expected 201 Created, got {0}.'.format(response.status_code))973 try:974 response.json()975 except ValueError:976 self.log_error('Expected json response, got {0}.'.format(response.text))977 else:978 try:979 self.requestID = response.json()['REQUEST_ID']980 except KeyError:981 self.log_error('Expected REQUEST_ID in response body, got {0}.'.format(response.json()))982 def cleanup(self):983 # We try to delete the request we created984 if self.requestID < 0: # The creation wasn't successful985 self.log_error('Could not delete request with id of {0}'.format(self.requestID))986 else:987 d = api.delete(self.session, self.url + str(self.requestID))988 if not d.status_code == 200:989 self.log_error('There was a problem performing cleanup for {0}'.format(self.test_name))990class post_membership_request_for_someone_else___regular_member(TestCase):991 """ Verify that we can't create a membership request for someone else.992 Pre-conditions:993 Valid Authentication Header.994 Authenticated as Regular member.995 Expectations:996 Endpoints -- api/requests/997 Expected Status Code -- 401 Unauthorized.998 Expected Response Content -- Empty Response.999 """1000 def __init__(self , session=None):1001 super().__init__(session)1002 self.url = hostURL + 'api/requests/'1003 self.data = {1004 'ACT_CDE': activity_code,1005 'SESS_CDE' : '201501',1006 'ID_NUM': random_id_number,1007 'PART_CDE':'MEMBR',1008 'DATE_SENT' : '07/06/2016',1009 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'1010 }1011 # We will get the actual id when we post.1012 self.requestID = -11013 def test(self):1014 response = api.post(self.session, self.url, self.data)1015 if not response.status_code == 401:1016 self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))1017 if response.text:1018 self.log_error('Expected empty response, got {0}.'.format(response.text))1019 if response.status_code == 201:1020 self.log_error('Will try to delete resource...')1021 try:1022 self.requestID = response.json()['REQUEST_ID']1023 except (ValueError, KeyError):1024 self.log_error('Error in test for {0}.'.format(self.test_name))1025 1026 def cleanup(self):1027 # If the creation went through, let's delete the resource1028 if self.requestID >= 0:1029 self.log_error('Request {0} was created even though it was supposed to be unauthorized'.format(self.requestID))1030 d = api.delete(self.session, self.url + str(self.requestID))1031 if d.status_code == 200: 1032 self.log_error('Unauthorized resource deleted.')1033 else:1034 self.log_error('Error deleting unauthorized resource.')1035# class put_membership_request___regular_member(TestCase):1036# """ Verify that regular member can't edit a membership request.1037# Pre-Conditions:1038# Valid Authorization Header.1039# Authenticated as regular member.1040# Expectations:1041# Endpoint -- api/requests/:id1042# Expected Status Code -- 401 Unauthorized1043# Expected Response Body -- Empty1044# """1045# def __init__(self , session=None):1046# super().__init__(session)1047# self.url = hostURL + '/api/requests/'1048# self.predata = {}1049# self.data = {}1050# self.requestID = -11051# def setup(self):1052# self.predata = {1053# 'ACT_CDE': activity_code,1054# 'SESS_CDE' : '201501',1055# 'ID_NUM': my_id_number,1056# 'PART_CDE':'MEMBR',1057# 'DATE_SENT' : '07/06/2016',1058# 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'1059# }1060# response = api.postAsJson(self.session, self.url, self.predata)1061# try:1062# self.requestID = response.json()['REQUEST_ID']1063# self.data = {1064# 'REQUEST_ID': self.requestID,1065# 'ACT_CDE': activity_code,1066# 'SESS_CDE' : '201501',1067# 'ID_NUM': my_id_number,1068# 'PART_CDE':'MEMBR',1069# 'DATE_SENT' : '07/06/2016',1070# 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE' 1071# } 1072# except ValueError:1073# self.log_error('Error performing setup for {0}.'.format(self.test_name))1074# def test(self):1075# response = api.putAsJson(self.session, self.url + str(self.requestID), self.data)1076# if not response.status_code == 401:1077# self.log_error('We did not get a 401 Unauthorized.')1078# if response.text:1079# self.log_error('We got a non-empty response body.')1080# def cleanup(self):1081# d = api.delete(self.session, self.url + str(self.requestID))1082# if not d.status_code == 200:1083# self.log_error('There was error performing cleanup for {0}.'.format(self.test_name))1084# class approve_my_request___regular_member(TestCase):1085# """ Verify that a regular member cannot approve his/her request1086# Pre-Conditions:1087# Valid Authentication Header1088# Authenticated as a regular member1089# Expectations:1090# Endpoints -- api/requests/:id/approve1091# Expected Status Code -- 401 Unauthorized1092# Expected Response Body -- Empty1093# """1094# def __init__(self, session=None):1095# super().__init__(session)1096# self.url = hostURL + 'api/requests/'1097# self.data = {}1098# self.requestID = -11099# def setup(self):1100# #Create a memberships request for the trash club.1101# self.data = {1102# 'ACT_CDE': activity_code,1103# 'SESS_CDE' : '201501',1104# 'ID_NUM': my_id_number,1105# 'PART_CDE':'MEMBR',1106# 'DATE_SENT' : '07/06/2016',1107# 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'1108# }1109# response = api.postAsJson(self.session, self.url, self.data)1110# if not response.status_code == 201:1111# self.log_error('Error in setup for {0}. Expected 201 Created, got {1}.'.format(self.test_name, response.status_code))1112# try:1113# response.json()1114# except ValueError:1115# self.log_error('Error in setup for {0}. Expected json response, got {1}.'.format(self.test_name, response.text))1116# else:1117# try:1118# self.requestID = response.json()['REQUEST_ID']1119# except KeyError:1120# self.log_error('Error in setup for {0}. Expected REQUEST_ID in response, got {1}.'.format(self.test_name, response.json()))1121 1122# def test(self):1123# response = api.postAsJson(self.session, self.url + str(self.requestID) + '/approve', None)1124# if not response.status_code == 401:1125# self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))1126# if response.text:1127# self.log_error('Expected empty response body, got {0}.'.format(response.text))1128# def cleanup(self):1129# # We try to delete the request we made1130# if self.requestID < 0: # The request was not successful1131# self.log_error('Error in cleanup for {0}. Expected valid request ID, got {1}.'.format(self.test_name, self.requestID))1132# else:1133# d = api.delete(self.session, self.url + str(self.requestID))1134# if not d.status_code == 200:1135# self.log_error('Error in cleanup for {0}. Expected 200 OK, got {1}.'.format(self.test_name, d.status_code))1136# class deny_my_request___regular_member(TestCase):1137# """ Verify that a regular member cannot deny his/her request1138# Pre-Conditions:1139# Valid Authentication Header1140# Authenticated as a regular member1141# Expectations:1142# Endpoints -- api/requests/:id/deny1143# Expected Status Code -- 401 Unauthorized1144# Expected Response Body -- Empty1145# """1146# def __init__(self, session=None):1147# super().__init__(session)1148# self.url = hostURL + 'api/requests/'1149# self.data = {}1150# self.requestID = -11151# def setup(self):1152# #Create a memberships request for the trash club.1153# self.data = {1154# 'ACT_CDE': activity_code,1155# 'SESS_CDE' : '201501',1156# 'ID_NUM': my_id_number,1157# 'PART_CDE':'MEMBR',1158# 'DATE_SENT' : '07/06/2016',1159# 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'1160# }1161# response = api.postAsJson(self.session, self.url, self.data)1162# if not response.status_code == 201:1163# self.log_error('Error in setup for {0}. Expected 201 Created, got {1}.'.format(self.test_name, response.status_code))1164# try:1165# response.json()1166# except ValueError:1167# self.log_error('Error in setup for {0}. Expected json response, got {1}.'.format(self.test_name, response.text))1168# else:1169# try:1170# self.requestID = response.json()['REQUEST_ID']1171# except KeyError:1172# self.log_error('Error in setup for {0}. Expected REQUEST_ID in response, got {1}.'.format(self.test_name, response.json()))1173 1174# def test(self):1175# response = api.postAsJson(self.session, self.url + str(self.requestID) + '/deny', None)1176# if not response.status_code == 401:1177# self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))1178# if response.text:1179# self.log_error('Expected empty response body, got {0}.'.format(response.text))1180# def cleanup(self):1181# # We try to delete the request we made1182# if self.requestID < 0: # The request was not successful1183# self.log_error('Error in cleanup for {0}. Expected valid request ID, got {1}.'.format(self.test_name, self.requestID))1184# else:1185# d = api.delete(self.session, self.url + str(self.requestID))1186# if not d.status_code == 200:1187# self.log_error('Error in cleanup for {0}. Expected 200 OK, got {1}.'.format(self.test_name, d.status_code))1188# class delete_my_membership_request___regular_member(TestCase):1189# """ Verify that regular member can delete his/her membership request1190# Pre-Conditions:1191# Valid Authentication Header1192# Expectations:1193# Endpoint -- api/requests/:id1194# Expected Status Code -- 200 OK 1195# Expected Response Body -- Json object with deleted resource1196# """1197# def __init__(self , session=None):1198# super().__init__(session)1199# self.url = hostURL + 'api/requests/'1200# self.predata = {}1201# self.requestID = -11202# def setup(self):1203# self.predata = {1204# 'ACT_CDE': activity_code,1205# 'SESS_CDE' : '201501',1206# 'ID_NUM': my_id_number,1207# 'PART_CDE':'MEMBR',1208# 'DATE_SENT' : '07/06/2016',1209# 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'1210# }1211# response = api.postAsJson(self.session, self.url, self.predata)1212# try:1213# self.requestID = response.json()['REQUEST_ID']1214# except ValueError:1215# self.log_error('Error on setup for {0}.'.format(self.test_name))1216# def test(self):1217# response = api.delete(self.session, self.url + str(self.requestID))1218# if not response.status_code == 200:1219# self.log_error('Expected Status Code 200, got {0}.'.format(response.status_code))1220# if not response.text:1221# self.log_error('We got an empty response body.')1222# try:1223# deletedData = response.json()1224# deletedDataID = deletedData['REQUEST_ID']1225# except ValueError:1226# self.log_error('We did not get a json response.')1227# else:1228# if not deletedDataID == self.requestID:1229# self.log_error('The resource we deleted is different from the one we created.')1230 1231# # # # # # # # # # #1232# # SUPERVISOR TESTS #1233# # # # # # # # # # #1234# class get_all_supervisors___regular_member(TestCase):1235# """ Verify that a regular member cannot view all supervisors.1236# Pre-Conditions:1237# Valid Authentication Header.1238# Authenticated as Regular member1239# Expectations:1240# Endpoint -- api/supervisors/1241# Expected Status Code -- 401 Unauthorized1242# Expected Response Body -- Empty1243# """1244# def __init__(self , session=None):1245# super().__init__(session)1246# self.url = hostURL + 'api/supervisors/'1247# def test(self):1248# response = api.get(self.session, self.url)1249# if not response.status_code == 401:1250# self.log_error('Expected Status Code 401 Unauthorized, got {0}.'.format(response.status_code))1251# if response.text:1252# self.log_error('Got non-empty response body.')1253# class get_supervisors_for_activity___regular_member(TestCase):1254# """ Verify that a regular member can get supervisors for activity1255# Pre-Conditions:1256# Valid Authentication Header.1257# Authenticated as regular member.1258# Expectations:1259# Endpoint -- api/supervisors/activity/:id1260# Expected Status Code -- 200 OK1261# Expected Response Body -- list of json objects1262# """1263# def __init__(self , session=None):1264# super().__init__(session)1265# self.url = hostURL + 'api/supervisors/activity/' + activity_code1266# def test(self):1267# response = api.get(self.session, self.url)1268# if not response.status_code == 200:1269# self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1270# if not response.text:1271# self.log_error('Got an empty response body.')1272# try:1273# response.json()1274# except ValueError:1275# self.log_error('Did not get a json response.')1276# else:1277# if not (type(response.json()) is list):1278# self.log_error('Did not get a list.')1279# # class post_supervisor___regular_member(TestCase):1280# # """ verify that a regular member can't add a supervisor1281# # Pre-Conditions:1282# # Valid Authentication Header.1283# # Authenticated as a regular member1284# # Expectations:1285# # Endpoint -- api/supervisors/1286# # Expected Status Code -- 401 Unauthorized1287# # Expected Response Body -- Empty1288# # """1289# # def __init__(self , session=None):1290# # super().__init__(session)1291# # self.url = hostURL + 'api/supervisors/'1292# # self.data = {}1293# # self.supervisorID = -11294# # def setup(self):1295# # self.data = {1296# # 'ID_NUM' : my_id_number,1297# # 'ACT_CDE' : activity_code,1298# # 'SESS_CDE' : '201501'1299# # }1300# # def test(self):1301# # response = api.postAsJson(self.session, self.url, self.data)1302# # if not response.status_code == 401:1303# # self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))1304# # if response.text:1305# # self.log_error('Expected empty response body, got {0}.'.format(response.text))1306# # if response.status_code == 201:1307# # self.log_error('Delete the unauthorized resource...')1308# # try:1309# # self.supervisorID = response.json()['SUP_ID']1310# # except ValueError:1311# # self.log_error('Problem accessing compromised resource.')1312 1313# # def cleanup(self):1314# # if self.supervisorID > 0: # Unauthorized creation took place1315# # d = api.delete(self.session, self.url + str(self.supervisorID))1316# # if response.status_code == 200: # Deletion was not successful1317# # self.log_error('Unauthorized resource deleted.')1318# # else:1319# # self.log_error('Error deleting Unauthorized resource.')1320# class put_supervisor___regular_member(TestCase):1321# """ Verify that a regular member can't edit an existing supervisor1322# Pre-Conditions:1323# Valid Authentication Header.1324# Authenticated as regular member.1325# Expectations:1326# Endpoint -- api/supervisors/:id1327# Expected Status Code -- 401 Unauthorized1328# Expected Response Body -- Empty1329# """1330# def __init__(self , session=None):1331# super().__init__(session)1332# # Trying to update a random supervisor1333# self.url = hostURL + 'api/supervisors/'1334# tempID = 01335# response = api.get(self.session, self.url + str(tempID))1336# # Iterate until we find an actual supervisor.1337# while response.status_code == 404:1338# tempID = tempID + 11339# response = api.get(self.session, self.url + str(tempID))1340# self.data = {1341# 'SUP_ID' : tempID,1342# 'ACT_CDE' : activity_code,1343# 'SESS_CDE' : '201501',1344# 'ID_NUM' : my_id_number1345# }1346# self.supervisorID = -11347 1348# def test(self):1349# response = api.putAsJson(self.session, self.url + str(self.data['SUP_ID']), self.data)1350# if not response.status_code == 401:1351# self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))1352# if response.text:1353# self.log_error('Expected empty response body, got {0}.'.format(response.text))1354# if response.status_code == 200: # If supervisor was updated1355# self.log_error('Unauthorized update. Attempting to delete...')1356# try:1357# self.supervisorID = response.json()['SUP_ID']1358# except (ValueError, KeyError):1359# self.log_error('Error accessing compromised supervisor.')1360 1361# def cleanup(self):1362# if self.supervisorID > 0: # The supervisor was updated.1363# d = api.delete(self.session, self.url)1364# if d.status_code == 200:1365# self.log_error('Compromised resource deleted.')1366# else:1367# self.log_error('Unable to delete compromised resource.')1368# class delete_supervisor___regular_member(TestCase):1369# """ Verify that regular member can't delete a supervisor 1370# Pre-Conditions:1371# Valid Authentication Header1372# Authenticated as regular member1373# Expectations:1374# Endpoint -- api/supervisors/:id1375# Expected Status Code -- 401 Unauthorized1376# Expected Response Body -- Empty1377# """1378# def __init__(self , session=None):1379# super().__init__(session)1380# self.url = hostURL + 'api/supervisors/2'1381# def test(self):1382# response = api.delete(self.session, self.url)1383# if not response.status_code == 401:1384# self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))1385# if response.text:1386# self.log_error('Expected empty body, got {0}.'.format(response.text))1387# # # # # # # # # #1388# # ACTIVITY TESTS #1389# # # # # # # # # #1390# class get_all_activities___regular_member(TestCase):1391# """ Verify that a regular member can get all activities.1392# Pre-Conditions:1393# Valid Authentication Header.1394# Expectations:1395# Endpoint -- api/activities/1396# Expected Status Code -- 200 OK1397# Expected Response Body -- List of activities1398# """1399# def __init__(self , session=None):1400# super().__init__(session)1401# self.url = hostURL + 'api/activities/'1402# def test(self):1403# response = api.get(self.session, self.url)1404# if not response.status_code == 200:1405# self.log_error('Expected 200 OK , got {0}.'.format(response.status_code))1406# try:1407# response.json()1408# except ValueError:1409# self.log_error('Expected Json response body, got {0}.'.format(respons.text))1410# else:1411# if not (type(response.json()) is list):1412# self.log_error('Expected list, got {0}.'.format(response.json()))1413# class get_one_activity___regular_member(TestCase):1414# """ Verify that a regular member can a single activity.1415# Pre-Conditions:1416# Valid Authentication Header1417# Expectations:1418# Endpoint -- api/activities1419# Expected Status Code -- 200 OK1420# Expected Response Body -- Json object with activity resource1421# """1422# def __init__(self , session=None):1423# super().__init__(session)1424# self.url = hostURL + 'api/activities/' + activity_code1425# def test(self):1426# response = api.get(self.session, self.url)1427# if not response.status_code == 200:1428# self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1429# try:1430# response.json()1431# except ValueError:1432# self.log_error('Expected Json response body, got {0}.'.format(response.text))1433# else:1434# try:1435# response.json()['ActivityCode']1436# except KeyError:1437# self.log_error('Expected ACT_CDE in response, got {0}.'.format(response.json()))1438# class get_activities_for_session___regular_member(TestCase):1439# """ Verify that a regular member can get all activities for specific session.1440# Pre-Conditions:1441# Valid Authentication Header1442# Expectations:1443# Endpoint -- api/activities/session/:id1444# Expected Status Code -- 200 OK 1445# Expected Response Body -- list of activities1446# """1447# def __init__(self , session=None):1448# super().__init__(session)1449# self.url = hostURL + 'api/activities/session/201501'1450# def test(self):1451# response = api.get(self.session, self.url)1452# if not response.status_code == 200:1453# self.log_error('Expected 200 OK, got {0}.'.format(response.json()))1454# try:1455# response.json()1456# except ValueError:1457# self.log_error('Expected Json response body, got {0}.'.format(response.json()))1458# else:1459# if not (type(response.json()) is list):1460# self.log_error('Expected list, got {0}.'.format(response.json()))1461# class update_activity___regular_member(TestCase):1462# """ Verify that a regular member cannot update activity information.1463# Pre-Conditions:1464# Valid Authentication Header1465# Authenticated as regular member1466# Expectations:1467# Endpoints -- api/activities/:id1468# Expected Status Code -- 401 Unauthorized1469# Expected Response Body -- Empty1470# """1471# def __init__(self, session=None):1472# super().__init__(session)1473# self.url = hostURL + 'api/activities/' + activity_code1474# self.data = {}1475# def setup(self):1476# # Report if there any current memberships for the Club to avoid false negatives.1477# # If I am currently a director of the club, this test should fail.1478# response = api.get(self.session, hostURL + 'api/memberships/student/' + str(my_id_number))1479# try:1480# for membership in response.json():1481# if(membership['ActivityCode'] == activity_code and membership['Participation'] in LEADERSHIP_POSITIONS):1482# self.log_error('False Negative: This user is a leader for the activity we are testing.')1483# except ValueError:1484# self.log_error('We did not get a json response back during setup.')1485# else:1486# self.data = {1487# "ACT_CDE" : activity_code,1488# "ACT_IMG" : "HACKING INTO SYSTEM AS REGULAR MEMBER",1489# "ACT_BLURB" : "HACKING INTO SYSTEM AS REGULAR MEMBER",1490# "ACT_URL" : "HACKING INTO SYSTEM AS REGULAR MEMBER"1491# }1492# def test(self):1493# response = api.putAsJson(self.session, self.url , self.data)1494# if not response.status_code == 401:1495# self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))1496# if response.text:1497# self.log_error('Expected empty response body, got {0}.'.format(response.text))1498# def cleanup(self):1499# # Don't delete activity even if it was updated. That's too drastic.1500# pass1501 1502#################1503# PROFILE TESTS #1504#################1505class get_my_profile___regular_member(TestCase):1506 """ Verify that a regular member can get a profile of the current user1507 1508 Pre-Conditions:1509 Valid Authentication header1510 Expectaions:1511 Endpoint -- api/profiles/1512 Expected Status Code -- 200 OK1513 Expected Respones Body -- A json object of information on own profile1514 """1515 def __init__(self, session=None):1516 super().__init__(session)1517 self.url = hostURL + 'api/profiles/'1518 def test(self):1519 response = api.get(self.session, self.url)1520 if not response.status_code == 200:1521 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1522 try:1523 response.json()1524 except ValueError:1525 self.log_error('Expected Json response body, got {0}.'.format(response.text))1526class get_profile_by_username___regular_member(TestCase):1527 """ Verify that a regular member can get another person's profile, filtering private information1528 Pre-Conditions:1529 Valid Authentication Header1530 Expectations:1531 Endpoint -- api/profiles/:username1532 Expected Status Code -- 200 Ok1533 Expected Response Body -- list of information on the user without private info1534 """1535 def __init__(self , session=None):1536 super().__init__(session)1537 self.url = hostURL + 'api/profiles/' + username1538 def test(self):1539 response = api.get(self.session, self.url)1540 if not response.status_code == 200:1541 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1542 try:1543 response.json()1544 except ValueError:1545 self.log_error('Expected Json response body, got{0}.'.format(response.text))1546class get_college_role_by_username___regular_member(TestCase):1547 """ Verify that a regular member can get a college role of the current user1548 Pre-Conditions:1549 Valid Authentication Header1550 Expectations:1551 Endpoint -- api/profiles/role/:username1552 Expected Status Code -- 200 Ok1553 Expected Response Body -- list of information on the user without private info1554 """1555 def __init__(self , session=None):1556 super().__init__(session)1557 self.url = hostURL + 'api/profiles/role/' + username1558 def test(self):1559 response = api.get(self.session, self.url)1560 if not response.status_code == 200:1561 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1562 try:1563 response.json()1564 except ValueError:1565 self.log_error('Expected Json response body, got{0}.'.format(response.text))1566class get_image___regular_member(TestCase):1567 """ Verify that a regular member can get a profile image of the current user1568 Pre-Conditions:1569 Valid Authentication Header1570 Expectations:1571 Endpoint -- api/profiles/image1572 Expected Status Code -- 200 Ok1573 Expected Response Body -- image path of the current user1574 """1575 def __init__(self , session=None):1576 super().__init__(session)1577 self.url = hostURL + 'api/profiles/image/'1578 def test(self):1579 response = api.get(self.session, self.url)1580 if not response.status_code == 200:1581 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1582 try:1583 response.json()1584 except ValueError:1585 self.log_error('Expected Json response body, got{0}.'.format(response.text))1586class get_image_by_username___regular_member(TestCase):1587 """ Verify that a regular member can get a profile image of someone else1588 Pre-Conditions:1589 Valid Authentication Header1590 Expectations:1591 Endpoint -- api/profiles/image/:username1592 Expected Status Code -- 200 Ok1593 Expected Response Body -- image path of another user1594 """1595 def __init__(self , session=None):1596 super().__init__(session)1597 self.url = hostURL + 'api/profiles/image/' + username1598 def test(self):1599 response = api.get(self.session, self.url)1600 if not response.status_code == 200:1601 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1602 try:1603 response.json()1604 except ValueError:1605 self.log_error('Expected Json response body, got{0}.'.format(response.text))1606 1607# Often does not PASS due to permission issue to the image columns in WebSQL/CCT databases1608class post_image___regular_member(TestCase):1609 """ Verify that a user can upload a profile image1610 Pre-Conditions:1611 Authenticated as Regular member.1612 Expectations:1613 Endpoint -- api/profiles/image/1614 Expected Status Code -- 200 OK 1615 Expected Content -- 1616 """1617 def __init__(self, session=None):1618 super().__init__(session)1619 self.url = hostURL + 'api/profiles/image/'1620 self.data = {1621 'ID': my_id_number,1622 'FILE_PATH': #File path of the image on the user's computer,1623 'FILE_NAME': #Barcode ID of the user1624 }1625 1626 def test(self):1627 response = api.post(self.session, self.url, self.data)1628 if not response.status_code == 200:1629 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1630 1631 def cleanup(self):1632 self.data = {1633 'ID': my_id_number,1634 'FILE_PATH': None,1635 'FILE_NAME': None1636 }1637 d = api.post(self.session, self.url + 'reset/', self.data)1638 if not d.status_code == 200:1639 self.log_error('There was a problem performing cleanup for {0}'.format(self.test_name))1640class post_reset_image___regular_member(TestCase):1641 """ Verify that a user can reset a profile image1642 Pre-Conditions:1643 Authenticated as Regular member.1644 Expectations:1645 Endpoint -- api/profiles/image/reset/1646 Expected Status Code -- 200 OK 1647 Expected Content -- 1648 """1649 def __init__(self, session=None):1650 super().__init__(session)1651 self.url = hostURL + 'api/profiles/image/reset/'1652 self.data = {1653 'ID': my_id_number,1654 'FILE_PATH': None,1655 'FILE_NAME': None1656 }1657 self.requestID = -11658 def test(self):1659 response = api.post(self.session, self.url, self.data)1660 if not response.status_code == 200:1661 self.log_error('Expected 200 Created, got {0}.'.format(response.status_code))1662 1663class put_social_media_links___regular_member(TestCase):1664 """ Verify that a user can add and edit social media links1665 Pre-Conditions:1666 Authenticated as Regular member.1667 Expectations:1668 Endpoint -- api/profiles/:type1669 Expected Status Code -- 200 OK1670 Expected Content --1671 """1672 # Any other SNS names can be used to replace 'facebook' to test1673 def __init__(self, session=None):1674 super().__init__(session)1675 self.url = hostURL + 'api/profiles/facebook/'1676 self.data = {1677 'facebook': #'URL of any SNS including the domain name'1678 }1679 1680 def test(self):1681 response = api.put(self.session, self.url, self.data)1682 if not response.status_code == 200:1683 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1684 1685 def cleanup(self):1686 self.resetdata = {1687 'facebook': ''1688 }1689 d = api.put(self.session, self.url, self.resetdata)1690 if not d.status_code == 200:1691 self.log_error('There was a problem performing cleanup for {0}'.format(self.test_name))1692class put_mobile_privacy___regular_member(TestCase):1693 """ Verify that a user can add and edit social media links1694 Pre-Conditions:1695 Authenticated as Regular member.1696 Expectations:1697 Endpoint -- api/profiles/mobile_privacy/:value (Y or N)1698 Expected Status Code -- 200 OK1699 Expected Content --1700 """1701 def __init__(self, session=None):1702 super().__init__(session)1703 self.url = hostURL + 'api/profiles/mobile_privacy/Y/'1704 self.data = {1705 'IsMobilePhonePrivate': 'Y'1706 }1707 1708 def test(self):1709 response = api.put(self.session, self.url, self.data)1710 if not response.status_code == 200:1711 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1712 1713 def cleanup(self):1714 self.resetdata = {1715 'IsMobilePhonePrivate': 'N'1716 }1717 d = api.put(self.session, self.url, self.resetdata)1718 if not d.status_code == 200:1719 self.log_error('There was a problem performing cleanup for {0}'.format(self.test_name))1720class put_image_privacy___regular_member(TestCase):1721 """ Verify that a user can add and edit social media links1722 Pre-Conditions:1723 Authenticated as Regular member.1724 Expectations:1725 Endpoint -- api/profiles/image_privacy/:value (Y or N)1726 Expected Status Code -- 200 OK1727 Expected Content --1728 """1729 def __init__(self, session=None):1730 super().__init__(session)1731 self.url = hostURL + 'api/profiles/image_privacy/Y/'1732 self.data = {1733 'show_pic': 'Y'1734 }1735 1736 def test(self):1737 response = api.put(self.session, self.url, self.data)1738 if not response.status_code == 200:1739 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1740 1741 def cleanup(self):1742 self.resetdata = {1743 'show_pic': 'N'1744 }1745 d = api.put(self.session, self.url, self.resetdata)1746 if not d.status_code == 200:1747 self.log_error('There was a problem performing cleanup for {0}'.format(self.test_name))1748# # # # # # # # # # # # # 1749# # PARTICIPATIONS TEST #1750# # # # # # # # # # # # #1751# class get_all_participations___regular_member(TestCase):1752# """ Verify that a regular member can get all participations1753# Pre-Conditions:1754# Valid Authentication Header1755# Expectations:1756# Endpoint -- api/participations1757# Expected Status Code -- 200 OK1758# Expected Response Body -- List of all participations1759# """1760# def __init__(self , session=None):1761# super().__init__(session)1762# self.url = hostURL + 'api/participations'1763# def test(self):1764# response = api.get(self.session, self.url)1765# if not response.status_code == 200:1766# self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1767# try:1768# response.json()1769# except ValueError:1770# self.log_error('Expected Json response body, got {0}.'.format(response.text))1771# else:1772# if not (type(response.json()) is list):1773# self.log_error('Expected list, got {0}.'.format(response.json()))1774# class get_one_participation___regular_member(TestCase):1775# """ Verify that a regular member can get a specific participation object1776# Pre-Conditions:1777# Valud Authentication Header1778# Expectations:1779# Endpoint -- api/participations1780# Expected Status Code -- 200 OK1781# Expected Response Body -- A participation object1782# """1783# def __init__(self , session=None):1784# super().__init__(session)1785# self.url = hostURL + 'api/participations/MEMBR'1786# def test(self):1787# response = api.get(self.session, self.url)1788# if not response.status_code == 200:1789# self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1790# try:1791# response.json()1792# except ValueErrror:1793# self.log_error('Expected Json response body, got {0}.'.format(response.text))1794# else:1795# try:1796# response.json()['ParticipationCode']1797# except KeyError:1798# self.log_error('Expected ParticipationCode in response, got {0}.'.format(response.json()))1799# # # # # # # # # #1800# # SESSIONS TEST #1801# # # # # # # # # #1802# class get_all_sessions___regular_member(TestCase):1803# """ Verify that a regular member can get all session objects1804# Pre-Conditions:1805# Valid Authentication Header1806# Expectations:1807# Endpoint -- api/sessions/1808# Expected Status Code -- 200 OK1809# Expected Response Body -- List of session resources1810# """1811# def __init__(self , session=None):1812# super().__init__(session)1813# self.url = hostURL + 'api/sessions/'1814# def test(self):1815# response = api.get(self.session, self.url)1816# if not response.status_code == 200:1817# self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1818# try:1819# response.json()1820# except ValueError:1821# self.log_error('Expected Json response body, got {0}.'.format(response.json()))1822# else:1823# if not (type(response.json()) is list):1824# self.log_error('Expected list, got {0}.'.format(response.json()))1825# class get_one_session___regular_member(TestCase):1826# """ Verify that a regular member can get a session object1827# Pre-Conditions:1828# Valid Authentication Header1829# Expectations:1830# Endpoint -- api/sessions/:id1831# Expected Status Code -- 200 OK1832# Expected Response Body -- A session resource.1833# """1834# def __init__(self , session=None):1835# super().__init__(session)1836# self.url = hostURL + 'api/sessions/201501'1837# def test(self):1838# response = api.get(self.session, self.url)1839# if not response.status_code == 200:1840# self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1841# try:1842# response.json()1843# except ValueError:1844# self.log_error('Expected Json response body, got {0}.'.format(response.text))1845# else:1846# try:1847# response.json()['SessionCode']1848# except KeyError:1849# self.log_error('Expected SessionCode in response, got {0}.'.format(response.json()))1850# # # # # # # # # #1851# # STUDENTS TEST #1852# # # # # # # # # #1853# class get_all_students___regular_member(TestCase):1854# """ Verify that a regular member cannot list all students1855# Pre-Conditions:1856# Valid Authentications Header1857# Expectations:1858# Endpoint -- api/students1859# Expected Status Code -- 401 Unauthorized1860# Expected Response Body -- Empty1861# """1862# def __init__(self , session=None):1863# super().__init__(session)1864# self.url = hostURL + 'api/students/'1865# def test(self):1866# response = api.get(self.session, self.url)1867# if not response.status_code == 401:1868# self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))1869# if response.text:1870# self.log_error('Expected empty response body, got {0}.'.format(response.text))1871 1872# class get_student_by_id___regular_member(TestCase):1873# """ Verify that a regular member can get a student resource1874# Pre-Conditions:1875# Valid Authentication Header1876# Expectations:1877# Endpoint -- api/students/:id1878# Expected Status Code -- 200 Ok1879# Expected Response Body -- A json response with the student resource1880# """1881# def __init__(self , session=None):1882# super().__init__(session)1883# self.url = hostURL + 'api/students/' + str(random_id_number)1884# def test(self):1885# response = api.get(self.session, self.url)1886# if not response.status_code == 200:1887# self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1888# try:1889# response.json()1890# except ValueError:1891# self.log_error('Expected Json response body, got{0}.'.format(response.text))1892# else:1893# try:1894# response.json()['StudentID']1895# except KeyError:1896# self.log_error('Expected StudentID in response, got{0}.'.format(response.json()))1897 1898# class get_student_by_email___regular_member(TestCase):1899# """ Verify that a regular member cannot get a student resource by email.1900# Pre-Conditions:1901# Valid Authentication Header1902# Expectations:1903# Endpoint -- api/students/email/:email1904# Expected Status Code -- 200 OK1905# Expected Response Body -- A json response with the student resource1906# """1907# def __init__(self, session=None):1908# super().__init__(session)1909# self.url = hostURL + 'api/students/email/ezeanyinabia.anyanwu@gordon.edu/'1910# def test(self):1911# response = api.get(self.session, self.url)1912# if not response.status_code == 200:1913# self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1914# try:1915# response.json()1916# except ValueError:1917# self.log_error('Expected Json response body, got{0}.'.format(response.text))1918# else:1919# try:1920# response.json()['StudentID']1921# except KeyError:1922# self.log_error('Expected StudentID in response, got{0}.'.format(response.json()))1923 1924# # # # # # # # #1925# # EMAIL TEST #1926# # # # # # # # #1927# class get_emails_for_activity___regular_member(TestCase):1928# """ Verify that a regular member cannot get the emails for the members of an activity1929 1930# Pre-conditions:1931# Valid Authentication Header1932# Authenticated as Regular Member1933# Expectations:1934# Endpoint -- api/emails/activity/:id1935# Expected Status Code -- 401 Unauthorized1936# Expected Response Body -- Empty1937# """1938# def __init__(self , session=None):1939# super().__init__(session)1940# self.url = hostURL + 'api/emails/activity/' + activity_code1941# def test(self):1942# response = api.get(self.session, self.url)1943# if not response.status_code == 401:1944# self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))1945# if response.text:1946# self.log_error('Expected empty response body, got {0}.'.format(response.text))1947 1948# class get_emails_for_leaders___regular_member(TestCase):1949# """ Verify that a regular member can get the emails for any activity leader1950 1951# Pre-Conditions:1952# Valid Authentication header1953# Expectaions:1954# Endpoint -- api/emails/activity/:id/leaders1955# Expected Status Code -- 200 OK1956# Expected Respones Body -- Json response with a list of emails1957# """1958# def __init__(self, session=None):1959# super().__init__(session)1960# self.url = hostURL + 'api/emails/activity/' + activity_code + '/leaders'1961# def test(self):1962# response = api.get(self.session, self.url)1963# if not response.status_code == 200:1964# self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1965# try:1966# response.json()1967# except ValueError:1968# self.log_error('Expected Json response body, got {0}.'.format(response.text))1969# else:1970# try:1971# response.json()[0]['Email']1972# except KeyError:1973# self.log_error('Expected Email in response, got{0}.'.format(response.json()))1974if __name__ == '__main__':...

Full Screen

Full Screen

gordon_360_tests_leader.py

Source:gordon_360_tests_leader.py Github

copy

Full Screen

...66 self.token_payload = { 'username':username, 'password':password, 'grant_type':'password' }67 def test(self):68 response = api.post(self.session, self.url, self.token_payload)69 if not response.status_code == 200:70 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))71 try:72 response.json()73 except ValueError:74 self.log_error('Expected Json, got {0}.'.format(response.text))75 else:76 if not 'access_token' in response.json():77 self.log_error('Expected access token in response, got {0}.'.format(response.json()))78# # # # # # # # # # #79# MEMBERSHIP TESTS #80# # # # # # # # # # #81class get_all_memberships___activity_leader(TestCase):82 """ Test retrieving all membership resources.83 Pre-conditions:84 Valid Authentication Header.85 Expectations:86 Endpoint -- memberships/87 Expected Status code -- 200 Ok88 Expected Content -- List89 """90 def __init__(self, session=None):91 super().__init__(session)92 self.url = hostURL + 'api/memberships/'93 def test(self):94 response = api.get(self.session, self.url)95 if not response.status_code == 200:96 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))97 try:98 response.json()99 except ValueError:100 self.log_error('Expected Json response, got {0}.'.format(response.text))101 else:102 if not (type(response.json()) is list):103 self.log_error('Response was not a list')104class get_one_membership___activity_leader(TestCase):105 """ Retrieve a specific membership resource.106 Pre-conditions:107 Valid Authentication header108 Expectations:109 Endpoint -- api/memberships/:id110 Expected Status Code -- 200 OK111 Expected Content -- A Json Object with a MembershipID attribute.112 """113 def __init__(self , session=None):114 super().__init__(session)115 self.url = hostURL + 'api/memberships/'116 self.membershipID = -1117 118 def setup(self):119 # Find a valid membership id120 response = api.get(self.session, self.url)121 if not response.status_code == 200:122 self.log_error('Error in setup for {0}. Expected 200 OK, got {1}.'.format(self.test_name, response.status_code))123 try:124 response.json()125 except ValueError:126 self.log_error('Error in setup for {0}. Expected json response body, got {1}.'.format(self.test_name, response.text))127 else:128 try:129 self.membershipID = response.json()[0]['MembershipID']130 self.url = self.url + str(self.membershipID)131 except KeyError:132 self.log_error('Error in setup for {0}. Expected MembershipID in response body, got {1}.'.format(self.test_name, self.response.json()))133 134 def test(self):135 response = api.get(self.session, self.url)136 if not response.status_code == 200:137 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))138 try:139 response.json()140 except ValueError:141 self.log_error('Expected Json response body, got {0}.'.format(response.text))142 else:143 if not ('MembershipID' in response.json()):144 self.log_error('Expected MembershipID in jsob object, got {0}.'.format(response.json()))145class get_all_my_memberships___activity_leader(TestCase):146 """ Verify that a regular member can fetch memberships associated with them.147 148 Pre-Conditions:149 Valid Authentication Header.150 Expectations:151 Endpoints -- api/memberships/student/:id152 Expected Status Code -- 200 OK153 Expected Reponse Content -- A list of json objects154 """155 def __init__(self , session=None):156 super().__init__(session)157 self.url = hostURL + 'api/memberships/student/' + str(my_id_number)158 def test(self):159 response = api.get(self.session, self.url)160 if not response.status_code == 200:161 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))162 try:163 response.json()164 except ValueError:165 self.log_error('Expected Json response body, got {0}.'.format(response.text))166 else:167 if not (type(response.json()) is list):168 self.log_error('Response was not a list.')169 170class get_all_memberships_for_someone_else___activity_leader(TestCase):171 """ Verify that regular member can fetch someone else's memberships.172 173 Pre-Conditions:174 Valid Authentication Header.175 Authenticated as regular member.176 Expectations177 Endpoint -- api/memberships/student/:id178 Expected Status Code -- 200 OK.179 Expected Response Content -- A list of json objects.180 """181 def __init__(self , session=None):182 super().__init__(session)183 self.url = hostURL + 'api/memberships/student/' + str(random_id_number)184 def test(self):185 response = api.get(self.session, self.url)186 if not response.status_code == 200:187 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))188 try:189 response.json()190 except ValueError:191 self.log_error('Expected Json response body, got {0}.'.format(response.text))192 else:193 if not (type(response.json()) is list):194 self.log_error('Response was not a list')195 196class get_memberships_for_an_activity___activity_leader(TestCase):197 """ Verify that a regular member can fetch memberships for an activity.198 Pre-Conditions:199 Valid Authentication Header.200 Expectations:201 Endpoint -- api/memberships/activity/:id202 Expected Status Code -- 200 OK203 Expected Response Content -- A list of json Objects.204 """205 def __init__(self , session=None):206 super().__init__(session)207 self.url = hostURL + 'api/memberships/activity/' + activity_code208 def test(self):209 response = api.get(self.session, self.url)210 if not response.status_code == 200:211 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))212 try:213 response.json()214 except ValueError:215 self.log_error('Expected Json response body, got {0}.'.format(response.text))216 else:217 if not (type(response.json()) is list):218 self.log_error('Response was not a list.')219 220 221class get_leader_memberships_for_an_activity___activity_leader(TestCase):222 """ Verify that a regular member can fetch all leaders for a specific activity.223 Pre-Conditions:224 Valid Authentication Header.225 Authenticated as regular member.226 Expectations:227 Endpoint -- api/memberships/activity/:id/leaders228 Expected Status Code -- 200 OK229 Expected Response Content -- A list of json objects.230 """231 def __init__(self , session=None):232 super().__init__(session)233 self.url = hostURL + 'api/memberships/activity/' + activity_code + '/leaders'234 def test(self):235 response = api.get(self.session, self.url)236 if not response.status_code == 200:237 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))238 try:239 response.json()240 except ValueError:241 self.log_error('Expected Json response body, got {0}.'.format(response.text))242 else:243 if not (type(response.json()) is list):244 self.log_error('Response was not a list.')245 246class post_new_guest_membership_for_someone_else__activity_leader(TestCase):247 """ Verify that an activity leader can create a Guest membership for someone.248 Pre-conditions:249 Valid Authentication Header.250 Expectations:251 Endpoints -- api/memberships/252 Expected Statis Cpde -- 201 Created.253 Expected Content -- A Json object with a MEMBERSHIP_ID attribute.254 """255 def __init__(self , session=None):256 super().__init__(session)257 self.url = hostURL + 'api/memberships/'258 self.data = {259 'ACT_CDE': activity_code,260 'SESS_CDE' : '201501',261 'ID_NUM': random_id_number,262 'PART_CDE':'GUEST',263 'BEGIN_DTE':'06/10/2016',264 'END_DTE':'07/16/2016',265 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'266 }267 # We will get the actual id when we post.268 # Setting it -1 to check later that we got an id from the post.269 self.createdMembershipID = -1270 def test(self):271 response = api.postAsJson(self.session, self.url, self.data)272 if not response.status_code == 201:273 self.log_error('Expected 201 Created, got {0}.'.format(response.status_code))274 try:275 response.json()276 except ValueError:277 self.log_error('Expected Json response body, got {0}.'.format(response.text))278 else:279 if not ('MEMBERSHIP_ID' in response.json()):280 self.log_error('Expected MEMBERSHIP_ID in json response, got {0}.'.format(response.json()))281 else:282 self.createdMembershipID = response.json()['MEMBERSHIP_ID']283 def cleanup(self):284 # We try to delete the membership we created285 if self.createdMembershipID < 0: # The creation wasn't successfull286 self.log_error('Expected valid membership ID, got {0}.'.format(self.createdMembershipID))287 else:288 d = api.delete(self.session, self.url + str(self.createdMembershipID))289 if not d.status_code == 200:290 self.log_error('Error in cleanup for {0}'.format(self.test_name))291 return292class post_new_membership_for_someone___activity_leader(TestCase):293 """ Verify that an activity leader can create a membership for someone.294 295 Pre-Conditions:296 Valid Authentication Header297 Authenticated as Activity Leader298 Expectations:299 Endpoint -- api/memberships/300 Expected Status Code -- 200 OK301 Expected Content -- A json response with the created membership302 """303 def __init__(self, session=None):304 super().__init__(session)305 self.url = hostURL + 'api/memberships/'306 self.data = {}307 self.createdMembershipID = -1308 def setup(self):309 # Add a new participant310 self.data = {311 'ACT_CDE': activity_code,312 'SESS_CDE' : '201501',313 'ID_NUM': random_id_number, 314 'PART_CDE':'PART',315 'BEGIN_DTE':'06/10/2016',316 'END_DTE':'07/16/2016',317 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'318 319 }320 def test(self):321 response = api.postAsJson(self.session, self.url, self.data)322 if not response.status_code == 201:323 self.log_error('Expected 201 Created, got {0}.'.format(response.status_code))324 try:325 response.json()326 except ValueError:327 self.log_error('Expected Json response body, got {0}.'.format(response.text))328 else:329 try:330 self.createdMembershipID = response.json()['MEMBERSHIP_ID']331 except KeyError:332 self.log_error('Expected MEMBERSHIP ID in response, got {0}.'.format(response.json()))333 334 def cleanup(self):335 # We try to delete the membership we created336 if self.createdMembershipID < 0: # The creation was not successfull337 self.log_error('Expected valid memberhsip ID, got {0}.'.format(self.createdMembershipID))338 else:339 d = api.delete(self.session, self.url + str(self.createdMembershipID))340 if not d.status_code == 200:341 self.log_error('Error in cleanup for {0}. Expected , got {1}.'.format(self.test_name, d.status_code))342class post_new_leader_membership_for_someone___activity_leader(TestCase):343 """ Verify that an activity leader can assign a new leader344 345 Pre-Conditions:346 Valid Authentication Header347 Authenticated as Activity Leader348 Expectations:349 Endpoint -- api/memberships/350 Expected Status Code -- 200 OK351 Expected Content -- A json response with the created membership352 """353 def __init__(self, session=None):354 super().__init__(session)355 self.url = hostURL + 'api/memberships/'356 self.data = {}357 self.createdMembershipID = -1358 def setup(self):359 # Add a new leader360 self.data = {361 'ACT_CDE': activity_code,362 'SESS_CDE' : '201501',363 'ID_NUM': random_id_number, 364 'PART_CDE':'DIREC',365 'BEGIN_DTE':'06/10/2016',366 'END_DTE':'07/16/2016',367 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'368 }369 def test(self):370 response = api.postAsJson(self.session, self.url, self.data)371 if not response.status_code == 201:372 self.log_error('Expected 201 Created, got {0}.'.format(response.status_code))373 try:374 response.json()375 except ValueError:376 self.log_error('Expected Json response body, got {0}.'.format(response.text))377 else:378 try:379 self.createdMembershipID = response.json()['MEMBERSHIP_ID']380 except KeyError:381 self.log_error('Expected MEMBERSHIP_ID in response, got {0}.'.format(response.json()))382 383 def cleanup(self): 384 # We try to delete the membership we created385 if self.createdMembershipID < 0: # The creation was not successful386 self.log_error('Expected valid memberhsip ID, got {0}.'.format(self.createdMembershipID))387 else:388 d = api.delete(self.session, self.url + str(self.createdMembershipID))389 if not d.status_code == 200: 390 self.log_error('Error in cleanup for {0}. Expected , got {1}.'.format(self.test_name, d.status_code))391 392class put_edited_membership_member_to_leader___activity_leader(TestCase):393 """ Verify that an activity leader can upgrade a normal membership to leader status.394 Pre-Conditions:395 Valid Authentication Header396 Authenticated as Activity Leader397 Expectations:398 Endpoint -- api/memberships/:id399 Expected Status Code -- 200 OK400 Expected Content -- A json object with a MEMBERSHIP_ID attribute.401 """ 402 def __init__(self , session=None):403 super().__init__(session) 404 self.url = hostURL + 'api/memberships/'405 self.data = {}406 self.createdMembershipID = -1407 def setup(self): 408 # The membership to modify409 self.predata = {410 'ACT_CDE': activity_code,411 'SESS_CDE' : '201501',412 'ID_NUM': random_id_number,413 'PART_CDE':'PART', # Is a participant at first.414 'BEGIN_DTE':'06/10/2016', # Old start date415 'END_DTE':'07/16/2016',416 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'417 }418 r = api.postAsJson(self.session, self.url, self.predata)419 try: 420 self.createdMembershipID = r.json()["MEMBERSHIP_ID"]421 # Updated Data422 self.data = {423 'MEMBERSHIP_ID' : self.createdMembershipID,424 'ACT_CDE': activity_code,425 'SESS_CDE' : '201501',426 'ID_NUM': random_id_number,427 'PART_CDE':'DIREC', # Upgrade him to director.428 'BEGIN_DTE':'02/10/2016', # New start date429 'END_DTE':'07/16/2016',430 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'431 }432 except (KeyError, ValueError):433 self.log_error('Error in setup for {0}.'.format(self.test_name))434 def test(self):435 response = api.putAsJson(self.session, self.url + str(self.createdMembershipID), self.data)436 if not response.status_code == 200:437 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))438 try:439 response.json()440 except ValueError:441 self.log_error('Expected Json response body, got {0}.'.format(response.text))442 else:443 try:444 response.json()['MEMBERSHIP_ID']445 except KeyError:446 self.log_error('Expected MEMBERSHIP_ID in json response, got {0}.'.format(response.json()))447 448 449 def cleanup(self):450 # We try to delete the membership we created451 if self.createdMembershipID < 0: # The Creation wasn't successfull. ID is still -1.452 self.log_error('Expected valid membership ID, got {0}.'.format(self.createdMembershipID))453 else:454 d = api.delete(self.session, self.url + str(self.createdMembershipID))455 if not d.status_code == 200:456 self.log_error('Error in cleanup for {0}'.format(self.test_name))457class put_edited_membership_leader_to_member___activity_leader(TestCase):458 """ Verify that an activity leader can demote a leader membership.459 Pre-Conditions:460 Valid Authentication Header461 Authenticated as Activity Leader462 Expectations:463 Endpoint -- api/memberships/:id464 Expected Status Code -- 200 OK465 Expected Content -- A json object with a MEMBERSHIP_ID attribute.466 """ 467 def __init__(self , session=None):468 super().__init__(session) 469 self.url = hostURL + 'api/memberships/'470 self.data = {}471 self.createdMembershipID = -1472 def setup(self): 473 # The membership to modify474 self.predata = {475 'ACT_CDE': activity_code,476 'SESS_CDE' : '201501',477 'ID_NUM': random_id_number,478 'PART_CDE':'DIREC', # Is a leader at first479 'BEGIN_DTE':'06/10/2016', # Old start date480 'END_DTE':'07/16/2016',481 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'482 }483 r = api.postAsJson(self.session, self.url, self.predata)484 try: 485 self.createdMembershipID = r.json()["MEMBERSHIP_ID"]486 # Updated Data487 self.data = {488 'MEMBERSHIP_ID' : self.createdMembershipID,489 'ACT_CDE': activity_code,490 'SESS_CDE' : '201501',491 'ID_NUM': random_id_number,492 'PART_CDE':'PART', # Demote him to participant493 'BEGIN_DTE':'02/10/2016', # New start date494 'END_DTE':'07/16/2016',495 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'496 }497 except (KeyError, ValueError):498 self.log_error('Error in setup for {0}.'.format(self.test_name))499 def test(self):500 response = api.putAsJson(self.session, self.url + str(self.createdMembershipID), self.data)501 if not response.status_code == 200:502 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))503 try:504 response.json()505 except ValueError:506 self.log_error('Expected Json response body, got {0}.'.format(response.text))507 else:508 try: 509 response.json()['MEMBERSHIP_ID']510 except KeyError:511 self.log_error('Expected MEMBERSHIP_ID in json response, got {0}.'.format(response.json()))512 513 514 def cleanup(self):515 # We try to delete the membership we created516 if self.createdMembershipID < 0: # The Creation wasn't successfull. ID is still -1.517 self.log_error('Expected valid membership ID, got {0}.'.format(self.createdMembershipID))518 else:519 d = api.delete(self.session, self.url + str(self.createdMembershipID))520 if not d.status_code == 200:521 self.log_error('Error in cleanup for {0}'.format(self.test_name))522class delete_valid_membership___activity_leader(TestCase):523 """ Verify that a an activity leader can delete someone else's membership.524 Pre-Conditions:525 Valid Authentication header.526 Authenticated as regular member for the activity.527 Expectations:528 Endpoint -- api/memberships/529 Expected Status Code -- 200 OK530 Expected Response Content -- The membership resource that wad delteed.531 """532 def __init__(self , session=None):533 super().__init__(session)534 self.url = hostURL + 'api/memberships/'535 self.createdMembershipID = -1536 def setup(self):537 # Create a Memerships that we'll eventually delete538 self.predata = {539 'ACT_CDE': activity_code,540 'SESS_CDE' : '201501',541 'ID_NUM': random_id_number,542 'PART_CDE':'PART',543 'BEGIN_DTE':'06/10/2016',544 'END_DTE':'07/16/2016',545 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'546 }547 r = api.postAsJson(self.session, self.url, self.predata)548 try:549 self.createdMembershipID = r.json()['MEMBERSHIP_ID']550 except (ValueError, KeyError):551 self.log_error('Error doing setup for {0}'.format(self.test_name))552 def test(self):553 response = api.delete(self.session, self.url + str(self.createdMembershipID))554 if not response.status_code == 200:555 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))556 try:557 response.json()558 except ValueError:559 self.log_error('Expected Json response body, got {0}.'.format(response.text))560 else:561 if not ('MEMBERSHIP_ID' in response.json()):562 self.log_error(self.log_error('Expected MEMBERSHIP_ID in response, got {0}.'.format(response.json())))563# # # # # # # # # # # # # #564# MEMBERSHIP REQUEST TESTS #565# # # # # # # # # # # # # #566class get_all_membership_requests___activity_leader(TestCase):567 """ Verify that an activity leader cannot access all membership requests.568 Pre-Conditions:569 Valid Authentication Header.570 Authenticated as activity leader.571 Expectations:572 Endpoint -- api/requests/573 Expected Status Code -- 401 Unauthorized574 Expected Response Content -- Empty response content.575 """576 def __init__(self , session=None):577 super().__init__(session)578 self.url = hostURL + 'api/requests/'579 def test(self):580 response = api.get(self.session, self.url)581 if not response.status_code == 401:582 self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))583 if response.text:584 self.log_error('Expected empty response body, got {0}.'.format(response.text))585class get_membership_requests_for_activity___activity_leader(TestCase):586 """ Verify that the activity leader can get requests to join the activity he/she is leading587 Pre-Conditions:588 Valid Authentication Header.589 Authenticated as activity leader.590 Expectations:591 Endpoint -- api/requests/activity/:id592 Expected Status Code -- 200 OK593 Expected Response Body -- List of json objects representing the membership requests.594 """595 def __init__(self, session=None):596 super().__init__(session)597 self.url = hostURL + 'api/requests/activity/' + activity_code598 def test(self):599 response = api.get(self.session, self.url)600 if not response.status_code == 200:601 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))602 try:603 response.json()604 except ValueError:605 self.log_error('Expected Json response body, got {0}.'.format(response.text))606 else:607 if not (type(response.json()) is list):608 self.log_error('Expected list in response body, got {0}.'.format(response.json()))609 610class get_membership_requests_for_someone_else___activity_leader(TestCase):611 """ Verify that an activity leader cannot get the membership requests of someone else.612 613 Pre-Conditions:614 Valid Authentication Header615 Authenticated as activity leader616 Expectations:617 Endpoint -- api/requests/student/:id618 Expected Status Code -- 401 Unauthorized619 Expected Response Body -- Empty620 """621 def __init__(self , session=None):622 super().__init__(session)623 self.url = hostURL + 'api/requests/student/' + str(random_id_number)624 def test(self):625 response = api.get(self.session, self.url)626 if not response.status_code == 401:627 self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))628 if response.text:629 self.log_error('Expected empty response bodty, got {0}.'.format(response.text))630class get_all_my_membership_requests___activity_leader(TestCase):631 """ Verify that an activity leader can retrieve all requests belonging to them.632 633 Pre-Conditions:634 Valid Authentication Header.635 Authenticated as regular member.636 Expectations:637 Endpoint -- api/requests/student/:id638 Expected Status Code -- 200 OK639 Expected Response Body -- A list of membership requests 640 """641 def __init__(self , session=None):642 super().__init__(session)643 self.url = hostURL + 'api/requests/student/' + str(my_id_number)644 def test(self):645 response = api.get(self.session, self.url)646 if not response.status_code == 200:647 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))648 try:649 response.json()650 except ValueError:651 self.log_error('Expected Json response body, got {0}.'.format(response.text))652 else:653 if not (type(response.json()) is list):654 self.log_error('Expected list, got {0}.'.format(response.json()))655 656class post_valid_membership_request___activity_leader(TestCase):657 """ Verify that we can create a membership request.658 Pre-conditions:659 Valid Authentication Header.660 Expectations:661 Endpoints -- api/requests/662 Expected Status Cpde -- 201 Created.663 Expected Content -- A Json object with a REQUEST_ID attribute.664 """665 def __init__(self , session=None):666 super().__init__(session)667 self.url = hostURL + 'api/requests/'668 self.data = {669 'ACT_CDE': activity_code,670 'SESS_CDE' : '201501',671 'ID_NUM': my_id_number,672 'PART_CDE':'MEMBR',673 'DATE_SENT' : '07/06/2016',674 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'675 }676 # We will get the actual id when we post.677 # Setting it -1 to check later that we got an id from the post.678 self.requestID = -1679 def test(self):680 response = api.postAsJson(self.session, self.url, self.data)681 if not response.status_code == 201:682 self.log_error('Expected 201 Created, got {0}.'.format(response.status_code))683 try:684 response.json()685 except ValueError:686 self.log_error('Expected json response, got {0}.'.format(response.text))687 else:688 try:689 self.requestID = response.json()['REQUEST_ID']690 if not response.json()['STATUS'] == REQUEST_STATUS_PENDING:691 self.log_error('Expected Pending status , got {0}.'.format(response.json()))692 except KeyError:693 self.log_error('Expected REQUEST_ID in response body, got {0}.'.format(response.json()))694 def cleanup(self):695 # We try to delete the request we created696 if self.requestID < 0: # The creation wasn't successfull697 self.log_error('Could not delete request with id of {0}'.format(self.requestID))698 else:699 d = api.delete(self.session, self.url + str(self.requestID))700 if not d.status_code == 200:701 self.log_error('There was a problem performing cleanup for {0}'.format(self.test_name))702class post_membership_request_for_someone_else___activity_leader(TestCase):703 """ Verify that we can't create a membership request for someone else.704 Pre-conditions:705 Valid Authentication Header.706 Authenticated as Activity Leader member.707 Expectations:708 Endpoints -- api/requests/709 Expected Status Code -- 401 Unauthorized.710 Expected Response Content -- Empty Response.711 """712 def __init__(self , session=None):713 super().__init__(session)714 self.url = hostURL + 'api/requests/'715 self.data = {716 'ACT_CDE': activity_code,717 'SESS_CDE' : '201501',718 'ID_NUM': random_id_number,719 'PART_CDE':'MEMBR',720 'DATE_SENT' : '07/06/2016',721 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'722 }723 # We will get the actual id when we post.724 self.requestID = -1725 def test(self):726 response = api.post(self.session, self.url, self.data)727 if not response.status_code == 401:728 self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))729 if response.text:730 self.log_error('Expected empty response, got {0}.'.format(response.text))731 if response.status_code == 201:732 self.log_error('Will try to delete resource...')733 try:734 self.requestID = response.json()['REQUEST_ID']735 except (ValueError, KeyError):736 self.log_error('Error in test for {0}.'.format(self.test_name))737 738 def cleanup(self):739 # If the creation went through, let's delete the resource740 if self.requestID >= 0:741 self.log_error('Request {0} was created even though it was supposed to be unauthorized'.format(self.requestID))742 d = api.delete(self.session, self.url + str(self.requestID))743 if d.status_code == 200: 744 self.log_error('Unauthorized resource deleted.')745 else:746 self.log_error('Error deleting unauthorized resource.')747class put_membership_request___activity_leader(TestCase):748 """ Verify that an activity leader can't edit a membership request through a put request.749 Pre-Conditions:750 Valid Authorization Header.751 Authenticated as activity leader.752 Expectations:753 Endpoint -- api/requests/:id754 Expected Status Code -- 401 Unauthorized755 Expected Response Body -- Empty756 """757 def __init__(self , session=None):758 super().__init__(session)759 self.url = hostURL + '/api/requests/'760 self.predata = {}761 self.data = {}762 self.requestID = -1763 def setup(self):764 self.predata = {765 'ACT_CDE': activity_code,766 'SESS_CDE' : '201501',767 'ID_NUM': my_id_number,768 'PART_CDE':'MEMBR',769 'DATE_SENT' : '07/06/2016',770 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'771 }772 response = api.postAsJson(self.session, self.url, self.predata)773 try:774 self.requestID = response.json()['REQUEST_ID']775 self.data = {776 'REQUEST_ID': self.requestID,777 'ACT_CDE': activity_code,778 'SESS_CDE' : '201501',779 'ID_NUM': random_id_number, #Changing values to emulate attacker muhahah780 'PART_CDE':'PART',781 'DATE_SENT' : '07/06/2016',782 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE' 783 } 784 except ValueError:785 self.log_error('Error performing setup for {0}.'.format(self.test_name))786 def test(self):787 response = api.putAsJson(self.session, self.url + str(self.requestID), self.data)788 if not response.status_code == 401:789 self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))790 if response.text:791 self.log_error('Expected empty response body, got {0}.'.format(response.text))792 def cleanup(self):793 d = api.delete(self.session, self.url + str(self.requestID))794 if not d.status_code == 200:795 self.log_error('There was error performing cleanup for {0}.'.format(self.test_name))796class delete_memberhsip_request___activity_leader(TestCase):797 """ Verify that an activity leader can delete a membership request for his activity798 Pre-Conditions:799 Expectations:800 Endpoints -- api/requests/:id801 Expected Status Code -- 200 OK802 Expected Response Body -- The request that was deleted803 """804 def __init__(self, session=None):805 super().__init__(session)806 self.url = hostURL + 'api/requests/'807 self.predata = {}808 self.requestID = -1809 def setup(self):810 self.predata = {811 'ACT_CDE': activity_code,812 'SESS_CDE': '201501',813 'PART_CDE': 'PART',814 'ID_NUM': my_id_number,815 'DATE_SENT': '07/19/2016',816 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'817 }818 response = api.postAsJson(self.session, self.url, self.predata)819 if not response.status_code == 201:820 self.log_error('Error in setup for {0}. Expected 201 Created, got {1}.'.format(self.test_name, response.status_code))821 else:822 self.requestID = response.json()['REQUEST_ID']823 def test(self):824 response = api.delete(self.session, self.url + '/' + str(self.requestID))825 if not response.status_code == 200:826 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))827 try:828 response.json()829 except ValueError:830 self.log_error('Expected Json response body, got {0}.'.format(response.text))831 else:832 try:833 response.json()['REQUEST_ID']834 except KeyError:835 self.log_error('Expected REQUEST_ID in response body, got {0}.'.format(response.json()))836 837 838class allow_someone_to_join_my_activity___activity_leader(TestCase):839 """ Verify that the activity leader can accept a request directed at their activity.840 Pre-Conditions:841 Valid Authentication Header842 Authenticated as Activity Leader843 Expectations:844 Endpoints -- api/requests/:id/approve845 Expected Status Code -- 200 OK846 Expected Response Body -- Json response with the request that was accepted.847 """848 def __init__(self, session=None):849 super().__init__(session)850 self.url = hostURL + 'api/requests/'851 self.data = {}852 self.requestID = -1853 self.membershipID = -1854 def setup(self):855 #Create a memberships request for the trash club.856 self.data = {857 'ACT_CDE': activity_code,858 'SESS_CDE' : '201501',859 'ID_NUM': my_id_number,860 'PART_CDE':'MEMBR',861 'DATE_SENT' : '07/06/2016',862 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'863 }864 response = api.postAsJson(self.session, self.url, self.data)865 if not response.status_code == 201:866 self.log_error('Error in setup for {0}. Expected 201 Created, got {1}.'.format(self.test_name, response.status_code))867 try:868 response.json()869 except ValueError:870 self.log_error('Error in setup for {0}. Expected json response, got {1}.'.format(self.test_name, response.text))871 else:872 try:873 self.requestID = response.json()['REQUEST_ID']874 except KeyError:875 self.log_error('Error in setup for {0}. Expected REQUEST_ID in response, got {1}.'.format(self.test_name, response.json()))876 877 def test(self):878 response = api.postAsJson(self.session, self.url + str(self.requestID) + '/approve', None)879 if not response.status_code == 200:880 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))881 try:882 response.json()883 except ValueError:884 self.log_error('Expected Json response body, got {0}.'.format(response.text))885 else:886 try:887 self.membershipID = response.json()['MEMBERSHIP_ID']888 except KeyError:889 self.log_error('Expected MEMBERSHIP_ID in response bady, got {0}.'.format(response.json()))890 891 def cleanup(self):892 # We try to delete the request we made893 if self.requestID < 0: # The request was not successful894 self.log_error('Error in cleanup for {0}. Expected valid request ID, got {1}.'.format(self.test_name, self.requestID))895 else:896 d = api.delete(self.session, self.url + str(self.requestID))897 if not d.status_code == 200:898 self.log_error('Error in cleanup for {0}. Expected 200 OK when deleting request, got {1}.'.format(self.test_name, d.status_code))899 # We try to delete the membership we created900 if self.membershipID < 0: # membership creatino was not successful901 self.log_error('Error in cleanup for {0}. Expected valid membership ID, got {1}.'.format(self.test_name, self.membershipID))902 else:903 d = api.delete(self.session, hostURL + 'api/memberships/' + str(self.membershipID))904 if not d.status_code == 200:905 self.log_error('Error in cleanup for {0}. Expected 200 OK when deleting membership, got {1}.'.format(self.test_name, d.status_code))906 907class deny_someone_joining_my_activity___activity_leader(TestCase):908 """ Verify that the activity leader can deny a request directed at their activity.909 Pre-Conditions:910 Valid Authentication Header911 Authenticated as Activity Leader912 Expectations:913 Endpoints -- api/requests/:id/deny914 Expected Status Code -- 200 OK915 Expected Response Body -- Json response with the request that was denied916 """917 def __init__(self, session=None):918 super().__init__(session)919 self.url = hostURL + 'api/requests/'920 self.data = {}921 self.requestID = -1922 def setup(self):923 #Create a memberships request for the trash club.924 self.data = {925 'ACT_CDE': activity_code,926 'SESS_CDE' : '201501',927 'ID_NUM': my_id_number,928 'PART_CDE':'MEMBR',929 'DATE_SENT' : '07/06/2016',930 'COMMENT_TXT':'Generated by the Raymond Test Suite. IGNORE'931 }932 response = api.postAsJson(self.session, self.url, self.data)933 if not response.status_code == 201:934 self.log_error('Error in setup for {0}. Expected 201 Created, got {1}.'.format(self.test_name, response.status_code))935 try:936 response.json()937 except ValueError:938 self.log_error('Error in setup for {0}. Expected json response, got {1}.'.format(self.test_name, response.text))939 else:940 try:941 self.requestID = response.json()['REQUEST_ID']942 except KeyError:943 self.log_error('Error in setup for {0}. Expected REQUEST_ID in response, got {1}.'.format(self.test_name, response.json()))944 945 def test(self):946 response = api.postAsJson(self.session, self.url + str(self.requestID) + '/deny', None)947 if not response.status_code == 200:948 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))949 try:950 response.json()951 except ValueError:952 self.log_error('Expected Json response body, got {0}.'.format(response.text))953 else:954 try:955 if not response.json()['STATUS'] == REQUEST_STATUS_DENIED:956 self.log_error('Expected approved request, got {0}.'.format(response.json()))957 except KeyError:958 self.log_error('Expected STATUS in response bady, got {0}.'.format(response.json()))959 def cleanup(self):960 # We try to delete the request we made961 if self.requestID < 0: # The request was not successful962 self.log_error('Error in cleanup for {0}. Expected valid request ID, got {1}.'.format(self.test_name, self.requestID))963 else:964 d = api.delete(self.session, self.url + str(self.requestID))965 if not d.status_code == 200:966 self.log_error('Error in cleanup for {0}. Expected 200 OK, got {1}.'.format(self.test_name, d.status_code))967# # # # # # # # # # #968# SUPERVISOR TESTS #969# # # # # # # # # #970class get_all_supervisors___activity_leader(TestCase):971 """ Verify that an activity leader cannot view all supervisors.972 Pre-Conditions:973 Valid Authentication Header.974 Authenticated as Activity leader975 Expectations:976 Endpoint -- api/supervisors/977 Expected Status Code -- 401 Unauthorized978 Expected Response Body -- Empty979 """980 def __init__(self , session=None):981 super().__init__(session)982 self.url = hostURL + 'api/supervisors/'983 def test(self):984 response = api.get(self.session, self.url)985 if not response.status_code == 401:986 self.log_error('Expected Status Code 401 Unauthorized, got {0}.'.format(response.status_code))987 if response.text:988 self.log_error('Got non-empty response body.')989class get_supervisors_for_activity___activity_leader(TestCase):990 """ Verify that an activity leader can get supervisors for activity991 Pre-Conditions:992 Valid Authentication Header.993 Authenticated as activity leader.994 Expectations:995 Endpoint -- api/supervisors/activity/:id996 Expected Status Code -- 200 OK997 Expected Response Body -- list of json objects998 """999 def __init__(self , session=None):1000 super().__init__(session)1001 self.url = hostURL + 'api/supervisors/activity/' + activity_code1002 def test(self):1003 response = api.get(self.session, self.url)1004 if not response.status_code == 200:1005 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1006 try:1007 response.json()1008 except ValueError:1009 self.log_error('Expected json response body, got {0}.'.format(response.text))1010 else:1011 if not (type(response.json()) is list):1012 self.log_error('Expected list, got {0}.'.format(response.json()))1013class post_supervisor___activity_leader(TestCase):1014 """ verify that an activity leader can't add a supervisor1015 Pre-Conditions:1016 Valid Authentication Header.1017 Authenticated as activity leader.1018 Expectations:1019 Endpoint -- api/supervisors/1020 Expected Status Code -- 401 Unauthorized1021 Expected Response Body -- Empty1022 """1023 def __init__(self , session=None):1024 super().__init__(session)1025 self.url = hostURL + 'api/supervisors/'1026 self.data = {}1027 self.supervisorID = -11028 def setup(self):1029 self.data = {1030 'ID_NUM' : my_id_number,1031 'ACT_CDE' : activity_code,1032 'SESS_CDE' : '201501'1033 }1034 def test(self):1035 response = api.postAsJson(self.session, self.url, self.data)1036 if not response.status_code == 401:1037 self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))1038 if response.text:1039 self.log_error('Expected empty response body, got {0}.'.format(response.text))1040 if response.status_code == 201:1041 self.log_error('Delete the unauthorized resource...')1042 try:1043 self.supervisorID = response.json()['SUP_ID']1044 except ValueError:1045 self.log_error('Problem accessing compromised resource.')1046 1047 def cleanup(self):1048 if self.supervisorID > 0: # Unauthorized creation took place1049 d = api.delete(self.session, self.url + str(self.supervisorID))1050 if response.status_code == 200: # Deletion was not successful1051 self.log_error('Unauthorized resource deleted.')1052 else:1053 self.log_error('Error deleting Unauthorized resource.')1054class put_supervisor___activity_leader(TestCase):1055 """ Verify that an activity leader can't edit an existing supervisor1056 Pre-Conditions:1057 Valid Authentication Header.1058 Authenticated as regular member.1059 Expectations:1060 Endpoint -- api/supervisors/:id1061 Expected Status Code -- 401 Unauthorized1062 Expected Response Body -- Empty1063 """1064 def __init__(self , session=None):1065 super().__init__(session)1066 # Trying to update a random supervisor1067 self.url = hostURL + 'api/supervisors/'1068 tempID = 01069 # Iterate until we find a valud supervisor1070 response = api.get(self.session,self.url + str(tempID))1071 while response.status_code == 404:1072 tempID = tempID + 11073 response = api.get(self.session, self.url + str(tempID))1074 1075 self.data = {1076 'SUP_ID' : tempID,1077 'ACT_CDE' : activity_code,1078 'SESS_CDE' : '201501',1079 'ID_NUM' : my_id_number1080 }1081 self.supervisorID = -11082 1083 def test(self):1084 response = api.putAsJson(self.session, self.url + str(self.data['SUP_ID']), self.data)1085 if not response.status_code == 401:1086 self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))1087 if response.text:1088 self.log_error('Expected empty respone body, got {0}.'.format(response.text))1089 if response.status_code == 200: # If supervisor was updated1090 self.log_error('Unauthorized update. Attempting to delete...')1091 try:1092 self.supervisorID = response.json()['SUP_ID']1093 except (ValueError, KeyError):1094 self.log_error('Error accessing compromised supervisor.')1095 1096 def cleanup(self):1097 if self.supervisorID > 0: # The supervisor was updated.1098 d = api.delete(self.session, self.url)1099 if d.status_code == 200:1100 self.log_error('Compromised resource deleted.')1101 else:1102 self.log_error('Unable to delete compromised resource.')1103# This test might need to be removed if the authorization process for supervisors is altered.1104class delete_supervisor___activity_leader(TestCase):1105 """ Verify that an activity leader can't delete a supervisor 1106 Pre-Conditions:1107 Valid Authentication Header1108 Authenticated as activity leader1109 Expectations:1110 Endpoint -- api/supervisors/:id1111 Expected Status Code -- 401 Unauthorized1112 Expected Response Body -- Empty1113 """1114 def __init__(self , session=None):1115 super().__init__(session)1116 self.url = hostURL + 'api/supervisors/2'1117 def test(self):1118 response = api.delete(self.session, self.url)1119 if not response.status_code == 401:1120 self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))1121 if response.text:1122 self.log_error('Expected empty body, got {0}.'.format(response.text))1123# # # # # # # # #1124# ACTIVITY TESTS #1125# # # # # # # # #1126class get_all_activities___activity_leader(TestCase):1127 """ Verify that an activity leader can get all activities.1128 Pre-Conditions:1129 Valid Authentication Header.1130 Expectations:1131 Endpoint -- api/activities/1132 Expected Status Code -- 200 OK1133 Expected Response Body -- List of activities1134 """1135 def __init__(self , session=None):1136 super().__init__(session)1137 self.url = hostURL + 'api/activities/'1138 def test(self):1139 response = api.get(self.session, self.url)1140 if not response.status_code == 200:1141 self.log_error('Expected 200 OK , got {0}.'.format(response.status_code))1142 try:1143 response.json()1144 except ValueError:1145 self.log_error('Expected Json response body, got {0}.'.format(respons.text))1146 else:1147 if not (type(response.json()) is list):1148 self.log_error('Expected list, got {0}.'.format(response.json()))1149class get_one_activity___activity_leader(TestCase):1150 """ Verify that an activity leader can a single activity.1151 Pre-Conditions:1152 Valid Authentication Header1153 Expectations:1154 Endpoint -- api/activities1155 Expected Status Code -- 200 OK1156 Expected Response Body -- Json object with activity resource1157 """1158 def __init__(self , session=None):1159 super().__init__(session)1160 self.url = hostURL + 'api/activities/' + activity_code1161 def test(self):1162 response = api.get(self.session, self.url)1163 if not response.status_code == 200:1164 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1165 try:1166 response.json()1167 except ValueError:1168 self.log_error('Expected Json response body, got {0}.'.format(response.text))1169 else:1170 try:1171 response.json()['ActivityCode']1172 except KeyError:1173 self.log_error('Expected ACT_CDE in response, got {0}.'.format(response.json()))1174class get_activities_for_session___activity_leader(TestCase):1175 """ Verify that an activity leader can get all activities for specific session.1176 Pre-Conditions:1177 Valid Authentication Header1178 Expectations:1179 Endpoint -- api/activities/session/:id1180 Expected Status Code -- 200 OK 1181 Expected Response Body -- list of activities1182 """1183 def __init__(self , session=None):1184 super().__init__(session)1185 self.url = hostURL + 'api/activities/session/'1186 self.sessionID = -11187 def setup(self):1188 response = api.get(self.session, hostURL + 'api/sessions/current')1189 if not response.status_code == 200:1190 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1191 try:1192 response.json()1193 except ValueError:1194 self.log_error('Error in setup for {0}. Expected json in response body, got {1}.'.format(self.test_name, response.text))1195 else:1196 try:1197 self.sessionID = response.json()['SessionCode']1198 except KeyError:1199 self.log_error('Error in setup for {0}. Expected SessionCode in response body, got {1}.'.format(self.test_name, response.json()))1200 1201 def test(self):1202 response = api.get(self.session, self.url + str(self.sessionID))1203 if not response.status_code == 200:1204 self.log_error('Expected 200 OK, got {0}.'.format(response.json()))1205 try:1206 response.json()1207 except ValueError:1208 self.log_error('Expected Json response body, got {0}.'.format(response.json()))1209 else:1210 if not (type(response.json()) is list):1211 self.log_error('Expected list, got {0}.'.format(response.json()))1212class update_activity___activity_leader(TestCase):1213 """ Verify that an activity leader can update activity information.1214 Pre-Conditions:1215 Valid Authentication Header1216 Authenticated as activity leader1217 Expectations:1218 Endpoints -- api/activities/:id1219 Expected Status Code -- 200 Ok1220 Expected Response Body -- Updated activity information1221 """1222 def __init__(self, session=None):1223 super().__init__(session)1224 self.url = hostURL + 'api/activities/' + activity_code1225 self.data = {}1226 def setup(self):1227 self.data = {1228 "ACT_CDE" : activity_code,1229 "ACT_BLURB" : 'BLURB GENERATED BY THE TEST SUITE.IGNORE',1230 "ACT_URL" : 'http://www.lolcats.com/'1231 }1232 def test(self):1233 response = api.putAsJson(self.session, self.url , self.data)1234 if not response.status_code == 200:1235 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1236 try:1237 response.json()1238 except ValueError:1239 self.log_error('Expected json in response body, got {0}.'.format(response.text))1240 else:1241 try:1242 response.json()['ACT_CDE']1243 except ValueError:1244 self.log_error('Expected ACT_CDE in response body, got {0}.'.format(response.json()))1245class update_activity_image___activity_leader(TestCase):1246 """ Verify that an activity leader can update the activity image.1247 Pre-Conditions:1248 Valid Authentication Header1249 Authenticated as an activity leader1250 Expectations:1251 Endpoint -- api/activities/:id/image1252 Expected Status Code -- 200 OK1253 Expected Json response -- Empty respons body.1254 """1255 def __init___(self, session=None):1256 pass1257 def setup(self):1258 pass1259 def test(self):1260 pass1261 1262# # # # # # # # # # # # 1263# PARTICIPATIONS TEST #1264# # # # # # # # # # # #1265class get_all_participations___activity_leader(TestCase):1266 """ Verify that an activity leader can get all participations1267 Pre-Conditions:1268 Valid Authentication Header1269 Expectations:1270 Endpoint -- api/participations1271 Expected Status Code -- 200 OK1272 Expected Response Body -- List of all participations1273 """1274 def __init__(self , session=None):1275 super().__init__(session)1276 self.url = hostURL + 'api/participations'1277 def test(self):1278 response = api.get(self.session, self.url)1279 if not response.status_code == 200:1280 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1281 try:1282 response.json()1283 except ValueError:1284 self.log_error('Expected Json response body, got {0}.'.format(response.text))1285 else:1286 if not (type(response.json()) is list):1287 self.log_error('Expected list, got {0}.'.format(response.json()))1288class get_one_participation___activity_leader(TestCase):1289 """ Verify that an activity leader can get a specific participation object1290 Pre-Conditions:1291 Valud Authentication Header1292 Expectations:1293 Endpoint -- api/participations1294 Expected Status Code -- 200 OK1295 Expected Response Body -- A participation object1296 """1297 def __init__(self , session=None):1298 super().__init__(session)1299 self.url = hostURL + 'api/participations/MEMBR'1300 def test(self):1301 response = api.get(self.session, self.url)1302 if not response.status_code == 200:1303 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1304 try:1305 response.json()1306 except ValueErrror:1307 self.log_error('Expected Json response body, got {0}.'.format(response.text))1308 else:1309 try:1310 response.json()['ParticipationCode']1311 except KeyError:1312 self.log_error('Expected ParticipationCode in response, got {0}.'.format(response.json()))1313# # # # # # # # #1314# SESSIONS TEST #1315# # # # # # # # #1316class get_all_sessions___activity_leader(TestCase):1317 """ Verify that an activity leader can get all session objects1318 Pre-Conditions:1319 Valid Authentication Header1320 Expectations:1321 Endpoint -- api/sessions/1322 Expected Status Code -- 200 OK1323 Expected Response Body -- List of session resources1324 """1325 def __init__(self , session=None):1326 super().__init__(session)1327 self.url = hostURL + 'api/sessions/'1328 def test(self):1329 response = api.get(self.session, self.url)1330 if not response.status_code == 200:1331 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1332 try:1333 response.json()1334 except ValueError:1335 self.log_error('Expected Json response body, got {0}.'.format(response.json()))1336 else:1337 if not (type(response.json()) is list):1338 self.log_error('Expected list, got {0}.'.format(response.json()))1339class get_one_session___activity_leader(TestCase):1340 """ Verify that an activity leader can get a session object1341 Pre-Conditions:1342 Valid Authentication Header1343 Expectations:1344 Endpoint -- api/sessions/:id1345 Expected Status Code -- 200 OK1346 Expected Response Body -- A session resource.1347 """1348 def __init__(self , session=None):1349 super().__init__(session)1350 self.url = hostURL + 'api/sessions/201501'1351 def test(self):1352 response = api.get(self.session, self.url)1353 if not response.status_code == 200:1354 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1355 try:1356 response.json()1357 except ValueError:1358 self.log_error('Expected Json response body, got {0}.'.format(response.text))1359 else:1360 try:1361 response.json()['SessionCode']1362 except KeyError:1363 self.log_error('Expected SessionCode in response, got {0}.'.format(response.json()))1364# # # # # # # # #1365# STUDENTS TEST #1366# # # # # # # # #1367class get_all_students___activity_leader(TestCase):1368 """ Verify that an activity leader cannot list all students1369 Pre-Conditions:1370 Valid Authentications Header1371 Expectations:1372 Endpoint -- api/students1373 Expected Status Code -- 401 Unauthorized1374 Expected Response Body -- Empty1375 """1376 def __init__(self , session=None):1377 super().__init__(session)1378 self.url = hostURL + 'api/students/'1379 def test(self):1380 response = api.get(self.session, self.url)1381 if not response.status_code == 401:1382 self.log_error('Expected 401 Unauthorized, got {0}.'.format(response.status_code))1383 if response.text:1384 self.log_error('Expected empty response body, got {0}.'.format(response.text))1385 1386class get_student_by_id___activity_leader(TestCase):1387 """ Verify that an activity leader can get a student resource1388 Pre-Conditions:1389 Valid Authentication Header1390 Expectations:1391 Endpoint -- api/students/:id1392 Expected Status Code -- 200 Ok1393 Expected Response Body -- A json response with the student resource1394 """1395 def __init__(self , session=None):1396 super().__init__(session)1397 self.url = hostURL + 'api/students/' + str(random_id_number)1398 def test(self):1399 response = api.get(self.session, self.url)1400 if not response.status_code == 200:1401 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1402 try:1403 response.json()1404 except ValueError:1405 self.log_error('Expected Json response body, got{0}.'.format(response.text))1406 else:1407 try:1408 response.json()['StudentID']1409 except KeyError:1410 self.log_error('Expected StudentID in response, got{0}.'.format(response.json()))1411 1412class get_student_by_email___activity_leader(TestCase):1413 """ Verify that an activity leader get a student resource by email.1414 Pre-Conditions:1415 Valid Authentication Header1416 Expectations:1417 Endpoint -- api/students/email/:email1418 Expected Status Code -- 200 OK1419 Expected Response Body -- A json response with the student resource1420 """1421 def __init__(self, session=None):1422 super().__init__(session)1423 self.url = hostURL + 'api/students/email/ezeanyinabia.anyanwu@gordon.edu/'1424 def test(self):1425 response = api.get(self.session, self.url)1426 if not response.status_code == 200:1427 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1428 try:1429 response.json()1430 except ValueError:1431 self.log_error('Expected Json response body, got{0}.'.format(response.text))1432 else:1433 try:1434 response.json()['StudentID']1435 except KeyError:1436 self.log_error('Expected StudentID in response, got{0}.'.format(response.json()))1437# # # # # # # #1438# EMAIL TEST #1439# # # # # # # #1440class get_emails_for_activity___activity_leader(TestCase):1441 """ Verify that an activity leader can get the emails for the members of an activity1442 1443 Pre-conditions:1444 Valid Authentication Header1445 Authenticated as Activity leader1446 Expectations:1447 Endpoint -- api/emails/activity/:id1448 Expected Status Code -- 200 OK1449 Expected Response Body -- A list of json objects 1450 """1451 def __init__(self , session=None):1452 super().__init__(session)1453 self.url = hostURL + 'api/emails/activity/' + activity_code1454 def test(self):1455 response = api.get(self.session, self.url)1456 if not response.status_code == 200:1457 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1458 try:1459 response.json()1460 except ValueError:1461 self.log_error('Expected Json in response body, got {0}.'.format(response.text))1462 else:1463 if not (type(response.json()) is list):1464 self.log_error('Expected list, got {0}.'.format(response.json))1465 1466class get_emails_for_leaders___activity_leader(TestCase):1467 """ Verify that a supervisor can get the emails for any activity leader1468 1469 Pre-Conditions:1470 Valid Authentication header1471 Expectaions:1472 Endpoint -- api/emails/activity/:id/leaders1473 Expected Status Code -- 200 OK1474 Expected Respones Body -- Json response with a list of emails1475 """1476 def __init__(self, session=None):1477 super().__init__(session)1478 self.url = hostURL + 'api/emails/activity/' + activity_code + '/leaders'1479 def test(self):1480 response = api.get(self.session, self.url)1481 if not response.status_code == 200:1482 self.log_error('Expected 200 OK, got {0}.'.format(response.status_code))1483 try:1484 response.json()1485 except ValueError:1486 self.log_error('Expected Json response body, got {0}.'.format(response.text))1487 else:1488 try:1489 response.json()[0]['Email']1490 except KeyError:1491 self.log_error('Expected Email in response, got{0}.'.format(response.json()))1492if __name__ == '__main__':...

Full Screen

Full Screen

validation_helper.py

Source:validation_helper.py Github

copy

Full Screen

...68 my_file.close()69 70 # Log Error71 @staticmethod72 def log_error(method, row_no):73 LOG_INFO.append("Row Number: %s --> %s \n" % (row_no, method))74 logging.info("Row Number: %s --> %s \n" % (row_no, method))75 76 77 # You could use this at the start of all methods78 # That need a basic string validation_helper79 @staticmethod80 def string_is_valid_example_only_use_the_next_one_down(value):81 82 if value:83 # Must have something in84 85 if isinstance(value, basestring):86 # Must be a string87 88 # Can use a string specific method now89 # to remove whitespace90 if value.strip():91 # Must have something in92 # A valid string93 94 return True95 96 else:97 # Must only have contained white space98 99 return False100 101 else:102 # is not a String!103 104 return False105 106 else:107 # is empty or null 108 109 return False110 111 112 @staticmethod113 def string_is_valid(value):114 115 if value and isinstance(value, basestring) and value.strip(): 116 return True117 118 return False119 120 @staticmethod121 def number_is_valid(value):122 123 # think this cover int float and long124 if value and isinstance(value, (long, int, float)):125 return True126 127 return False128 129 # Date Validation 130 @staticmethod131 def date_validation(date): 132 # Date will always be String from CSV ?133 134 if validation_helper.string_is_valid(date):135 # There something in the String136 137 # Format could be d/m/yy138 # Format could be d/m/yyyy139 # Format could use separator - or / or . 140 141 # We need to get any string format into a date object142 # Look at this answer and library 143 # http://stackoverflow.com/a/25341965/1256219144 try: 145 parse(date)146 147 # Must be a date formatted string148 return True149 except ValueError:150 # not a date formatted string151 return False152 else:153 return False154 155 156 # Exclude Currency Value157 # http://stackoverflow.com/questions/8421922/how-do-i-convert-a-currency-string-to-a-floating-point-number-in-python158 @staticmethod159 def exlude_currency(value):160 if value and value != 'AE' :161 value = Decimal(sub(r'[^\d.]', '', value))162 return float(value)163 else:164 return False165 166 # Email Validation167 @staticmethod168 def email_validation(email, row_no):169 170 log_message_name = 'Email Validation: '171 172 if DEBUG:173 logging.info("email_validation" + str(row_no) + ' ~ '+ email)174 175 # If you try to do regex validation_helper on a null string 176 # in Java, it will crash.177 # I don't know about python?178 # Do other validation_helper first179 if validation_helper.string_is_valid(email): 180 match = re.search(EMAIL_VALIDATION, email.strip())181 182 if match:183 validation_helper.log_error(''+log_message_name+'Success', row_no)184 else:185 # A log would need to written to the error file186 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)187 188 189 # Employee ID Validation190 @staticmethod191 def employee_id_validation(value, row_no, employee_id_list): 192 193 log_message_name = 'Employee ID Validation: '194 195 if DEBUG:196 logging.info("employee_id_validation: " + str(row_no) + ' ~ '+ value) 197 if value: 198 if validation_helper.string_is_valid(value):199 if not value in employee_id_list:200 validation_helper.log_error(''+log_message_name+'Success', row_no)201 else:202 validation_helper.log_error(''+log_message_name+'Not Unique', row_no)203 else:204 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)205 206 # Title Validation207 @staticmethod208 def title_validation(value, row_no):209 210 log_message_name = 'Title Validation: '211 212 if DEBUG:213 logging.info("title_validation: " + str(row_no) + ' ~ '+ value) 214 if value:215 if validation_helper.string_is_valid(value):216 if value.lower() in HONORIFICS:217 validation_helper.log_error(''+log_message_name+'Success', row_no)218 else:219 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)220 else:221 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)222 223 224 # First Name Validation225 # TODO - check for foriegn characters226 @staticmethod227 def firstname_validation(value, row_no):228 229 log_message_name = 'First Name Validation: '230 231 if DEBUG:232 logging.info("firstname_validation: " + str(row_no) + ' ~ '+ value)233 234 if value:235 if validation_helper.string_is_valid(value):236 validation_helper.log_error(''+log_message_name+'Success', row_no)237 else:238 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)239 else:240 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)241 242 243 # Surname Validation244 @staticmethod245 def surname_validation(value, row_no): 246 247 log_message_name = 'Surname Validation: '248 249 if DEBUG:250 logging.info("surname_validation: " + str(row_no) + ' ~ '+ value)251 252 if value: 253 if validation_helper.string_is_valid(value):254 validation_helper.log_error(''+log_message_name+'Success', row_no)255 else:256 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)257 else:258 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)259 260 261 # Job Title Validation262 @staticmethod263 def job_title_validation(value, row_no): 264 265 log_message_name = 'Job Title Validation: '266 267 if DEBUG:268 logging.info("job_title_validation: " + str(row_no) + ' ~ '+ value)269 270 if validation_helper.string_is_valid(value):271 if value.lower() in JOB_TITLE:272 validation_helper.log_error(''+log_message_name+'Success', row_no)273 else:274 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)275 else:276 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)277 278 # Date of Birth Validation279 @staticmethod280 def dob_validation(dob, row_no):281 282 log_message_name = 'Date of birth Validation: ' 283 284 if DEBUG:285 logging.info("dob_validation: " + str(row_no) + ' ~ '+ dob) 286 287 if dob:288 if validation_helper.date_validation(dob):289 290 now = datetime.datetime.now().now()291 #http://stackoverflow.com/questions/27800775/python-dateutil-parser-parse-parses-month-first-not-day292 date_parse = parse(dob, dayfirst=True)293 294 295 age = dateutil.relativedelta.relativedelta(now, date_parse).years296 297 if age >= MIN_AGE:298 validation_helper.log_error(''+log_message_name+'Success', row_no)299 else:300 validation_helper.log_error(''+log_message_name+'Too young!!', row_no)301 else:302 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)303 else:304 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)305 306 # National Insurance Validation307 @staticmethod308 def national_insurance_validation(national_insurance, row_no):309 310 log_message_name = 'National Insurance Validation: ' 311 312 if DEBUG:313 logging.info("national_insurance_validation: " + str(row_no) + ' ~ '+ national_insurance) 314 315 if national_insurance:316 if validation_helper.string_is_valid(national_insurance):317 318 319 match = re.search(NI_VALIDATION, national_insurance.replace(" ", ""), re.IGNORECASE)320 321 if match:322 validation_helper.log_error(''+log_message_name+'Success', row_no)323 else:324 # A log would need to written to the error file325 validation_helper.log_error(''+log_message_name+'Not Valid Format', row_no)326 else:327 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)328 else:329 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)330 331 332 # Annual Leave Validation333 @staticmethod334 def annual_holiday_allowance_validation(value, row_no):335 336 log_message_name = 'Annual Holiday Allowance Validation: ' 337 338 if DEBUG:339 logging.info("annual_holiday_allowance_validation: " + str(row_no) + ' ~ '+ str(value)) 340 341 if value:342 if validation_helper.number_is_valid(float(value)):343 if float(value) <= MAX_HOLIDAY: 344 validation_helper.log_error(''+log_message_name+'Success', row_no)345 else:346 validation_helper.log_error(''+log_message_name+'Too much holiday allowance', row_no) 347 else:348 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)349 else:350 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)351 352 # Employee Date Joined Validation353 @staticmethod354 def employee_date_joined_validation(date, row_no):355 356 log_message_name = 'Employee Date Joined Validation: ' 357 358 if DEBUG:359 logging.info("employee_date_joined_validation: " + str(row_no) + ' ~ '+ date) 360 361 if date: 362 if validation_helper.date_validation(date):363 364 now = datetime.datetime.now().now()365 #http://stackoverflow.com/questions/27800775/python-dateutil-parser-parse-parses-month-first-not-day366 date_parse = parse(date, dayfirst=True)367 368 month = dateutil.relativedelta.relativedelta(now, date_parse).months369 370 year = dateutil.relativedelta.relativedelta(now, date_parse).years371 372 if year >=0 and month > JOINED_DATE_RANGE:373 374 validation_helper.log_error(''+log_message_name+'Success', row_no)375 376 else:377 378 validation_helper.log_error(''+log_message_name+'Error future date', row_no)379 380 else:381 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)382 else:383 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)384 385 # Employee Date of Leaving Validation386 @staticmethod387 def employee_date_of_leaving_validation(date, row_no):388 389 log_message_name = 'Employee Date of leaving Validation: ' 390 391 if DEBUG:392 logging.info("employee_date_of_leaving_validation: " + str(row_no) + ' ~ '+ date) 393 394 if date:395 if validation_helper.date_validation(date):396 validation_helper.log_error(''+log_message_name+'Success', row_no)397 else:398 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)399 else:400 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)401 402 403 # Company Validation404 @staticmethod405 def company_validation(value, row_no):406 407 log_message_name = 'Company Validation: ' 408 409 if DEBUG:410 logging.info("company_validation: " + str(row_no) + ' ~ '+ value) 411 412 if value: 413 if validation_helper.string_is_valid(value):414 validation_helper.log_error(''+log_message_name+'Success', row_no)415 else:416 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)417 else:418 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)419 420 421 422 # Basic Salary Validation423 @staticmethod424 def basic_salary_validation(value, row_no):425 426 log_message_name = 'Basic Salary Validation: ' 427 428 if DEBUG:429 logging.info("basic_salary_validation: " + str(row_no) + ' ~ '+ str(value)) 430 431 # Exclude currency432 value = validation_helper.exlude_currency(value)433 434 if value: 435 if validation_helper.number_is_valid(value):436 validation_helper.log_error(''+log_message_name+'Success', row_no)437 else:438 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)439 else:440 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)441 442 # Bonus Validation443 @staticmethod444 def bonus_validation(value, row_no):445 446 log_message_name = 'Bonus Validation: ' 447 448 if DEBUG:449 logging.info("bonus_validation: " + str(row_no) + ' ~ '+ value) 450 451 # Exclude currency452 value = validation_helper.exlude_currency(value)453 454 if value:455 if validation_helper.number_is_valid(value):456 validation_helper.log_error(''+log_message_name+'Success', row_no)457 else:458 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)459 else:460 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)461 462 # Commission Validation463 @staticmethod464 def commision_validation(value, row_no):465 466 log_message_name = 'Commission Validation: '467 468 if DEBUG:469 logging.info("commission_validation: " + str(row_no) + ' ~ '+ value) 470 471 # Exclude currency472 value = validation_helper.exlude_currency(value)473 474 if value:475 if validation_helper.number_is_valid(value):476 validation_helper.log_error(''+log_message_name+'Success', row_no)477 else:478 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)479 else:480 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)481 482 # Overtime Validation483 @staticmethod484 def overtime_validation(value, row_no):485 log_message_name = 'Overtime Validation: '486 487 if DEBUG:488 logging.info("overtime_validation: " + str(row_no) + ' ~ '+ value) 489 490 # Exclude currency491 value = validation_helper.exlude_currency(value)492 493 if value:494 if validation_helper.number_is_valid(value):495 validation_helper.log_error(''+log_message_name+'Success', row_no)496 else:497 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)498 else:499 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)500 501 502 # Fuel Allowance Validation503 @staticmethod504 def fuel_allowance_validation(value, row_no):505 506 log_message_name = 'Fuel Allowance Validation: '507 508 if DEBUG:509 logging.info("fuel_allowance_validation: " + str(row_no) + ' ~ '+ value) 510 511 # Exclude currency512 value = validation_helper.exlude_currency(value)513 514 if value: 515 if validation_helper.number_is_valid(value):516 validation_helper.log_error(''+log_message_name+'Success', row_no)517 else:518 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)519 520 else:521 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)522 523 524 # Allowance Total Validation525 @staticmethod526 def allowance_total_validation(value, row_no):527 528 log_message_name = 'Allowance Total Validation: '529 if DEBUG:530 logging.info("allowance_total_validation: " + str(row_no) + ' ~ '+ value) 531 532 # Exclude currency533 value = validation_helper.exlude_currency(value)534 535 if value: 536 if validation_helper.number_is_valid(value):537 validation_helper.log_error(''+log_message_name+'Success', row_no)538 else:539 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)540 541 else:542 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)543 544 # Pension Date Joined Validation545 @staticmethod546 def pension_date_joined_validation(value, row_no):547 548 log_message_name = 'Pension Date Joined Validation: '549 550 if DEBUG:551 logging.info("pension_date_joined_validation: " + str(row_no) + ' ~ '+ value) 552 if value:553 if validation_helper.date_validation(value):554 validation_helper.log_error(''+log_message_name+'Success', row_no)555 else:556 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)557 else:558 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)559 560 # Pension Provider Joined Validation561 @staticmethod562 def pension_provider_validation(value, row_no):563 564 log_message_name = 'Pension Provider Validation: '565 566 if DEBUG:567 logging.info("pension_provider_validation: " + str(row_no) + ' ~ '+ value) 568 569 if value: 570 if validation_helper.string_is_valid(value):571 validation_helper.log_error(''+log_message_name+'Success', row_no)572 else:573 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)574 else:575 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)576 577 578 # Pension Scheme Type Validation579 @staticmethod580 def pension_scheme_type_validation(value, row_no):581 582 log_message_name = 'Pension Scheme Type Validation: '583 584 if DEBUG:585 logging.info("pension_scheme_type_validation: " + str(row_no) + ' ~ '+ value) 586 if value: 587 if validation_helper.string_is_valid(value):588 validation_helper.log_error(''+log_message_name+'Success', row_no)589 else:590 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)591 else:592 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)593 594 # Pension Policy Number Validation595 @staticmethod596 def pension_policy_no_validation(value, row_no):597 598 log_message_name = 'Pension Policy Number Validation: '599 600 if DEBUG:601 logging.info("pension_policy_no_validation: " + str(row_no) + ' ~ '+ value) 602 603 if value: 604 if validation_helper.string_is_valid(value):605 validation_helper.log_error(''+log_message_name+'Success', row_no)606 else:607 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)608 else:609 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)610 611 # Employee Pension Validation612 @staticmethod613 def employee_pension_validation(value, row_no):614 615 log_message_name = 'Employee Pension Validation: '616 617 if DEBUG:618 logging.info("employee_pension_validation: " + str(row_no) + ' ~ '+ str(value)) 619 620 # Exclude currency621 value = validation_helper.exlude_currency(value)622 623 if value:624 if validation_helper.number_is_valid(value):625 validation_helper.log_error(''+log_message_name+'Success', row_no)626 else:627 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)628 else:629 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)630 631 # Employer Pension Validation632 @staticmethod633 def employer_pension_validation(value, row_no):634 635 log_message_name = 'Employer Pension Validation: '636 637 if DEBUG:638 logging.info("employer_pension_validation: " + str(row_no) + ' ~ '+ value) 639 640 # Exclude currency641 value = validation_helper.exlude_currency(value)642 643 if value: 644 if validation_helper.number_is_valid(value):645 validation_helper.log_error(''+log_message_name+'Success', row_no)646 else:647 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)648 else:649 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)650 651 # Life Start Date Validation652 @staticmethod653 def life_start_date_validation(value, row_no):654 655 log_message_name = 'Life Start Date Validation: '656 657 if DEBUG:658 logging.info("life_start_date_validation: " + str(row_no) + ' ~ '+ value) 659 660 if value: 661 if validation_helper.date_validation(value):662 validation_helper.log_error(''+log_message_name+'Success', row_no)663 else:664 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)665 else:666 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)667 668 669 # Life Start Date Validation670 @staticmethod671 def life_salary_multiple_validation(value, row_no):672 673 log_message_name = 'Life Salary Multiple Validation: '674 675 if DEBUG:676 logging.info("life_salary_multiple_validation: " + str(row_no) + ' ~ '+ value) 677 678 if value: 679 if value:680 if validation_helper.number_is_valid(int(value)):681 validation_helper.log_error(''+log_message_name+'Success', row_no)682 else:683 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)684 else:685 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)686 687 # Life Value Validation688 @staticmethod689 def life_value_validation(value, row_no):690 691 log_message_name = 'Life Value Validation: '692 693 if DEBUG:694 logging.info("life_value_validation: " + str(row_no) + ' ~ '+ value) 695 696 # Exclude currency697 value = validation_helper.exlude_currency(value)698 699 if value:700 if validation_helper.number_is_valid(value):701 validation_helper.log_error(''+log_message_name+'Success', row_no)702 else:703 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)704 else:705 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)706 707 708 # PMI Start Date Validation709 @staticmethod710 def pmi_start_date_validation(value, row_no):711 712 log_message_name = 'PMI Start Date Validation: '713 714 if DEBUG:715 logging.info("pmi_start_date_validation: " + str(row_no) + ' ~ '+ value) 716 if value: 717 if validation_helper.date_validation(value):718 validation_helper.log_error(''+log_message_name+'Success', row_no)719 else:720 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)721 else:722 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)723 724 725 # PMI Start Date Validation726 @staticmethod727 def pmi_scheme_type_validation(value, row_no):728 729 log_message_name = 'PMI Scheme Type Validation: '730 731 if DEBUG:732 logging.info("pmi_scheme_type_validation: " + str(row_no) + ' ~ '+ value) 733 734 if value: 735 if validation_helper.string_is_valid(value):736 validation_helper.log_error(''+log_message_name+'Success', row_no)737 else:738 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)739 else:740 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)741 742 # PMI Value Validation743 @staticmethod744 def pmi_value_validation(value, row_no):745 746 log_message_name = 'PMI Value Validation: '747 748 if DEBUG:749 logging.info("pmi_value_validation: " + str(row_no) + ' ~ '+ value) 750 751 # Exclude currency752 value = validation_helper.exlude_currency(value)753 754 if value: 755 if validation_helper.number_is_valid(value):756 validation_helper.log_error(''+log_message_name+'Success', row_no)757 else:758 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)759 else:760 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)761 762 763 # CCV Value Validation764 @staticmethod765 def ccv_value_validation(value, row_no):766 log_message_name = 'Child Care Voucher Value Validation: '767 768 if DEBUG:769 logging.info("ccv_value_validation: " + str(row_no) + ' ~ '+ value) 770 771 # Exclude currency772 value = validation_helper.exlude_currency(value)773 774 if value:775 if validation_helper.number_is_valid(value):776 validation_helper.log_error(''+log_message_name+'Success', row_no)777 else:778 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)779 else:780 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)781 # C2W Value Validation782 @staticmethod783 def ctw_value_validation(value, row_no):784 785 log_message_name = 'Cycle To Work Value Validation: '786 if DEBUG:787 logging.info("ctw_value_validation: " + str(row_no) + ' ~ '+ value) 788 789 # Exclude currency790 value = validation_helper.exlude_currency(value)791 792 if value: 793 if validation_helper.number_is_valid(value):794 validation_helper.log_error(''+log_message_name+'Success', row_no)795 else:796 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)797 else:798 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)799 800 801 # Company Car Value Validation802 @staticmethod803 def company_car_value_validation(value, row_no):804 805 log_message_name = 'Company Car Value Validation: '806 if DEBUG:807 logging.info("company_car_value_validation: " + str(row_no) + ' ~ '+ value) 808 809 # Exclude currency810 value = validation_helper.exlude_currency(value)811 812 if value: 813 if validation_helper.number_is_valid(value):814 validation_helper.log_error(''+log_message_name+'Success', row_no)815 else:816 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)817 else:818 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)819 820 821 # Car Allowance Value Validation822 @staticmethod823 def car_allowance_value_validation(value, row_no):824 825 log_message_name = 'Car Allowance Value Validation: '826 827 if DEBUG:828 logging.info("car_allowance_value_validation: " + str(row_no) + ' ~ '+ value) 829 830 # Exclude currency831 value = validation_helper.exlude_currency(value)832 833 if value:834 if validation_helper.number_is_valid(value):835 validation_helper.log_error(''+log_message_name+'Success', row_no)836 else:837 validation_helper.log_error(''+log_message_name+'Not Valid', row_no)838 else:839 validation_helper.log_error(''+log_message_name+EMPTY_FIELD+'', row_no)840 841 ...

Full Screen

Full Screen

WMS-command_job-logging-info.py

Source:WMS-command_job-logging-info.py Github

copy

Full Screen

...34 utils.info("We are testing %s"%(version))35 utils.remove(utils.get_tmp_file())36 except (RunCommandError,GeneralError,TimeOutError) , e :37 fails=fails+138 utils.log_error("%s"%(utils.get_current_test()))39 utils.log_error("Command: %s"%(e.expression))40 utils.log_error("Message: %s"%(e.message))41 utils.log_traceback("%s"%(utils.get_current_test()))42 utils.log_traceback(traceback.format_exc())43 utils.info ("Submit a job")44 logging.info("Submit a job")45 JOBID=utils.run_command ("glite-wms-job-submit %s --config %s --nomsg --output %s %s "%(utils.get_delegation_options(),utils.get_config_file(),utils.get_jobid_file(),utils.get_jdl_file()))46 logging.info("Job submitted successfuly. Returned JOBID: %s",JOBID)47 # Test a simple logging info operation48 utils.show_progress("Test 3")49 try:50 logging.info("Test 3: Test a simple logging info operation")51 utils.info ("")52 utils.info ("Test a simple logging info operation")53 utils.run_command_continue_on_error ("%s %s"%(COMMAND,JOBID))54 except (RunCommandError,GeneralError,TimeOutError) , e :55 fails=fails+156 utils.log_error("%s"%(utils.get_current_test()))57 utils.log_error("Command: %s"%(e.expression))58 utils.log_error("Message: %s"%(e.message))59 utils.log_traceback("%s"%(utils.get_current_test()))60 utils.log_traceback(traceback.format_exc())61 # Test --config option62 utils.show_progress("Test 4")63 try:64 logging.info("Test 4: Check --config option")65 utils.info ("")66 utils.info ("Test option --config")67 utils.run_command_continue_on_error ("%s --config %s %s"%(COMMAND,utils.get_config_file(),JOBID))68 except (RunCommandError,GeneralError,TimeOutError) , e :69 fails=fails+170 utils.log_error("%s"%(utils.get_current_test()))71 utils.log_error("Command: %s"%(e.expression))72 utils.log_error("Message: %s"%(e.message))73 utils.log_traceback("%s"%(utils.get_current_test()))74 utils.log_traceback(traceback.format_exc())75 # Test --output option76 utils.show_progress("Test 5")77 try:78 logging.info("Test 5: Check --output option")79 utils.info ("")80 utils.info ("Test option --output")81 utils.run_command_continue_on_error ("%s --output %s --config %s %s"%(COMMAND,utils.get_output_file(),utils.get_config_file(),JOBID))82 utils.info ("Check the output file")83 logging.info("Check the output file")84 utils.run_command_continue_on_error ("cat %s"%(utils.get_output_file()))85 utils.remove(utils.get_output_file())86 except (RunCommandError,GeneralError,TimeOutError) , e :87 fails=fails+188 utils.log_error("%s"%(utils.get_current_test()))89 utils.log_error("Command: %s"%(e.expression))90 utils.log_error("Message: %s"%(e.message))91 utils.log_traceback("%s"%(utils.get_current_test()))92 utils.log_traceback(traceback.format_exc())93 # Test --logfile option94 utils.show_progress("Test 6")95 try:96 logging.info("Test 6: Check --logfile option")97 utils.info ("")98 utils.info ("Test option --logfile")99 utils.run_command_continue_on_error ("%s --logfile %s --config %s %s"%(COMMAND,utils.get_log_file(),utils.get_config_file(),JOBID))100 utils.info ("Check the log file")101 logging.info("Check the log file")102 utils.run_command_continue_on_error ("cat %s"%(utils.get_log_file()))103 utils.remove(utils.get_log_file())104 except (RunCommandError,GeneralError,TimeOutError) , e :105 fails=fails+1106 utils.log_error("%s"%(utils.get_current_test()))107 utils.log_error("Command: %s"%(e.expression))108 utils.log_error("Message: %s"%(e.message))109 utils.log_traceback("%s"%(utils.get_current_test()))110 utils.log_traceback(traceback.format_exc())111 # Test --debug and --logfile options112 utils.show_progress("Test 7")113 try:114 logging.info("Test 7: Check --debug and --logfile options")115 utils.info ("")116 utils.info ("Test options --debug and --logfile")117 utils.run_command_continue_on_error ("%s --debug --logfile %s --output %s %s"%(COMMAND,utils.get_log_file(),utils.get_output_file(),JOBID))118 utils.info ("Check the log file with debug option enabled")119 logging.info("Check the log file with debug option enabled")120 utils.run_command_continue_on_error ("cat %s"%(utils.get_log_file()))121 utils.info ("Check the output file with debug option enabled")122 logging.info("Check the output file with debug option enabled")123 utils.run_command_continue_on_error ("cat %s"%(utils.get_output_file()))124 utils.remove(utils.get_output_file())125 except (RunCommandError,GeneralError,TimeOutError) , e :126 fails=fails+1127 utils.log_error("%s"%(utils.get_current_test()))128 utils.log_error("Command: %s"%(e.expression))129 utils.log_error("Message: %s"%(e.message))130 utils.log_traceback("%s"%(utils.get_current_test()))131 utils.log_traceback(traceback.format_exc())132 # Test --verbosity [0|1|2|3] option133 utils.show_progress("Test 8")134 try:135 logging.info("Test 8: Check --verbosity option")136 utils.info ("")137 utils.info ("Test option --verbosity")138 for i in range(4) :139 utils.run_command_continue_on_error ("%s --verbosity %d --output %s %s"%(COMMAND,i,utils.get_output_file(),JOBID))140 utils.info ("Check the output file with verbosity %d option"%(i))141 logging.info("Check the output file with verbosity %d option",i)142 utils.run_command_continue_on_error ("cat %s"%(utils.get_output_file()))143 utils.remove(utils.get_output_file())144 except (RunCommandError,GeneralError,TimeOutError) , e :145 fails=fails+1146 utils.log_error("%s"%(utils.get_current_test()))147 utils.log_error("Command: %s"%(e.expression))148 utils.log_error("Message: %s"%(e.message))149 utils.log_traceback("%s"%(utils.get_current_test()))150 utils.log_traceback(traceback.format_exc())151 152 # Test --input option153 utils.show_progress("Test 9")154 try:155 logging.info("Test 9: Check --input option")156 utils.info ("Submit 2 jobs")157 logging.info("Submit 2 jobs and save their ids in file %s",utils.get_jobid_file())158 utils.run_command_continue_on_error ("glite-wms-job-submit %s --output %s %s"%(utils.get_delegation_options(),utils.get_jobid_file(),utils.get_jdl_file()))159 utils.run_command_continue_on_error ("glite-wms-job-submit %s --output %s %s"%(utils.get_delegation_options(),utils.get_jobid_file(),utils.get_jdl_file()))160 utils.info ("")161 utils.info ("Test the --input option")162 utils.run_command_continue_on_error ("%s --noint --config %s --input %s"%(COMMAND,utils.get_config_file(),utils.get_jobid_file()))163 except (RunCommandError,GeneralError,TimeOutError) , e :164 fails=fails+1165 utils.log_error("%s"%(utils.get_current_test()))166 utils.log_error("Command: %s"%(e.expression))167 utils.log_error("Message: %s"%(e.message))168 utils.log_traceback("%s"%(utils.get_current_test()))169 utils.log_traceback(traceback.format_exc())170 utils.info("Sleep for 60 secs")171 time.sleep (60)172 173 NOW = time.strftime("%H:%M")174 175 # Test --to option176 utils.show_progress("Test 10")177 try:178 logging.info("Test 10: Check --to option")179 utils.info ("")180 utils.info ("Test the --to option")181 # this test fails on gLite UI 3.2.2182 utils.run_command_continue_on_error ("%s --config %s --to %s %s"%(COMMAND,utils.get_config_file(),NOW,JOBID))183 except (RunCommandError,GeneralError,TimeOutError) , e :184 fails=fails+1185 utils.log_error("%s"%(utils.get_current_test()))186 utils.log_error("Command: %s"%(e.expression))187 utils.log_error("Message: %s"%(e.message))188 utils.log_traceback("%s"%(utils.get_current_test()))189 utils.log_traceback(traceback.format_exc())190 # Test --from option191 utils.show_progress("Test 11")192 try:193 logging.info("Test 11: Check --from option")194 utils.info ("")195 utils.info ("Test the --from option")196 utils.run_command_continue_on_error ("%s --config %s --from %s %s"%(COMMAND,utils.get_config_file(),START,JOBID))197 except (RunCommandError,GeneralError,TimeOutError) , e :198 fails=fails+1199 utils.log_error("%s"%(utils.get_current_test()))200 utils.log_error("Command: %s"%(e.expression))201 utils.log_error("Message: %s"%(e.message))202 utils.log_traceback("%s"%(utils.get_current_test()))203 utils.log_traceback(traceback.format_exc())204 # Test --event option205 utils.show_progress("Test 12")206 try:207 logging.info("Test 12: Test the --event option (show only ACCEPTED events)")208 utils.info ("")209 utils.info ("Test the --event option (show only ACCEPTED events)")210 utils.run_command_continue_on_error ("%s --config %s --event ACCEPTED %s | grep \"Event: Accepted\""%(COMMAND,utils.get_config_file(),JOBID))211 212 except (RunCommandError,GeneralError,TimeOutError) , e :213 fails=fails+1214 utils.log_error("%s"%(utils.get_current_test()))215 utils.log_error("Command: %s"%(e.expression))216 utils.log_error("Message: %s"%(e.message))217 utils.log_traceback("%s"%(utils.get_current_test()))218 utils.log_traceback(traceback.format_exc())219 # Test --exclude option220 utils.show_progress("Test 13")221 try:222 logging.info("Test 13: Test the --exclude option (exclude ACCEPTED events)")223 utils.info ("")224 utils.info ("Test the --exclude option (exclude ACCEPTED events)")225 utils.run_command_continue_on_error ("%s --config %s --exclude ACCEPTED %s | grep \"Event: Accepted\""%(COMMAND,utils.get_config_file(),JOBID),1)226 except (RunCommandError,GeneralError,TimeOutError) , e :227 fails=fails+1228 utils.log_error("%s"%(utils.get_current_test()))229 utils.log_error("Command: %s"%(e.expression))230 utils.log_error("Message: %s"%(e.message))231 utils.log_traceback("%s"%(utils.get_current_test()))232 utils.log_traceback(traceback.format_exc())233 # Test --user-tag option234 os.system("echo \"\nusertags = [ type = \'test job\' ];\" >> %s"%(utils.get_jdl_file()))235 utils.show_progress("Test 14")236 try:237 logging.info("Test 14: Check --user-tag option")238 utils.info ("")239 utils.info ("Test the --user-tag option ")240 utils.run_command_continue_on_error ("%s --config %s --user-tag type=\'test job\' %s"%(COMMAND,utils.get_config_file(),JOBID))241 except (RunCommandError,GeneralError,TimeOutError) , e :242 fails=fails+1243 utils.log_error("%s"%(utils.get_current_test()))244 utils.log_error("Command: %s"%(e.expression))245 utils.log_error("Message: %s"%(e.message))246 utils.log_traceback("%s"%(utils.get_current_test()))247 utils.log_traceback(traceback.format_exc())248 249 # Test all options together250 utils.show_progress("Test 15")251 try:252 logging.info("Test 15: Test all options together")253 utils.info ("")254 utils.info ("Test all the options together (extract only EnQueued events)")255 utils.run_command_continue_on_error ("%s --noint --input %s --output %s --logfile %s --config %s --verbosity 3 --from %s --to %s --event EnQueued"%(COMMAND,utils.get_jobid_file(),utils.get_output_file(),utils.get_log_file(),utils.get_config_file(),START,NOW))256 utils.info ("Check the log file")257 logging.info("Check the log file")258 utils.run_command_continue_on_error ("cat %s"%(utils.get_log_file()))259 utils.info ("Check the output file")260 logging.info("Check the output file")261 utils.run_command_continue_on_error ("cat %s"%(utils.get_output_file()))262 except (RunCommandError,GeneralError,TimeOutError) , e :263 fails=fails+1264 utils.log_error("%s"%(utils.get_current_test()))265 utils.log_error("Command: %s"%(e.expression))266 utils.log_error("Message: %s"%(e.message))267 utils.log_traceback("%s"%(utils.get_current_test()))268 utils.log_traceback(traceback.format_exc())269 if fails > 0 :270 utils.exit_failure("%s test(s) fail(s)"%(fails))271 else:272 utils.exit_success()273if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful