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_get_invalid_snippet(self): print '\tTesting GET method (with invalid snippet id)' r = requests.get(self.INVALID_SNIPPET_URL) testfor.status_code(self, r, 404) testfor.cors_headers(self, r, {'Origin': '*'}) testfor.body( self, r, 'No snippet exists with key "%s/%s"' % (TestEndpoint.USER_ID, TestEndpoint.INVALID_SNIPPET_KEY))
def test_post(self): print '\tTesting POST method' r = requests.post(self.API_URL) testfor.status_code(self, r, 200) testfor.cors_headers(self, r, {'Origin': '*'}) p = urlparse(r.text) if p.scheme != 'https' or self.USER_ID + '/snippets.zip' not in p.path: self.fail('Response is not URL or is incorrect')
def test_options (self): print('\tTesting OPTIONS method') r = requests.options(self.API_URL) testfor.status_code(self, r, 200) testfor.cors_headers(self, r, { 'Headers' : 'Content-Type,X-Amz-Date,Authorization,x-api-key,x-amz-security-token', 'Methods' : 'GET,OPTIONS', 'Origin' : '*' }) testfor.body(self, r, '')
def test_put(self, note): print '\tTesting PUT method (' + note + ')' headers = {'Authorization': self.ACCESS_TOKEN} r = requests.put(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) expected_key = json.loads(self.SNIPPET) \ ['snippetTitle'] \ .replace(' ', '_') \ .lower() testfor.key_val_start(self, r, 'key', expected_key)
def test_post(self): print '\tTesting POST method' headers = {'Authorization': self.ACCESS_TOKEN} r = requests.post(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) expected_key = json.loads(self.SNIPPET) \ ['snippetTitle'] \ .replace(' ', '_') \ .lower() testfor.key_val_start(self, r, 'key', expected_key) # Update config file with received key for later tests config.update('snippet_id', r.json()['key'])