async def test_post_golink_existing_non_owner(self): await self.add_golink_url(url='http://example.com/old/', owner='frank') resp = await self.post_golink() self.assert_status(resp, web.HTTPForbidden) self.assert_database( {'test': model.Golink('test', 'http://example.com/old/', 'frank')})
def assert_database(self, expected={ 'test': model.Golink('test', 'http://example.com/test/', TestAuth.USER) }): self.assertEqual(expected, self.database.golinks)
async def test_post_existing_golink(self): await self.add_golink_url(url='http://example.com/old') resp = await self.post_golink() self.assert_status(resp, web.HTTPForbidden) self.assert_database({ 'test': model.Golink('test', 'http://example.com/old', TestAuth.USER) })
async def test_post_golink_existing(self): await self.add_golink_url(url='http://example.com/old/') self.assert_database({ 'test': model.Golink('test', 'http://example.com/old/', TestAuth.USER) }) resp = await self.post_golink() self.assert_status(resp, web.HTTPSeeOther) self.assert_location(resp, '/+edit/test') self.assert_database()
async def add_golink_url(self, name='test', url='http://example.com/test/', owner=TestAuth.USER): """Add Golink URL to database.""" await self.database.insert_or_replace(model.Golink(name, url, owner))
def test_urljoin_netloc_only(self): golink = model.Golink('test', 'http://www.example.com') self.assert_urljoin('http://www.example.com', golink, '') self.assert_urljoin('http://www.example.com/123', golink, '123') self.assert_urljoin('http://www.example.com/123', golink, '/123')
def test_urljoin_with_fragments(self): golink = model.Golink('test', 'http://www.example.com/path#foo') self.assert_urljoin('http://www.example.com/path#foo', golink, '') self.assert_urljoin('http://www.example.com/path#foo123', golink, '123')
def test_urljoin_path_with_query(self): golink = model.Golink('test', 'http://www.example.com/path?q=') self.assert_urljoin('http://www.example.com/path?q=', golink, '') self.assert_urljoin('http://www.example.com/path?q=123', golink, '123') self.assert_urljoin('http://www.example.com/path?q=/123', golink, '/123')
def test_urljoin_full_path(self): golink = model.Golink('test', 'http://www.example.com/path/') self.assert_urljoin('http://www.example.com/path/', golink, '') self.assert_urljoin('http://www.example.com/path/123', golink, '123') self.assert_urljoin('http://www.example.com/path//123', golink, '/123')