예제 #1
0
    def _bounce_post_job(self, url, uid, value, to_cache=False, params=None):
        """
        Requests a post job given an url, uid and value, and optionally a
        get url parameters.

        Optionally inserts the record into cache.

        Returns False if response code is not 200. Converts the response
        content into a valid record if possible and returns the record on
        success.

        :param url: str
        :param uid: str
        :param value: str
        :param to_cache: bool. If True records the response into cache.
        :param params: dict
        :return: dict
        """
        response = Helpers.request_post(
            url=url,
            dirs=[uid],
            data={'value': value},
            params=params,
        )

        record = RecordHelper.str2record(content=response.content)

        if response.status_code != 200 or not record:
            return False

        if to_cache:
            self._cache.put(record)

        return record
예제 #2
0
파일: storage.py 프로젝트: westial/minstore
    def _read(self):
        """
        Reads the file and returns the content formatted as expected record
        :return dict
        """
        content = self._file.read()
        record = RecordHelper.str2record(content=content)

        return record
예제 #3
0
파일: storage.py 프로젝트: westial/minstore
    def _read(self):
        """
        Reads the file and returns the content formatted as expected record
        :return dict
        """
        content = self._file.read()
        record = RecordHelper.str2record(content=content)

        return record
예제 #4
0
파일: api.py 프로젝트: westial/minstore
    def _copy_input(self, content):
        """
        Given a formatted json string updates the record related to.
        :param content: str
        :return: dict
        """
        record = RecordHelper.str2record(content=content)

        if not record:
            return None

        self._model.copy(record=record)

        return record
예제 #5
0
    def _copy_input(self, content):
        """
        Given a formatted json string updates the record related to.
        :param content: str
        :return: dict
        """
        record = RecordHelper.str2record(content=content)

        if not record:
            return None

        self._model.copy(record=record)

        return record
예제 #6
0
    def _bounce_get_job(cls, url, uid, params=None):
        """
        Requests a get job given an url and uid, and optionally a set of url
        parameters.

        Returns False if response code is not 200. Converts the response
        content into a valid record if possible and returns the record on
        success.

        :param url: str
        :param uid: str
        :param params: dict
        :return: dict
        """
        response = Helpers.request_get(url=url, dirs=[uid], params=params)

        record = RecordHelper.str2record(content=response.content)

        if response.status_code != 200 or not record:
            return False

        return record
예제 #7
0
파일: test.py 프로젝트: westial/minstore
    def triple_server_inequable(self, route_key):
        self.start_triple_server(key=route_key)

        uid = self.sample_fixed['uid']
        value = self.sample_fixed['value']
        response = Helpers.request_post(
            url=URL1,
            dirs=['text', uid],
            data={'value': value})
        self.assertEqual(response.status_code, 200)

        time.sleep(10)

        Helpers.delete_file(
            file_path='test-sandbox/{key}/{key}1/{uid}'.format(key=route_key,
                                                               uid=uid)
        )

        exists1 = Helpers.path_exists(
            'test-sandbox/{key}/{key}1/{uid}'.format(key=route_key, uid=uid)
        )

        self.assertFalse(exists1, 'Record 1 still exists')

        record2 = self.get_record_by_path(
            'test-sandbox/{key}/{key}2/{uid}'.format(key=route_key, uid=uid)
        )
        record3 = self.get_record_by_path(
            'test-sandbox/{key}/{key}3/{uid}'.format(key=route_key, uid=uid)
        )

        self.assertEqual(record2, record3, 'POST: Record 2 and 3')
        self.assertEqual(record2['uid'], uid, 'POST: Unexpected uid')

        response = Helpers.request_get(
            url=URL1,
            dirs=['text', uid])

        self.assertEqual(response.status_code, 200, 'Get failed')

        record1 = RecordHelper.str2record(content=response.content)

        self.assertEqual(record1, record2, 'POST: Record 1 and 2')

        response = Helpers.request_delete(
            url=URL1,
            dirs=['text', uid])

        self.assertEqual(response.status_code, 200)

        time.sleep(10)

        exists1 = Helpers.path_exists(
            'test-sandbox/{key}/{key}1/{uid}'.format(key=route_key, uid=uid)
        )
        exists2 = Helpers.path_exists(
            'test-sandbox/{key}/{key}2/{uid}'.format(key=route_key, uid=uid)
        )
        exists3 = Helpers.path_exists(
            'test-sandbox/{key}/{key}3/{uid}'.format(key=route_key, uid=uid)
        )

        self.assertFalse(exists1)
        self.assertFalse(exists2)
        self.assertFalse(exists3)

        self.stop_all_apis()