-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmotiondetect_database_test.py
More file actions
138 lines (121 loc) · 5.42 KB
/
motiondetect_database_test.py
File metadata and controls
138 lines (121 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# #!/usr/bin/python
# import os
# import sys
# import cv2 as CV2
# import sqlite3
# from sqlite3 import Connection, Cursor
# from sys import stdout
# import unittest
# from motiondetect import dataBase, MotionDetect
# from datetime import datetime, timedelta
# class DatabaseTest(unittest.TestCase):
# '''
# > to run test on this class, do:
# tests/motiondetect_database_test.py
# > python -m unittest tests/motiondetect_database_test.py
# '''
# test_video = '/home/kcdouglass/Desktop/SoftwareEngineering/open-source-security-camera/open-source-security-camera/osCam/videos/funny_monkeys.avi'
# USER_CONFIG_SETTING = {
# 'recordToDevice':0,
# 'filePath':'/home/pi/open-source-security-camera/osCam/videos/',
# 'maxSpace': 100,
# 'timeToLive':60,
# 'lengthOfRecordings': 10,
# }
# def setUp(self) -> None:
# # For Database Class
# self.TEST_DB_FILE_NAME = r"osCam.test/db.sqlite3"
# self.db_file_name = r"osCam/db.sqlite3"
# self.userconfig_name = 'userconfig_storage'
# self._db = dataBase
# self.connection = dataBase.create_connection(self.db_file_name)
# self.cursor = self.connection.cursor()
# self.motion_detect = MotionDetect()
# def tearDown(self) -> None:
# """
# Delete any Test database/ Entries on Treadown
# """
# tear_down_file_name = self.db_file_name
# if self.connection and self.cursor == self.connection:
# # if there was a valid connection we should roll-back any potential changes on tear-down
# self.connection.cursor.close()
# self.connection.close()
# if self.db_file_name is None:
# os.remove(self.TEST_DB_FILE_NAME)
# else:
# os.remove(self.db_file_name)
# else:
# print("No {} Connections to Close.".format(self.db_file_name))
# def test_smoke_test(self):
# self.assertEqual(1,1)
# def test_valid_userconfig_setting_entry_list(self):
# # Ensure the lists are the same and data had been saved
# self.db_file_name = r"osCam/db.sqlite3"
# _connection = self._db.create_connection(self.db_file_name)
# selected_items = self._db.GetSettingsFromDB(_connection)
# self.assertIsNotNone((selected_items))
# def test_has_valid_db_entry(self):
# """
# ENTRY RETURN VALUE EXAMPLE
# [1, 0, '/home/pi/open-source-security-camera/osCam/videos/', 100, 60, 10]
# """
# self.db_file_name=r"osCam/db.sqlite3"
# self.connection = dataBase.create_connection(self.db_file_name)
# self.cursor = self.connection.cursor()
# userconf_storage = self.cursor.execute('SELECT * FROM userconfig_storage').fetchall()
# original_items = [1, 0, '/home/pi/open-source-security-camera/osCam/videos/', 100, 60, 10]
# _storage = []
# for record in userconf_storage:
# for data in record:
# _storage.append(data)
# # ENSURE SAMENESS
# self.assertListEqual(
# original_items,
# _storage,
# )
# def test_create_connection(self):
# '''Sqlit3 returns instance-of *Connection* on successfull connection'''
# is_connected = dataBase.create_connection(r"osCam/db.sqlite3")
# self.assertIsInstance(is_connected, sqlite3.Connection)
# self.assertTrue(isinstance(is_connected, sqlite3.Connection))
# def test_create_invalid_connection_exeption(self):
# """Ensure that database is not created Every time by checking when invalid connection"""
# try:
# is_connected = dataBase.create_connection("file:testtemplate.db?mode=ro")
# self.assertTrue(is_connected is None)
# except sqlite3.Error:
# self.assertTrue(is_connected is None)
# self.fail()
# def test_motiondetect_smoke_test(self):
# self.assertTrue(self.motion_detect.capture)
# def handle_open_video(self, capture, frame, isReading):
# count = 0
# while(capture.isOpened() and count < 20):
# if isReading:
# CV2.imshow('FRAME', frame)
# count += 1
# else:
# break
# def test_detect_invalid(self):
# self.motion_detect = MotionDetect()
# self.motion_detect.capture = CV2.VideoCapture(self.test_video)
# capture = self.motion_detect.capture
# isDetect, frame = capture.read()
# self.handle_open_video(capture, frame, isDetect )
# self.assertEqual(isDetect, True)
# def test_rescale_frame(self):
# self.motion_detect = MotionDetect()
# self.motion_detect.capture = CV2.VideoCapture(self.test_video)
# capture = self.motion_detect.capture
# isReading, frame = capture.read()
# self.handle_open_video(capture,frame, isReading)
# self.motion_detect.actions(self.motion_detect.rescaleFrame(frame))
# self.assertTrue(isReading != None)
# def test_motiondetect_init_then_cleanup(self):
# self.motion_detect = MotionDetect()
# captured_video = CV2.VideoCapture(self.test_video)
# isReading, frame = self.motion_detect.capture.read()
# self.motion_detect.cleanUp()
# self.assertEqual(isReading, False)
# if __name__ == '__main__':
# unittest.main()