Ejemplo n.º 1
0
    def test_dhcp(self):
        doc1 = {
            "action": "",
            "device_name": "psxrjs-mbp",
            "host_name": "psxrjs-mbp",
            "ip_address": "10.2.0.1",
            "mac_address": "68:a8:6d:3b:05:e4",
            "name": "Rob",
            "state": "permit",
            "timestamp": time.time(),
            "collection": "devices",
            "lease_action": "add",
            "device_type": "laptop",
            "notification_service": "email",
            "connection_event": "connect",
            "changed_by": "system"
        }

        db = couchdb_config_parser.get_db()
        res = db.save_doc(doc1)
        vr = db.view("homework-remote/dhcp")
        vra = vr.all()
        self.assertEqual(vr.count(), 1)
        self.assertEqual(vra[0]['id'], res['id'])
        self.assertEqual(vra[0]['key'], "68:a8:6d:3b:05:e4")
        doc1['_deleted'] = True
        db.save_doc(doc1, force_update=True)
Ejemplo n.º 2
0
    def test_notifications(self):
        inc = {
            "collection": "notifications",
            "status": "pending",
            "name": "Rob",
            "service": "email",
            "user": "******"
        }

        not_inc = {
            "collection": "notifications",
            "status": "done",
            "name": "Rob",
            "service": "email",
            "user": "******"
        }

        db = couchdb_config_parser.get_db()
        res = db.save_doc(inc)
        res2 = db.save_doc(not_inc)
        stream = ChangesStream(db, filter="homework-remote/notifications")
        self.assertEqual(1, len(list(stream)))
        self.assertEqual(res['id'], list(stream)[0]['id'])
        inc['hidden'] = True
        not_inc['hidden'] = True
        db.save_doc(inc, force_update=True)
        db.save_doc(not_inc, force_update=True)
Ejemplo n.º 3
0
    def test_wifi(self):
        inc = {
            "collection": "wifi",
            "status": "pending",
            "ssid": "spencer",
            "encryption_type": "wpa",
            "channel": 1,
            "mode": "g",
            "password_type": "txt",
            "password": "******"
        }

        not_inc = {
            "collection": "wifi",
            "status": "done",
            "ssid": "spencer",
            "encryption_type": "wpa",
            "channel": 1,
            "mode": "g",
            "password_type": "txt",
            "password": "******"
        }

        db = couchdb_config_parser.get_db()
        res = db.save_doc(inc)
        res2 = db.save_doc(not_inc)
        stream = ChangesStream(db, filter="homework-remote/wifi")
        self.assertEqual(1, len(list(stream)))
        self.assertEqual(res['id'], list(stream)[0]['id'])
        inc['hidden'] = True
        not_inc['hidden'] = True
        db.save_doc(inc, force_update=True)
        db.save_doc(not_inc, force_update=True)
Ejemplo n.º 4
0
 def test_events(self):
     doc = {
         "timestamp":
         datetime.datetime.now(tzutc()).isoformat(),
         "collection":
         "events",
         "title":
         "testing",
         "description":
         "testing, testing, 1,2,3",
         "undoable":
         True,
         "perform_undo":
         False,
         "docs": [{
             "doc_id": "aabbcc",
             "doc_rev": "1-aabbcc",
             "doc_collection": "devices",
             "action": "edit"
         }]
     }
     db = couchdb_config_parser.get_db()
     res = db.save_doc(doc)
     vr = db.view("homework-remote/events")
     vra = vr.all()
     self.assertEqual(vr.count(), 1)
     self.assertEqual(vra[0]['id'], res['id'])
     doc['_deleted'] = True
     db.save_doc(doc, force_update=True)
Ejemplo n.º 5
0
 def __init__(self, doc, event):
     self.doc = doc
     self.evt = event
     if len(event['docs']) == 1:
         self.current_rev = event['docs'][0]['doc_rev']
         self.action = event['docs'][0]['action']
     self.db = couchdb_config_parser.get_db()
