def test_create_and_download(self, content): """ Upload some content (via 'PUT /uri') and then download it (via 'GET /uri?uri=...') """ http_client = create_tahoe_treq_client() @inlineCallbacks def do_test(): resp = yield http_client.put("http://example.com/uri", content) self.assertThat(resp.code, Equals(201)) cap_raw = yield resp.content() cap = from_string(cap_raw) self.assertThat(cap, IsInstance(CHKFileURI)) resp = yield http_client.get( "http://example.com/uri?uri={}".format(cap.to_string())) self.assertThat(resp.code, Equals(200)) round_trip_content = yield resp.content() # using the form "/uri/<cap>" is also valid resp = yield http_client.get("http://example.com/uri/{}".format( cap.to_string())) self.assertEqual(resp.code, 200) round_trip_content = yield resp.content() self.assertEqual(content, round_trip_content) self.assertThat( do_test(), succeeded(Always()), )
def test_duplicate_upload(self, content): """ Upload the same content (via 'PUT /uri') twice """ http_client = create_tahoe_treq_client() @inlineCallbacks def do_test(): resp = yield http_client.put("http://example.com/uri", content) self.assertEqual(resp.code, 201) cap_raw = yield resp.content() self.assertThat( cap_raw, AfterPreprocessing( from_string, IsInstance(CHKFileURI) ) ) resp = yield http_client.put("http://example.com/uri", content) self.assertThat(resp.code, Equals(200)) self.assertThat( do_test(), succeeded(Always()), )
def test_download_no_arg(self): """ Error if we GET from "/uri" with no ?uri= query-arg """ http_client = create_tahoe_treq_client() uri = DecodedURL.from_text(u"http://example.com/uri/") resp = http_client.get(uri.to_uri().to_text()) self.assertThat(resp, succeeded(MatchesStructure(code=Equals(400))))
def test_download_missing(self): """ Error if we download a capability that doesn't exist """ http_client = create_tahoe_treq_client() cap_gen = capability_generator("URI:CHK:") uri = DecodedURL.from_text(u"http://example.com/uri?uri={}".format( next(cap_gen))) resp = http_client.get(uri.to_uri().to_text()) self.assertThat(resp, succeeded(MatchesStructure(code=Equals(500))))