def test_put_no_token(self): print '\tTesting PUT method (with no auth token)' r = requests.put(self.API_URL, data=self.SNIPPET) testfor.status_code(self, r, 401) testfor.valid_json(self, r) testfor.key_val(self, r, 'message', 'Unauthorized')
def test_post_no_body(self): print '\tTesting POST method (with no body)' headers = {'Authorization': self.ACCESS_TOKEN} r = requests.post(self.API_URL, headers=headers) testfor.status_code(self, r, 400) testfor.valid_json(self, r) testfor.key_val(self, r, 'message', 'Invalid request body')
def test_post_invalid_token(self): print '\tTesting POST method (with invalid auth token)' headers = {'Authorization': 'vim is the best editor'} r = requests.post(self.API_URL, headers=headers, data=self.SNIPPET) testfor.status_code(self, r, 401) testfor.valid_json(self, r) testfor.key_val(self, r, 'message', 'Unauthorized')
def test_delete(self): print '\tTesting DELETE method' headers = {'Authorization': self.ACCESS_TOKEN} r = requests.delete(self.API_URL, headers=headers, data=self.SNIPPET) testfor.status_code(self, r, 200) testfor.cors_headers(self, r, {'Origin': '*'}) testfor.valid_json(self, r) testfor.key_val(self, r, 'response', 'Successfully deleted.')
def test_post_invalid_language(self): print '\tTesting POSTT method (with invalid snippet language)' headers = {'Authorization': self.ACCESS_TOKEN} data = { "snippetLanguage": "python2", "AST": {}, "snippetTitle": "title", "snippet": "", "readOnly": False, "filters": {}, "annotations": {} } r = requests.post(self.API_URL, headers=headers, data=self.SNIPPET_INVALID_LANG) testfor.status_code(self, r, 400) testfor.valid_json(self, r) testfor.key_val(self, r, 'message', 'Invalid request body')
def test_put_no_title(self): print '\tTesting PUT method (with no snippet title)' headers = {'Authorization': self.ACCESS_TOKEN} data = { "snippetLanguage": "python3", "AST": {}, "snippetTitle": "", "snippet": "", "readOnly": False, "filters": {}, "annotations": {} } r = requests.put(self.API_URL, headers=headers, data=self.SNIPPET_NO_TITLE) testfor.status_code(self, r, 400) testfor.valid_json(self, r) testfor.key_val(self, r, 'message', 'Invalid request body')