Ejemplo n.º 6
0
    def test_undo(self):
        inc = {
            "collection": "events",
            "perform_undo": True,
            "undoable": True,
            "title": "test",
            "description": "test",
            "docs": [{
                "doc_id": "aabbcc",
                "doc_rev": "1-aabbcc",
                "doc_collection": "notifications",
                "action": "add"
            }],
            "timestamp": datetime.datetime.now(tzutc()).isoformat()
        }

        not_inc_not_perform_undo = {
            "collection": "events",
            "perform_undo": False,
            "undoable": True,
            "title": "test",
            "description": "test",
            "docs": [{
                "doc_id": "aabbcc",
                "doc_rev": "2-aabbcc",
                "doc_collection": "notifications",
                "action": "add"
            }],
            "timestamp": datetime.datetime.now(tzutc()).isoformat()
        }

        not_inc = {
            "collection": "events",
            "perform_undo": False,
            "undoable": False,
            "title": "test",
            "description": "test",
            "docs": [{
                "doc_id": "aabbcc",
                "doc_rev": "4-aabbcc",
                "doc_collection": "notifications",
                "action": "add"
            }],
            "timestamp": datetime.datetime.now(tzutc()).isoformat()
        }

        db = couchdb_config_parser.get_db()
        res = db.save_doc(inc)
        res2 = db.save_doc(not_inc_not_perform_undo)
        res3 = db.save_doc(not_inc)
        stream = ChangesStream(db, filter="homework-remote/undo")
        self.assertEqual(1, len(list(stream)))
        self.assertEqual(res['id'], list(stream)[0]['id'])
        inc['_deleted'] = True
        not_inc_not_perform_undo['_deleted'] = True
        not_inc['_deleted'] = True
        db.save_doc(inc, force_update=True)
        db.save_doc(not_inc, force_update=True)
        db.save_doc(not_inc_not_perform_undo, force_update=True)
Ejemplo n.º 7
0
 def setUpClass(cls):
     cls.db = couchdb_config_parser.get_db()
     current_events = cls.db.view('homework-remote/events')
     if current_events.count() > 0:
         current_events_all = current_events.all()
         for row in current_events_all:
             current_doc = cls.db.get(row['id'])
             current_doc['_deleted'] = True
             cls.db.save_doc(current_doc, force_update=True)
Ejemplo n.º 8
0
 def test_invalid_collection(self):
     doc = {
         "name": "Rob",
         "service": "email",
         "userdetails": "*****@*****.**",
         "collection": "notify"
     }
     db = couchdb_config_parser.get_db()
     with self.assertRaises(Exception):
         db.save_doc(doc)
Ejemplo n.º 9
0
 def test_required(self):
     doc = {
         "service": "twitter",
         "collection": "notifications",
         "user": "******",
         "status": "foo"
     }
     db = couchdb_config_parser.get_db()
     with self.assertRaises(Exception):
         db.save_doc(doc)
Ejemplo n.º 10
0
    def test_rollback_invalid_status(self):
        doc = {
            "collection": "request_revert",
            "timestamp": datetime.datetime.now(tzutc()).isoformat(),
            "status": "waiting"
        }

        db = couchdb_config_parser.get_db()
        with self.assertRaises(Exception):
            db.save_doc(doc)
Ejemplo n.º 11
0
    def test_rollback_invalid_timestamp(self):
        doc = {
            "collection": "request_revert",
            "timestamp": '2015-14-27T15:19:06.690Z',
            "status": "pending"
        }

        db = couchdb_config_parser.get_db()
        with self.assertRaises(Exception):
            db.save_doc(doc)
Ejemplo n.º 12
0
 def test_notification_invalid_email(self):
     doc = {
         "name": "Rob",
         "service": "email",
         "collection": "notifications",
         "user": "******",
         "status": "pending"
     }
     db = couchdb_config_parser.get_db()
     with self.assertRaises(Exception):
         db.save_doc(doc)
Ejemplo n.º 13
0
 def test_empty_string(self):
     doc = {
         "collection": "notification-request",
         "to": "",
         "service": "email",
         "body": "message",
         "status": "pending"
     }
     db = couchdb_config_parser.get_db()
     with self.assertRaises(Exception):
         db.save_doc(doc)
Ejemplo n.º 14
0
 def test_notification_request_status_invalid(self):
     doc = {
         "collection": "notification-request",
         "to": "Rob",
         "service": "email",
         "body": "message",
         "status": "complete"
     }
     db = couchdb_config_parser.get_db()
     with self.assertRaises(Exception):
         db.save_doc(doc)
Ejemplo n.º 15
0
    def test_valid_rollback_request(self):
        doc = {
            "collection": "request_revert",
            "timestamp": datetime.datetime.now(tzutc()).isoformat(),
            "status": "pending"
        }

        db = couchdb_config_parser.get_db()
        res = db.save_doc(doc)
        doc['_deleted'] = True
        db.save_doc(doc, force_update=True)
Ejemplo n.º 16
0
 def test_valid_notification_request(self):
     doc = {
         "collection": "request_notification",
         "to": "Rob",
         "service": "email",
         "body": "message",
         "status": "pending"
     }
     db = couchdb_config_parser.get_db()
     res = db.save_doc(doc)
     doc['_deleted'] = True
     db.save_doc(doc, force_update=True)
