def test_delete_website_document(self): webiste_nosql = WebsiteNoSql() body = {'urls': ['http://ibm.com.br']} webiste_nosql.create(2, body) webiste_nosql = WebsiteNoSql() webiste_nosql.delete(2)
def test_search_website_with_status_done(self): website = Website() website.url = "http://vtrmantovani.com.br" website.status = Website.Status.DONE db.session.add(website) db.session.commit() self.assertEqual(Website.query.count(), 1) webiste_nosql = WebsiteNoSql() body = {'urls': ['http://ibm.com.br']} webiste_nosql.create(1, body) params = {"status": "DONE", "limit": 2, "offset": 0} response = self.client.post("/api/search", headers={ 'Authorization': self.api_key, 'Content-Type': 'application/json' }, data=json.dumps(params)) r = json.loads(response.data.decode('utf-8')) self.assertEqual(response.status_code, 200) self.assertEqual(r['websites'][0]['website'], "http://vtrmantovani.com.br") # noqa self.assertEqual(r['websites'][0]['urls'][0], "http://ibm.com.br") self.assertEqual(r['total_itens'], 1) webiste_nosql.delete(1)
def test_delete_website_document_with_error(self, mock_elastich): mock_elastich.side_effect = mock.Mock( side_effect=ElasticsearchException()) # noqa with self.assertRaises(ElasticsearchException): webiste_nosql = WebsiteNoSql() webiste_nosql.delete(1) self.assertEqual(mock_elastich.call_count, 1)
def test_get_website_document(self): webiste_nosql = WebsiteNoSql() body = {'urls': ['http://ibm.com.br']} webiste_nosql.create(3, body) bd_web_site = webiste_nosql.get(3) body = {'urls': ['http://ibm.com.br']} self.assertEquals(bd_web_site['_source'], body) webiste_nosql.delete(3)
def test_update_website_document(self): webiste_nosql = WebsiteNoSql() body = {'urls': ['http://ibm.com.br']} webiste_nosql.create(4, body) body = {'urls': ['http://vtrmantovani.com.br']} webiste_nosql.update(4, body) bd_web_site = webiste_nosql.get(4) self.assertEquals(bd_web_site['_source'], body) webiste_nosql.delete(4)
def test_get_website(self): webiste_nosql = WebsiteNoSql() body = {'urls': ['http://ibm.com.br']} webiste_nosql.create(1, body) response = self.client.get( '/api/website/1', headers={'Authorization': 'PXaLogin apikey="xpo"'}) r = json.loads(response.data.decode('utf-8')) self.assertEquals(r['urls'][0], 'http://ibm.com.br') self.assertEqual(response.status_code, 200) webiste_nosql.delete(1)
def test_save_website_links_without_website_done(self): db.session.add(self.website) db.session.commit() list_urls = ['http://ibm.com.br'] website_backend = WebsiteBackend() website_backend._save_website_links(self.website, list_urls) webiste_nosql = WebsiteNoSql() self.assertEqual(Website.query.count(), 2) self.assertTrue(webiste_nosql.get(1)) webiste_nosql.delete(1)
def test_save_website_links_without_website_nosql_differents_urls(self): self.website.status = Website.Status.DONE db.session.add(self.website) db.session.commit() webiste_nosql = WebsiteNoSql() list_urls = ['http://vtrmantovani.com.br'] body = {'urls': list_urls} webiste_nosql.create(1, body) website_backend = WebsiteBackend() website_backend._save_website_links(self.website, list_urls) self.assertEqual(Website.query.count(), 1) self.assertTrue(webiste_nosql.get(1)) webiste_nosql.delete(1)