def reset_db(self): """ Takedown: Remove all test documents from prod db. """ docs = api.read_document("status", "test") for doc in docs: api.delete_document(doc) error = { "Error": "No documents found!", "alive": False } result = next(api.read_document("status", "test")) self.assertEqual(error, result, "Test documents still exist!")
def test_will_delete_one_w_document_duplicates(self): """ Test: Delete one document with document (duplicates exist). """ api.insert_documents(doc3.copy()) api.insert_documents(doc3.copy()) original = next(api.read_document(doc3.copy())) result = api.delete_document(doc3.copy()) self.assertDictEqual(original, result) # Ensure that there's still at least one document left: other = next(api.read_document(doc3.copy())) self.assertNotEqual(result["_id"], other["_id"]) # Remove the ids, it should be the only key different between the two. result.pop("_id") other.pop("_id") # Then ensure that both documents are equal to each other. This means # that two was found, but only one remains even though both documents # are identical. self.assertDictEqual(result, other)
def test_will_not_delete(self): """ Test: Won't find a document to delete. """ result = api.delete_document(doc3.copy()) self.assertIn("Error", result)
def test_will_delete_one_w_key_value(self): """ Test: Delete one document with k, v. """ api.insert_documents(doc3.copy()) doc = {"Ticker": doc3["Ticker"], "status": "test"} original = next(api.read_document(doc3.copy())) result = api.delete_document(doc) self.assertDictEqual(original, result)
def test_will_delete_one_w_document(self): """ Test: Delete one document with document. """ # This test may not run last, not sure. Regardless, lets make sure # there's something to delete. # Update: Using a test runner, so it should run last. Regardless, I'm # going to keep this insertion code in here. api.insert_documents(doc3.copy()) original = next(api.read_document(doc3.copy())) result = api.delete_document(doc3.copy()) self.assertDictEqual(original, result) error = next(api.read_document(doc3.copy())) self.assertEqual(error["Error"], "No documents found!")
def delete(symbol = ""): """ Deletes a document with given parameters @params: Symbol from route. @return: I guess the JSON object that was deleted. @h_resp: 200 OK, 404 Not Found """ status = 200 try: req = { "Ticker": symbol } res = api.delete_document(req) if "Error" in res: status = 404 # Again, api is more descriptive, so I'll just send that error. except Exception as e: print_error(e) return bottle.HTTPResponse(status = status, body = get_json(res))