示例#1
0
 def _put_job(self, url, dirs, params, data):
     """Puts result data job
     """
     Helpers.request_put(url=url,
                         dirs=dirs,
                         data=data,
                         params=params)
示例#2
0
文件: test.py 项目: westial/minstore
    def test_put_exists(self):
        self.start_simple_server()
        first_content = self.sample_fixed['value']
        second_content = 'New content.'

        response = Helpers.request_post(
            url=URL,
            dirs=['text', self.sample_fixed['uid']],
            data={'value': first_content})

        self.assertEqual(response.status_code, 200, 'First post failed')

        first_len = len(response.content)
        difference = len(second_content) - len(first_content)
        expected_second_len = first_len + difference

        response = Helpers.request_put(
            url=URL,
            dirs=['text', self.sample_fixed['uid']],
            data={'value': 'New content.'})

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

        second_len = len(response.content)

        second_len -= 1     # Due to optional negative sign on check_sum

        self.assertLessEqual(second_len, expected_second_len)

        response = Helpers.request_delete(
            url=URL,
            dirs=['text', self.sample_fixed['uid']])

        self.assertEqual(response.status_code, 200, 'Delete failed')
示例#3
0
    def _bounce_put_job(self, url, uid, value, to_cache=False, params=None):
        """
        Requests a put job given an url, uid and value, and optionally a
        get url parameters.

        Optionally updates 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_put(
            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
示例#4
0
文件: test.py 项目: westial/minstore
    def test_put_not_exists_error(self):
        self.start_simple_server()
        response = Helpers.request_put(
            url=URL,
            dirs=['text', self.new_uid()],
            data={'value': 'dummy content'})

        self.assertEqual(response.status_code, 404)
示例#5
0
文件: test.py 项目: westial/minstore
    def triple_server_common(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)

        record1 = self.get_record_by_path(
            'test-sandbox/{key}/{key}1/{uid}'.format(key=route_key, uid=uid)
        )
        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(record1, record2, 'POST: Record 1 and 2')
        self.assertEqual(record2, record3, 'POST: Record 2 and 3')
        self.assertEqual(record1['uid'], uid, 'POST: Unexpected uid')

        value = 'I have changed the content on first and {!s} site too.'\
            .format(route_key)

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

        response_record = self.get_record_by_response_content(response.content)

        self.assertEqual(response_record['value'][0:20], value[0:20])

        time.sleep(10)

        record1 = self.get_record_by_path(
            'test-sandbox/{key}/{key}1/{uid}'.format(key=route_key, uid=uid)
        )
        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(record1, record2, 'PUT: Record 1 and 2')
        self.assertEqual(record2, record3, 'PUT: Record 2 and 3')
        self.assertEqual(record1['uid'], uid, 'PUT: Unexpected uid')

        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()
示例#6
0
文件: test.py 项目: westial/minstore
    def test_cache(self):
        route_key = 'cache'
        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},
            params={CACHE_MODE: int(True)},
        )
        self.assertEqual(response.status_code, 200)

        time.sleep(10)

        self.assertRaises(IOError,
                          self.get_record_by_path,
                          'test-sandbox/{key}/{key}1/{uid}'.format(
                              key=route_key,
                              uid=uid
                          ))

        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.assertNotEqual(record2, record3, 'POST: Record 2 and 3 are equal')
        self.assertEqual(record2['value'], record3['value'],
                         'POST: Record 2 and 3 different values')
        self.assertEqual(record2['uid'], uid, 'POST: Unexpected uid')

        value = 'I have changed the content on first and {!s} site too.'\
            .format(route_key)

        response = Helpers.request_put(
            url=URL1,
            dirs=['text', uid],
            data={'value': value},
            params={CACHE_MODE: int(True)},
        )
        self.assertEqual(response.status_code, 200)

        response_record = self.get_record_by_response_content(response.content)

        self.assertEqual(response_record['value'][0:20], value[0:20])

        time.sleep(10)

        self.assertRaises(IOError,
                          self.get_record_by_path,
                          'test-sandbox/{key}/{key}1/{uid}'.format(
                              key=route_key,
                              uid=uid
                          ))

        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.assertNotEqual(record2, record3, 'PUT: Record 2 and 3 are equal')
        self.assertEqual(record2['value'], record3['value'],
                         'PUT: Record 2 and 3 different values')
        self.assertEqual(record2['uid'], uid, 'PUT: Unexpected uid')

        response = Helpers.request_delete(
            url=URL1,
            dirs=['text', uid],
            params={CACHE_MODE: int(True)},
        )

        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()