Ejemplo n.º 17
0
 def test_notification_valid(self):
     doc = {
         "name": "Rob",
         "service": "twitter",
         "collection": "notifications",
         "user": "******",
         "status": "pending"
     }
     db = couchdb_config_parser.get_db()
     res = db.save_doc(doc)
     doc['_deleted'] = True
     db.save_doc(doc, force_update=True)
Ejemplo n.º 18
0
 def test_long_ssid(self):
     doc = {
         "collection": "wifi",
         "status": "pending",
         "ssid": "abcdefghijklmnopqrstuvwxyz1234567890",
         "mode": "g",
         "channel": 1,
         "encryption_type": "wpa",
         "password": "******"
     }
     db = couchdb_config_parser.get_db()
     with self.assertRaises(Exception):
         db.save_doc(doc)
Ejemplo n.º 19
0
 def test_password_non_ascii_chars(self):
     doc = {
         "collection": "wifi",
         "status": "pending",
         "ssid": "spencer",
         "mode": "g",
         "channel": 1,
         "encryption_type": "wpa",
         "password": "******"
     }
     db = couchdb_config_parser.get_db()
     with self.assertRaises(Exception):
         db.save_doc(doc)
Ejemplo n.º 20
0
 def test_invalid_status(self):
     doc = {
         "collection": "wifi",
         "status": "finished",
         "ssid": "spencer",
         "mode": "g",
         "channel": 1,
         "encryption_type": "wpa",
         "password": "******"
     }
     db = couchdb_config_parser.get_db()
     with self.assertRaises(Exception):
         db.save_doc(doc)
Ejemplo n.º 21
0
 def test_unchanged(self):
     doc = {
         "name": "Rob",
         "service": "twitter",
         "collection": "notifications",
         "user": "******",
         "status": "pending"
     }
     db = couchdb_config_parser.get_db()
     db.save_doc(doc)
     doc['name'] = 'test'
     with self.assertRaises(Exception):
         db.save_doc(doc, force_update=True)
Ejemplo n.º 22
0
 def test_send_notification(self):
     the_id = ''
     res = change_notification.sendNotification("Rob", "email", "foo")
     the_id = res['id']
     db = couchdb_config_parser.get_db()
     ret_doc = db.get(the_id)
     self.assertEqual(ret_doc['_id'], the_id)
     self.assertEqual(ret_doc['collection'], 'request_notification')
     self.assertEqual(ret_doc['status'], 'pending')
     self.assertEqual(ret_doc['to'], 'Rob')
     self.assertEqual(ret_doc['service'], 'email')
     self.assertEqual(ret_doc['body'], 'foo')
     ret_doc['hidden'] = True
     db.save_doc(ret_doc, force_update=True)
Ejemplo n.º 23
0
 def test_txt_password_8_chars(self):
     doc = {
         "collection": "wifi",
         "status": "pending",
         "ssid": "spencer",
         "mode": "g",
         "channel": 1,
         "encryption_type": "wpa",
         "password": "******"
     }
     db = couchdb_config_parser.get_db()
     res = db.save_doc(doc)
     doc['_deleted'] = True
     db.save_doc(doc, force_update=True)
Ejemplo n.º 24
0
 def test_event_no_action(self):
     doc = {
         "timestamp": datetime.datetime.now(tzutc()).isoformat(),
         "collection": "events",
         "title": "testing",
         "description": "testing, testing, 1,2,3",
         "doc_id": "aabbcc",
         "doc_rev": "1-aabbcc",
         "undoable": False,
         "perform_undo": True,
         "doc_collection": "devices"
     }
     db = couchdb_config_parser.get_db()
     with self.assertRaises(Exception):
         db.save_doc(doc)
