def teste_excluir_documento_valido(self): string_json = '{"projeto": "teste_excluir"}' Op.inserir_json(self.colecao, string_json) valor_obtido = Op.buscar_json(self.colecao, string_json).count() self.assertEqual(valor_obtido, 1) Op.excluir_json(self.colecao, string_json) valor_obtido = Op.buscar_json(self.colecao, string_json).count() self.assertEqual(valor_obtido, 0)
def teste_alterar_documento_valido(self): string_json_inserir = '{"projeto": "teste_altera"}' Op.inserir_json(self.colecao, string_json_inserir) string_json_alterar = '{"projeto": "teste_alterado"}' retorno = Op.alterar_json(self.colecao, string_json_inserir, string_json_alterar) self.assertTrue(retorno) Op.excluir_json(self.colecao, string_json_alterar)
def teste_alterar_json_nova_vazia(self): string_json_inserir = '{"projeto": "teste_altera"}' Op.inserir_json(self.colecao, string_json_inserir) string_nova_json = '{}' with self.assertRaises(SystemExit) as ex: Op.alterar_json(self.colecao, string_json_inserir, string_nova_json) self.assertEqual(ex.exception.code, 5) Op.excluir_json(self.colecao, string_json_inserir)
def teste_inserir_documento_duplicado(self): string_json = '{"projeto": "teste_inserir"}' Op.inserir_json(self.colecao, string_json) Op.inserir_json(self.colecao, string_json) valor_obtido = Op.buscar_json(self.colecao, string_json).count() self.assertEqual(valor_obtido, 2) retorno = Op.excluir_json(self.colecao, string_json) self.assertTrue(retorno) retorno2 = Op.excluir_json(self.colecao, string_json) self.assertTrue(retorno2)
def __busca_projeto(self): string_busca = '{"projeto":"' + self.nome_projeto + '"}' documentos_encontrados = Operacoes.buscar_json(self.colecao, string_busca) if documentos_encontrados.count() == 0: Log.imprime("A BUSCA NAO RETORNOU NENHUM DOCUMENTO REFERENTE AO PROJETO.\nNOME DE PROJETO INFORMADO: " + self.nome_projeto + "INSERINDO PROJETO NO MONGO", classe=InformacoesArtefatos) Operacoes.inserir_json(self.colecao, string_busca) self.__conexao.fechar_conexao() return documentos_encontrados[0]
def teste_inserir_json_vazio(self): string_json = '{}' with self.assertRaises(SystemExit) as ex: Op.inserir_json(self.colecao, string_json) self.assertEqual(ex.exception.code, 3)