def test_get_event_by_id(self): self.event.setHttpMethod('GET') self.event.setQueryStringParameters({'event_id': "27"}) response = main_handler(self.event.getEvent(), context) status_code = response['statusCode'] # check for correct status code self.assertEqual(200, status_code)
def run_tests(self, id): self.resource = resources[id] self.num_methods = num_valid_methods[id] self.event.setPath(self.resource) # event = Event() # test all valid methods for method in methods[:self.num_methods]: self.event.setHttpMethod(method) msg = message_template.format(self.resource, method.lower()) res = main_handler(self.event.getEvent(), None) self.assertEqual(res['statusCode'], 200) body = ast.literal_eval(res['body']) self.assertEqual(body['message'], msg) # test all invalid methods for method in methods[self.num_methods:]: self.event.setHttpMethod(method) res = main_handler(self.event.getEvent(), None) self.assertEqual(res['statusCode'], 501) self.assertEqual(res['body'], str(None))
def test_add_new_event(self): self.event.setHttpMethod('POST') test_dict = {'events': []} event_name = 'Best Event' event_type = 'Music' is_public = True event_date = '2018-06-15' start_time = '15:30:00' end_time = '20:30:00' points = 9000 is_free = False location = { "street": 'Lame St.', "state": 'CA', "city": 'San Diego', "country": 'United States', "zip": 92364, "latitude": 0.000, "longitude": 0.000 } test_dict['events'].append({ 'name': event_name, 'start_time': start_time, 'end_time': end_time, 'is_free': is_free, 'location': location, 'points': points, 'is_public': is_public, 'event_date': event_date, 'type': event_type }) self.req_body['events'] = test_dict['events'] self.event.setBody(json.dumps(self.req_body)) response = main_handler(self.event.getEvent(), context) resp_body = json.loads(response['body']) print(resp_body) status_code = response['statusCode'] # check for correct status code self.assertEqual(201, status_code) # check for correct body self.assertEqual(None, resp_body)
def test_add_new_event(self): self.event.setHttpMethod('POST') test_dict = {'missions': []} mission_name = 'New Mission' mission_type = 'Adventure' mission_date = '2018-06-15' start_time = '15:30:00' end_time = '20:30:00' description = "Sucks to succk" image = "" points = 9000 location = { "street": 'Lame St.', "state": 'CA', "city": 'san diego', "country": 'United States', "zip": 92364, "latitude": 0.000, "longitude": 0.000 } test_dict['missions'].append({ 'name': mission_name, 'mission_start': start_time, 'mission_end': end_time, 'description': description, 'location': location, 'points': points, 'mission_date': mission_date, 'image': image }) self.req_body['missions'] = test_dict['missions'] self.event.setBody(json.dumps(self.req_body)) response = main_handler(self.event.getEvent(), context) resp_body = json.loads(response['body']) print(resp_body) status_code = response['statusCode'] print(response) # check for correct status code self.assertEqual(201, status_code) # check for correct body self.assertEqual(None, resp_body)
def test_add_new_user(self): self.event.setHttpMethod('POST') # add user with required fields self.req_body['display_name'] = 'test_user' self.req_body['email'] = '*****@*****.**' self.req_body['first_name'] = 'Test' self.req_body['last_name'] = 'Case' self.event.setBody(json.dumps(self.req_body)) response = main_handler(self.event.getEvent(), context) resp_body = json.loads(response['body']) status_code = response['statusCode'] # check for correct status code self.assertEqual(201, status_code) # check for correct body self.assertEqual(None, resp_body)