Ejemplo n.º 25
0
    def test_devices_edit(self):
        not_inc = {
            "_id": "00:11:22:33:44:55",
            "action": "permit",
            "collection": "devices",
            "device_name": "test-device",
            "host_name": "test-device",
            "ip_address": "10.2.0.61",
            "lease_action": "add",
            "mac_address": "aa:bb:cc:dd:ee:ff",
            "name": "Rob",
            "state": "pending",
            "device_type": "laptop",
            "notification_service": "email",
            "timestamp": time.time(),
            "connection_event": "disconnect",
            "changed_by": "user"
        }

        inc = {
            "_id": "00:11:22:33:44:56",
            "action": "",
            "collection": "devices",
            "device_name": "test-device2",
            "host_name": "test-device",
            "ip_address": "10.2.0.65",
            "lease_action": "add",
            "mac_address": "ab:bc:cd:de:ef:fa",
            "name": "Rob",
            "state": "permit",
            "device_type": "laptop",
            "notification_service": "twitter",
            "timestamp": time.time(),
            "connection_event": "disconnect",
            "changed_by": "user"
        }
        db = couchdb_config_parser.get_db()
        db.save_doc(inc, force_update=True)
        db.save_doc(not_inc, force_update=True)
        stream = ChangesStream(db, filter="homework-remote/edit_device")
        self.assertEqual(len(list(stream)), 1)
        self.assertEqual("00:11:22:33:44:56", list(stream)[0]['id'])
        inc['_deleted'] = True
        not_inc['_deleted'] = True
        db.save_doc(inc, force_update=True)
        db.save_doc(not_inc, force_update=True)
Ejemplo n.º 26
0
 def test_event(self):
     doc = {
         "timestamp": datetime.datetime.now(tzutc()).isoformat(),
         "collection": "events",
         "title": "testing",
         "description": "testing, testing, 1,2,3",
         "docs": [{
             "doc_id": "aabbcc",
             "doc_rev": "1-aabbcc",
             "doc_collection": "devices",
             "action": "edit"
         }],
         "undoable": True,
         "perform_undo": False
     }
     db = couchdb_config_parser.get_db()
     res = db.save_doc(doc)
     doc['_deleted'] = True
     db.save_doc(doc, force_update=True)
Ejemplo n.º 27
0
 def test_device_set_metadata_when_pending(self):
     doc = {
         "action": "",
         "device_name": "psxrjs-mbp",
         "host_name": "psxrjs-mbp",
         "ip_address": "10.2.0.1",
         "mac_address": "68:a8:6d:3b:05:e4",
         "name": "Rob",
         "state": "pending",
         "timestamp": time.time(),
         "collection": "devices",
         "lease_action": "add",
         "device_type": "laptop",
         "notification_service": "email",
         "connection_event": "connect",
         "changed_by": "user"
     }
     db = couchdb_config_parser.get_db()
     with self.assertRaises(Exception):
         db.save_doc(doc)
Ejemplo n.º 28
0
 def test_invalid_mac_address(self):
     doc = {
         "action": "",
         "device_name": "",
         "host_name": "",
         "ip_address": "",
         "mac_address": "",
         "name": "Rob",
         "state": "permit",
         "timestamp": time.time(),
         "collection": "devices",
         "lease_action": "add",
         "device_type": "",
         "notification_service": "",
         "connection_event": "disconnect",
         "changed_by": "system"
     }
     db = couchdb_config_parser.get_db()
     with self.assertRaises(Exception):
         db.save_doc(doc)
Ejemplo n.º 29
0
    def test_notification_with_service(self):
        db = couchdb_config_parser.get_db()
        doc1 = {
            "collection": "notifications",
            "name": "Rob",
            "service": "email",
            "user": "******",
            "status": "done"
        }

        doc2 = {
            "collection": "notifications",
            "name": "Rob",
            "service": "growl",
            "user": "******",
            "status": "done"
        }

        doc3 = {
            "collection": "notifications",
            "name": "Rob",
            "service": "email",
            "user": "******",
            "status": "done",
            "hidden": True
        }

        res = db.save_doc(doc1)
        res2 = db.save_doc(doc2)
        res3 = db.save_doc(doc3)
        key = ["email", "Rob"]
        vr = db.view("homework-remote/notification_with_service", key=key)
        vr_all = vr.all()
        self.assertEqual(vr.count(), 1)
        res_obj = vr_all[0]
        self.assertEqual(res_obj['value'], doc1['user'])
        self.assertEqual(res_obj['id'], res['id'])
        doc1['hidden'] = True
        doc2['hidden'] = True
        db.save_doc(doc1, force_update=True)
        db.save_doc(doc2, force_update=True)
Ejemplo n.º 30
0
 def test_valid_device(self):
     doc = {
         "action": "",
         "device_name": "psxrjs-mbp",
         "host_name": "psxrjs-mbp",
         "ip_address": "10.2.0.1",
         "mac_address": "68:a8:6d:3b:05:e4",
         "name": "Rob",
         "state": "permit",
         "timestamp": time.time(),
         "collection": "devices",
         "lease_action": "add",
         "device_type": "laptop",
         "notification_service": "email",
         "connection_event": "connect",
         "changed_by": "system"
     }
     db = couchdb_config_parser.get_db()
     res = db.save_doc(doc)
     doc['_deleted'] = True
     db.save_doc(doc, force_update=True)