summaryrefslogtreecommitdiff
path: root/gentoobrowse-api/unittests
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-12-02 21:27:50 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2016-12-02 21:27:50 +0000
commit9101b953e4434d1a50aa42d7329dfb8223a0b333 (patch)
treee561e24bcb81407bc1cc1fd8b729dcfa9858b81c /gentoobrowse-api/unittests
parentFix use flag ordering to be not locale sensitive and resulting changes in tes... (diff)
downloadgentoobrowse-api-9101b953e4434d1a50aa42d7329dfb8223a0b333.tar.bz2
gentoobrowse-api-9101b953e4434d1a50aa42d7329dfb8223a0b333.tar.xz
gentoobrowse-api-9101b953e4434d1a50aa42d7329dfb8223a0b333.zip
Basic notification service implementation
Diffstat (limited to 'gentoobrowse-api/unittests')
-rw-r--r--gentoobrowse-api/unittests/Jamfile.jam8
-rw-r--r--gentoobrowse-api/unittests/mockDefs.cpp5
-rw-r--r--gentoobrowse-api/unittests/mockDefs.h3
-rw-r--r--gentoobrowse-api/unittests/testNotifications.cpp102
4 files changed, 118 insertions, 0 deletions
diff --git a/gentoobrowse-api/unittests/Jamfile.jam b/gentoobrowse-api/unittests/Jamfile.jam
index 92501c0..70fa90f 100644
--- a/gentoobrowse-api/unittests/Jamfile.jam
+++ b/gentoobrowse-api/unittests/Jamfile.jam
@@ -98,6 +98,14 @@ run
: testUsers ;
run
+ testNotifications.cpp
+ : : :
+ <dependency>../db/schema.sql
+ <define>BOOST_TEST_DYN_LINK
+ <library>testCommon
+ : testNotifications ;
+
+run
testBugs.cpp
: : :
<dependency>../db/schema.sql
diff --git a/gentoobrowse-api/unittests/mockDefs.cpp b/gentoobrowse-api/unittests/mockDefs.cpp
index 70f5b69..eeab5f2 100644
--- a/gentoobrowse-api/unittests/mockDefs.cpp
+++ b/gentoobrowse-api/unittests/mockDefs.cpp
@@ -2,6 +2,9 @@
#include <definedDirs.h>
Service::Service() :
+ IceTray::DryIce({
+ "--GentooBrowseAPI.MailServer=smtp.random.lan:25",
+ }),
PQ::Mock("user=postgres dbname=postgres", "GentooBrowseAPI", {
rootDir.parent_path() / "db" / "schema.sql",
rootDir / "data.sql" })
@@ -22,6 +25,8 @@ Maintenance::Maintenance() :
TestClient::TestClient() :
m(getProxy<Gentoo::MaintenancePrx>("maintenance")),
p(getProxy<Gentoo::PortagePrx>("portage")),
+ n(getProxy<Gentoo::NotificationsPrx>("notifications")),
+ ms(getProxy<Gentoo::MailServerPrx>("mailserver")),
u(getProxy<Gentoo::UsersPrx>("users"))
{
}
diff --git a/gentoobrowse-api/unittests/mockDefs.h b/gentoobrowse-api/unittests/mockDefs.h
index 9a35c1f..a0c044a 100644
--- a/gentoobrowse-api/unittests/mockDefs.h
+++ b/gentoobrowse-api/unittests/mockDefs.h
@@ -7,6 +7,7 @@
#include <portage.h>
#include <users.h>
#include <maintenance.h>
+#include <notifications.h>
#include <selectcommandUtil.impl.h>
class DLL_PUBLIC Service : public IceTray::DryIce, PQ::Mock {
@@ -25,6 +26,8 @@ class DLL_PUBLIC TestClient : public IceTray::DryIceClient {
Gentoo::MaintenancePrx m;
Gentoo::PortagePrx p;
+ Gentoo::NotificationsPrx n;
+ Gentoo::MailServerPrx ms;
Gentoo::UsersPrx u;
};
diff --git a/gentoobrowse-api/unittests/testNotifications.cpp b/gentoobrowse-api/unittests/testNotifications.cpp
new file mode 100644
index 0000000..81b28d0
--- /dev/null
+++ b/gentoobrowse-api/unittests/testNotifications.cpp
@@ -0,0 +1,102 @@
+#define BOOST_TEST_MODULE TestNotifications
+#include <boost/test/unit_test.hpp>
+
+#include "mockDefs.h"
+#include <fstream>
+
+BOOST_GLOBAL_FIXTURE( Service );
+
+BOOST_FIXTURE_TEST_SUITE(tp, TestClient);
+
+bool
+isHtml(const std::string & body)
+{
+ return body.find("<html") != std::string::npos;
+}
+
+void
+save(const std::string & name, Gentoo::EmailPtr e)
+{
+ std::ofstream text("/tmp/" + name + ".txt");
+ text << e->body[0]->payload;
+ std::ofstream html("/tmp/" + name + ".html");
+ html << e->body[1]->payload;
+}
+
+void
+commonAssert(Gentoo::EmailPtr e)
+{
+ BOOST_REQUIRE_EQUAL(e->body.size(), 2);
+ BOOST_REQUIRE_EQUAL(e->body[0]->mimetype, "text/plain");
+ BOOST_REQUIRE(!isHtml(e->body[0]->payload));
+ BOOST_REQUIRE_EQUAL(e->body[1]->mimetype, "text/html");
+ BOOST_REQUIRE(isHtml(e->body[1]->payload));
+}
+
+#if 0
+BOOST_AUTO_TEST_CASE( testSend )
+{
+ Gentoo::NewUserPtr u = new Gentoo::NewUser(1, "testuser", "Test User", "dangoodliffe@gmail.com", "some-guid");
+ auto e = n->getSignup(u);
+ BOOST_REQUIRE(e);
+ ms->sendEmail(e);
+}
+#endif
+
+BOOST_AUTO_TEST_CASE( testSignup )
+{
+ Gentoo::NewUserPtr u = new Gentoo::NewUser(1, "testuser", "Test User", "test@user.com", "some-guid");
+ auto e = n->getSignup(u);
+ BOOST_REQUIRE(e);
+ BOOST_REQUIRE_EQUAL(e->subject, "Gentoo Browse: Welcome");
+ BOOST_REQUIRE_EQUAL(e->from.name, "Gentoo Browse");
+ BOOST_REQUIRE_EQUAL(e->from.address, "noreply@gentoobrowse.randomdan.homeip.net");
+ BOOST_REQUIRE_EQUAL(e->to.name, "Test User");
+ BOOST_REQUIRE_EQUAL(e->to.address, "test@user.com");
+ commonAssert(e);
+ save("signup", e);
+ for (auto p : e->body) {
+ BOOST_REQUIRE(p->payload.find("Welcome to Gentoo Browse") != std::string::npos);
+ BOOST_REQUIRE(p->payload.find("http://gentoobrowse.randomdan.homeip.net/user/verify/some-guid") != std::string::npos);
+ BOOST_REQUIRE(p->payload.find("confirmation page: some-guid") != std::string::npos);
+ }
+}
+
+BOOST_AUTO_TEST_CASE( testNews )
+{
+ Gentoo::UserPtr u = new Gentoo::User(1, "testuser", "Test User", "test@user.com");
+ Gentoo::NewsContent nc {
+ {
+ new Gentoo::Category(1, "app-test", "Test cat1"),
+ new Gentoo::Category(2, "sys-test", "Test cat2"),
+ new Gentoo::Category(3, "no-show", "Unused cat")
+ },
+ {
+ new Gentoo::Package(1, 1, "app1", "first-seen", "Test app desc one", "Test summary 1", IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None),
+ new Gentoo::Package(2, 1, "app2", "first-seen", "Test app desc two", "Test summary 1", IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None),
+ new Gentoo::Package(3, 2, "app3", "first-seen", "Test app desc three", "Test summary 1", IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None),
+ new Gentoo::Package(4, 2, "app4", "first-seen", "Test app no-show", "Test summary 1", IceUtil::None, IceUtil::None, IceUtil::None, IceUtil::None)
+ },
+ {
+ new Gentoo::Ebuild(1, 1, 1, "1.0a", "slot", "first-seen", "last-mod", IceUtil::None),
+ new Gentoo::Ebuild(2, 1, 1, "1.1a", "slot", "first-seen", "last-mod", IceUtil::None),
+ new Gentoo::Ebuild(3, 1, 1, "1.2a", "slot", "first-seen", "last-mod", IceUtil::None),
+ new Gentoo::Ebuild(4, 2, 1, "2.0a", "slot", "first-seen", "last-mod", IceUtil::None),
+ new Gentoo::Ebuild(5, 3, 1, "3.0a", "slot", "first-seen", "last-mod", IceUtil::None),
+ new Gentoo::Ebuild(6, 2, 1, "2.1a", "slot", "first-seen", "last-mod", IceUtil::None),
+ new Gentoo::Ebuild(7, 3, 1, "3.1a", "slot", "first-seen", "last-mod", IceUtil::None)
+ }
+ };
+ auto e = n->getNews(u, nc);
+ commonAssert(e);
+ save("news", e);
+ for (auto p : e->body) {
+ BOOST_REQUIRE(p->payload.find("Latest news") != std::string::npos);
+ // BOOST_REQUIRE(p->payload.find("http://gentoobrowse.randomdan.homeip.net/packages/app-test") != std::string::npos);
+ // BOOST_REQUIRE(p->payload.find("http://gentoobrowse.randomdan.homeip.net/packages/app-test/app") != std::string::npos);
+ BOOST_REQUIRE(p->payload.find("no-show") == std::string::npos);
+ }
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+