示例#1
0
文件: test.py 项目: westial/minstore
    def test_delete_not_exists_error(self):
        self.start_simple_server()
        response = Helpers.request_delete(
            url=URL,
            dirs=['text', self.new_uid()])

        self.assertEqual(response.status_code, 404)
示例#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_delete_job(self, url, uid, params=None):
        """
        Requests a delete job given an url, uid and value, and optionally a
        get url parameters.

        Returns False if response code is not 200.

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

        if response.status_code != 200:
            return False

        try:
            self._cache.forget(uid=uid)

        finally:
            return True
示例#4
0
文件: test.py 项目: westial/minstore
    def test_post_new(self):
        self.start_simple_server()
        uid = self.new_uid()
        response = Helpers.request_post(
            url=URL,
            dirs=['text', uid],
            data={'value': self.sample_normal['value']})
        self.assertEqual(response.status_code, 200, 'Post failed')

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

        self.assertEqual(response.status_code, 200, 'Delete failed')
示例#5
0
文件: test.py 项目: westial/minstore
    def test_get_exists(self):
        self.start_simple_server()
        uid = self.sample_fixed_len['uid']
        expected_len = 158
        response = Helpers.request_post(
            url=URL,
            dirs=['text', uid],
            data={'value': self.sample_fixed_len['value']})
        self.assertEqual(response.status_code, 200, 'Post failed')

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

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

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

        self.assertEqual(response.status_code, 200, 'Delete failed')
示例#6
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()
示例#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()
示例#8
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()
示例#9
0
    def _delete_job(self, url, dirs, params):
        Helpers.request_delete(url=url, dirs=dirs, params=params)

        uid = dirs[-1]
        self._cache.forget(uid=uid)