From 549e7cd01734a2ee6655de6da643aaa4cb410aa3 Mon Sep 17 00:00:00 2001
From: aknecht2 <aknecht2@unl.edu>
Date: Mon, 29 Feb 2016 16:11:00 -0600
Subject: [PATCH] Added new tests.  Added all sample verification.

---
 chipathlon/db.py     | 27 +++++++++++++++++++++++++++
 chipathlon/tester.py | 17 +++++++++++++++--
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/chipathlon/db.py b/chipathlon/db.py
index 2eeef6e..8846474 100644
--- a/chipathlon/db.py
+++ b/chipathlon/db.py
@@ -22,6 +22,33 @@ class MongoDB(object):
 
         return
 
+    def check_valid_samples(self):
+        cursor = self.db.experiments.aggregate([
+            {
+                "$match": {
+                    "target": {"$exists": True},
+                    "revoked_files.0": {"$exists": False},
+                    "assembly.0": {"$exists": True},
+                    "assembly.1": {"$exists": False}
+                }
+            },
+            {
+                "$lookup": {
+                    "from": "samples",
+                    "localField": "_id",
+                    "foreignField": "experiment_id",
+                    "as": "samples"
+                }
+            }
+        ])
+        total = 0
+        has_samples = 0
+        for document in cursor:
+            total += 1
+            if len(document["samples"]) > 0:
+                has_samples += 1
+        return (has_samples, total)
+
     def get_samples(self, experiment_id):
         valid = True
         msg = ""
diff --git a/chipathlon/tester.py b/chipathlon/tester.py
index ad96938..389cac6 100644
--- a/chipathlon/tester.py
+++ b/chipathlon/tester.py
@@ -75,12 +75,23 @@ def exp_files_test_3():
     print_test("Exp_Files_Test_3", not valid and msg == "Experiment with id 'ENCSR329RIP' does not have all required metadata (assembly, target, no revoked_files).")
     return
 
-# Test8, multiple control experiments, no possible control_inputs
+# Test8, multiple control experiments
 def exp_files_test_4():
     valid, msg, data = mdb.get_samples("ENCSR000CWZ")
     print_test("Exp_Files_Test_4", valid and msg == "Succesfully retrieved input files for experiment with id 'ENCSR000CWZ'." and len(data["control"]) == 4 and len(data["experiment"]) == 2)
     return
 
+# Test9, multiple control experiments, no possible control_inputs
+def exp_files_test_5():
+    valid, msg, data = mdb.get_samples("ENCSR000DKB")
+    print_test("Exp_Files_Test_5", not valid and msg == "Experiment with id 'ENCSR000DKB' has '0' possible control inputs, and '3' possible experiment inputs.")
+    return
+
+def valid_samples():
+    has_samples, total = mdb.check_valid_samples()
+    print_test("Verify_All_Samples", has_samples == total)
+    return
+
 
 
 tests = [
@@ -91,7 +102,9 @@ tests = [
     exp_files_test_1,
     exp_files_test_2,
     exp_files_test_3,
-    exp_files_test_4
+    exp_files_test_4,
+    exp_files_test_5,
+    valid_samples
 ]
 for test in tests:
     test()
-- 
GitLab