Example #1
0
    def test_get(self):
        print '\tTesting GET method'
        r = requests.get(self.API_URL)

        testfor.status_code(self, r, 200)
        testfor.valid_json(self, r)
        testfor.body(self, r, self.SNIPPET)
    def test_get(self):
        print '\tTesting GET method'
        r = requests.get(self.API_URL)

        testfor.status_code(self, r, 200)
        testfor.valid_json(self, r)

        print '\t\tBody object keys should be valid snippet meta data'
        schema = {
            'title': 'Snippet Meta Data',
            'type': 'object',
            'properties': {
                'snippetTitle': {
                    'type': 'string'
                },
                'language': {
                    'type': 'string'
                },
                'lastEdited': {
                    'type': 'string'
                },
            },
            'required': ['snippetTitle', 'language', 'lastEdited'],
        }
        for key, value in r.json().items():
            try:
                validate(value, schema)
            except ValidationError as error:
                self.fail('Body object keys not valid snippet meta data')
                print error
Example #3
0
    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_get_with_query (self):
        print '\tTesting GET method (with query string)'
        url = self.API_URL + "?users=" + self.USER_ID
        r = requests.get(url)

        testfor.status_code(self, r, 200)
        testfor.valid_json(self, r)

        print '\t\tBody object keys should be valid index entries'
        schema = {
            'title'      : 'Index Entry',
            'type'       : 'object',
            'properties' : {
                'lastEdited'   : {'type' : 'string'},
                'language'     : {'type' : 'string'},
                'snippetTitle' : {'type' : 'string'},
            },
            'required': ['lastEdited', 'language', 'snippetTitle'],
        }
        index = r.json()[self.USER_ID].items()
        for snippet, entry in index:
            try:
                validate(entry, schema)
            except ValidationError as error:
                self.fail('Found invalid index entry')
    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')
Example #7
0
    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.')
Example #8
0
    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'])
    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')
Example #11
0
    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')
    def test_get_no_query (self):
        print '\tTesting GET method (with no query string)'
        r = requests.get(self.API_URL)

        testfor.status_code(self, r, 200)
        testfor.valid_json(self, r)

        print '\t\tBody object keys should be valid index entries'
        schema = {
            'title'      : 'Index Entry',
            'type'       : 'object',
            'properties' : {
                'lastEdited'   : {'type' : 'string'},
                'language'     : {'type' : 'string'},
                'snippetTitle' : {'type' : 'string'},
            },
            'required': ['lastEdited', 'language', 'snippetTitle'],
        }
        for user, index in r.json().items():
            for snippet, entry in index.items():
                try:
                    validate(entry, schema)
                except ValidationError as error:
                    self.fail('Found invalid index entry')