Browse Source

Fixing/updating insert/read test scripts

Charles Reid 1 year ago
parent
commit
3430903e93
3 changed files with 25 additions and 40 deletions
  1. 10
    26
      test/test_mongo_insert.py
  2. 15
    0
      test/test_mongo_read.py
  3. 0
    14
      test/test_mongo_retrieve.py

+ 10
- 26
test/test_mongo_insert.py View File

@@ -1,35 +1,19 @@
1 1
 from pymongo import MongoClient
2 2
 import random
3
+from datetime import datetime
3 4
 
4
-client = MongoClient('localhost', 27017)
5
+client = MongoClient('10.6.0.1', 27017)
5 6
 db = client.test_database
6 7
 collection = db.test_collection
7 8
 
8
-docs = [{ 
9
-            'timestamp' : '2017-04-11 11:04:12',
10
-            'bssid' : 'DEADBEEFSFUOESIEWR', 
11
-            'channel' : random.randint(0,100), 
12
-            'ssid' : 'wiiiiiifi', 
13
-            'strength' : -24, 
14
-            'encryption' : 'WPA' 
15
-        },
16
-        {
17
-            'timestamp' : '2017-04-11 11:01:12',
18
-            'bssid' : 'BEEOIEUDSJFLKSDJFF', 
19
-            'channel' : random.randint(0,100), 
20
-            'ssid' : 'iurtiruyiuyrwe',
21
-            'strength' : -20, 
22
-            'encryption' : 'WPA' 
23
-        },
24
-        {
25
-            'timestamp' : '2017-04-11 11:24:12',
26
-            'bssid' : 'BEEF2DJFSKJFLKJSFKJL', 
27
-            'channel' : random.randint(0,100), 
28
-            'ssid' : 'sdfjaskfjlkdfjglfdghfketa', 
29
-            'strength' : -30, 
30
-            'encryption' : 'WPA' 
31
-        }]
9
+docs = []
10
+for i in range(20):
11
+    d = {
12
+            'timestamp' : datetime.now(),
13
+            'channel' : random.randint(1000,8000)
14
+        }
15
+    docs.append(d)
32 16
 
33 17
 result = collection.insert_many(docs)
34
-print result.inserted_ids
18
+print(result.inserted_ids)
35 19
 

+ 15
- 0
test/test_mongo_read.py View File

@@ -0,0 +1,15 @@
1
+from pymongo import MongoClient
2
+
3
+"""
4
+Test Read
5
+
6
+Tests the ability to read records from the database.
7
+"""
8
+
9
+client = MongoClient('10.6.0.1', 27017)
10
+db = client.test_database
11
+collection = db.test_collection
12
+
13
+for doc in collection.find():
14
+    print(doc)
15
+

+ 0
- 14
test/test_mongo_retrieve.py View File

@@ -1,14 +0,0 @@
1
-from pymongo import MongoClient
2
-import random
3
-
4
-client = MongoClient('localhost', 27017)
5
-db = client.test_database
6
-collection = db.test_collection
7
-
8
-# Note: 
9
-# The space in front of the askterisk is important. 
10
-# (Got it working through trial and error: W* worked, *A didn't, so * as leading character led to problems.)
11
-for doc in collection.find({'encryption':{'$regex':' *'}}):
12
-    print "Channel: %d \tNetwork bssid: %s"%( doc['channel'], doc['bssid'] )
13
-
14
-