diff options
author | louib <L0U13@protonmail.com> | 2019-06-17 04:33:13 +0300 |
---|---|---|
committer | Jonathan White <support@dmapps.us> | 2019-09-22 19:42:53 +0300 |
commit | 77fcde875e78fa44fc664b92e77db14f41b92c0b (patch) | |
tree | fbad6e7fe4695bac9dec72244d6cd13a5d43e2f9 /tests | |
parent | 547c246e8872d90daf2b09de58a4913bb5d66a7e (diff) |
CLI: Export database as CSV
* Changed `Extract` to `Export` to support additional formats
* Allow database expot as CSV. Added a `--format` option to the `Export` command for that, which defaults to xml, so the current behavior is unchanged.
*The `CsvExporter` had to be refactored a bit, but nothing major. It can
now print to a file or return a string.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/TestCli.cpp | 45 | ||||
-rw-r--r-- | tests/TestCli.h | 2 |
2 files changed, 38 insertions, 9 deletions
diff --git a/tests/TestCli.cpp b/tests/TestCli.cpp index 0b7de14e7..d1ae3992d 100644 --- a/tests/TestCli.cpp +++ b/tests/TestCli.cpp @@ -39,7 +39,7 @@ #include "cli/Diceware.h" #include "cli/Edit.h" #include "cli/Estimate.h" -#include "cli/Extract.h" +#include "cli/Export.h" #include "cli/Generate.h" #include "cli/List.h" #include "cli/Locate.h" @@ -170,7 +170,7 @@ void TestCli::testCommand() QVERIFY(Command::getCommand("diceware")); QVERIFY(Command::getCommand("edit")); QVERIFY(Command::getCommand("estimate")); - QVERIFY(Command::getCommand("extract")); + QVERIFY(Command::getCommand("export")); QVERIFY(Command::getCommand("generate")); QVERIFY(Command::getCommand("locate")); QVERIFY(Command::getCommand("ls")); @@ -742,14 +742,14 @@ void TestCli::testEstimate() } } -void TestCli::testExtract() +void TestCli::testExport() { - Extract extractCmd; - QVERIFY(!extractCmd.name.isEmpty()); - QVERIFY(extractCmd.getDescriptionLine().contains(extractCmd.name)); + Export exportCmd; + QVERIFY(!exportCmd.name.isEmpty()); + QVERIFY(exportCmd.getDescriptionLine().contains(exportCmd.name)); Utils::Test::setNextPassword("a"); - extractCmd.execute({"extract", m_dbFile->fileName()}); + exportCmd.execute({"export", m_dbFile->fileName()}); m_stdoutFile->seek(0); m_stdoutFile->readLine(); // skip prompt line @@ -768,12 +768,41 @@ void TestCli::testExtract() // Quiet option QScopedPointer<Database> dbQuiet(new Database()); qint64 pos = m_stdoutFile->pos(); + qint64 posErr = m_stderrFile->pos(); Utils::Test::setNextPassword("a"); - extractCmd.execute({"extract", "-q", m_dbFile->fileName()}); + exportCmd.execute({"export", "-f", "xml", "-q", m_dbFile->fileName()}); m_stdoutFile->seek(pos); + m_stderrFile->seek(posErr); reader.readDatabase(m_stdoutFile.data(), dbQuiet.data()); QVERIFY(!reader.hasError()); QVERIFY(db.data()); + QCOMPARE(m_stderrFile->readAll(), QByteArray("")); + + // CSV exporting + pos = m_stdoutFile->pos(); + posErr = m_stderrFile->pos(); + Utils::Test::setNextPassword("a"); + exportCmd.execute({"export", "-f", "csv", m_dbFile->fileName()}); + m_stdoutFile->seek(pos); + m_stdoutFile->readLine(); // skip prompt line + m_stderrFile->seek(posErr); + QByteArray csvHeader = m_stdoutFile->readLine(); + QCOMPARE(csvHeader, QByteArray("\"Group\",\"Title\",\"Username\",\"Password\",\"URL\",\"Notes\"\n")); + QByteArray csvData = m_stdoutFile->readAll(); + QVERIFY(csvData.contains(QByteArray( + "\"NewDatabase\",\"Sample Entry\",\"User Name\",\"Password\",\"http://www.somesite.com/\",\"Notes\"\n"))); + QCOMPARE(m_stderrFile->readAll(), QByteArray("")); + + // test invalid format + pos = m_stdoutFile->pos(); + posErr = m_stderrFile->pos(); + Utils::Test::setNextPassword("a"); + exportCmd.execute({"export", "-f", "yaml", m_dbFile->fileName()}); + m_stdoutFile->seek(pos); + m_stdoutFile->readLine(); // skip prompt line + m_stderrFile->seek(posErr); + QCOMPARE(m_stdoutFile->readLine(), QByteArray("")); + QCOMPARE(m_stderrFile->readLine(), QByteArray("Unsupported format yaml\n")); } void TestCli::testGenerate_data() diff --git a/tests/TestCli.h b/tests/TestCli.h index a313fe224..09c55e0ed 100644 --- a/tests/TestCli.h +++ b/tests/TestCli.h @@ -52,7 +52,7 @@ private slots: void testEdit(); void testEstimate_data(); void testEstimate(); - void testExtract(); + void testExport(); void testGenerate_data(); void testGenerate(); void testKeyFileOption(); |