示例#1
0
    def test_init_data_storage(self):
        os.system("python3 init_data.py")
        data = controller.load_serialized_data("park_data")
        correct = True
        files = os.listdir("data_storage/")

        for file in files:
            if file != "report_data":
                if controller.load_serialized_data(file) != {"id": 0}:
                    correct = False

        self.assertEqual(correct, True)
示例#2
0
    def test_check_if_visitor_paid(self):
        os.system("python3 init_data.py")
        allParks = controller.load_serialized_data("park_data")
        allVisitors = controller.load_serialized_data("visitor_data")
        allParks[10] = Park(10)
        allVisitors[10] = Visitor(5)

        controller.dump_serialized_data("park_data", allParks)
        controller.dump_serialized_data("visitor_data", allVisitors)

        self.assertTrue((controller.check_if_visitor_paid(5, 10) != True))
        os.system("python3 init_data.py")
示例#3
0
    def test_get_admission_report_generation(self):
        os.system("python3 init_data.py")
        args = self.data["2"]

        r = requests.post(args[2],
                          data=json.dumps(args[1]),
                          headers=self.headers)

        allParks = controller.load_serialized_data("park_data")
        allNotes = controller.load_serialized_data("notes_data")

        n1 = Note(0, "2018-2-20")
        n1.title = "Lots of animals"

        n2 = Note(1, "2018-2-22")
        n2.title = "Good food"
        allNotes[0] = n1
        allNotes[1] = n2
        allParks[0].note_ids.append(0)
        allParks[0].note_ids.append(1)

        controller.dump_serialized_data("park_data", allParks)
        controller.dump_serialized_data("notes_data", allNotes)

        args = self.data["12"]
        r = requests.post(args[2],
                          data=json.dumps(args[1]),
                          headers=self.headers)

        expected = {
            'end_date':
            '',
            'name':
            'Admissions report',
            'total_admissions':
            1,
            'start_date':
            '',
            'rid':
            '911',
            'detail_by_park': [{
                'name': 'Apple River Canyon',
                'pid': '0',
                'admissions': 1
            }]
        }
        self.assertEqual(
            controller.get_admissions_or_revenue_range([0, 99999999], 911),
            expected)
示例#4
0
    def test_admissions_report_initialization(self):
        allReports = controller.load_serialized_data("report_data")

        self.assertEqual(allReports["911"].getSimpleJsonObject(), {
            "rid": "911",
            "name": "Admissions report"
        })
示例#5
0
    def test_revenue_report_initialization(self):
        allReports = controller.load_serialized_data("report_data")

        self.assertEqual(allReports["917"].getSimpleJsonObject(), {
            "rid": "917",
            "name": "Revenue report"
        })
示例#6
0
 def test_data_serialization(self):
     allParks = controller.load_serialized_data("park_data")
     allParks[10] = Park(10)
     controller.dump_serialized_data("park_data", allParks)
     newParks = controller.load_serialized_data("park_data")
     print(newParks[10].toJsonObject(False))
     self.assertEqual(
         newParks[10].toJsonObject(True), {
             "payment_info": {},
             "pid": "10",
             "location_info": {
                 "geo": None,
                 "web": None,
                 "phone": None,
                 "address": None,
                 "name": None,
                 "region": None
             }
         })
示例#7
0
 def test_report_getAsJsonObject_method(self):
     allReports = controller.load_serialized_data("report_data")
     self.assertEqual(
         allReports["911"].getAsJsonObject(), {
             "total_admissions": 0,
             "name": "Admissions report",
             "detail_by_park": [],
             "end_date": "",
             "start_date": "",
             "rid": "911"
         })
示例#8
0
    def test_check_get_all_notes_function(self):
        os.system("python3 init_data.py")
        args = self.data["5"]
        r = requests.post(args[2],
                          data=json.dumps(args[1]),
                          headers=self.headers)

        allNotes = controller.load_serialized_data("notes_data")
        allParks = controller.load_serialized_data("park_data")

        note1 = Note(0, "")
        note1.title = "Nice Place"
        note2 = Note(1, "")
        note2.title = "Bad Place"

        allNotes[0] = note1
        allNotes[1] = note2

        allParks[0].note_ids.append(0)
        allParks[0].note_ids.append(1)

        controller.dump_serialized_data("notes_data", allNotes)
        controller.dump_serialized_data("park_data", allParks)

        self.assertEqual(controller.get_all_notes(), [{
            'notes': [{
                'title': 'Nice Place',
                'nid': '0',
                'date': ''
            }, {
                'title': 'Bad Place',
                'nid': '1',
                'date': ''
            }],
            'pid':
            0
        }])
示例#9
0
    def test_get_all_visitors(self):
        os.system("python3 init_data.py")
        allVisitors = controller.load_serialized_data("visitor_data")
        v1 = Visitor(0)
        v1.name = "Test Visitor1"
        v1.email = "*****@*****.**"
        v2 = Visitor(1)
        v2.name = "Test Visitor2"
        v2.email = "*****@*****.**"

        allVisitors[0] = v1
        allVisitors[1] = v2

        controller.dump_serialized_data("visitor_data", allVisitors)
        print(controller.get_all_visitors())
        expected = {}
        self.assertEqual(2 + 2, 4)
示例#10
0
    def test_get_all_data_in_bounds_method(self):
        os.system("python3 init_data.py")
        args = self.data["2"]

        r = requests.post(args[2],
                          data=json.dumps(args[1]),
                          headers=self.headers)

        allParks = controller.load_serialized_data("park_data")
        allNotes = controller.load_serialized_data("notes_data")

        n1 = Note(0, "2018-2-20")
        n1.title = "Lots of animals"

        n2 = Note(1, "2018-2-22")
        n2.title = "Good food"
        allNotes[0] = n1
        allNotes[1] = n2
        allParks[0].note_ids.append(0)
        allParks[0].note_ids.append(1)

        controller.dump_serialized_data("park_data", allParks)
        controller.dump_serialized_data("notes_data", allNotes)

        args = self.data["12"]
        r = requests.post(args[2],
                          data=json.dumps(args[1]),
                          headers=self.headers)

        expected = [{
            'parks': [{
                'location_info': {
                    'phone': '815-745-3302',
                    'web':
                    'https://www.dnr.illinois.gov/Parks/Pages/AppleRiverCanyon.aspx',
                    'address': '8763 E. Canyon Rd, Apple River, IL 61001',
                    'region': 'Northwestern Illinois',
                    'geo': {
                        'lat': 42.448,
                        'lng': -90.043
                    },
                    'name': 'Apple River Canyon'
                },
                'pid': '0'
            }]
        }, {
            'notes': [{
                'date': '2018-2-20',
                'nid': '0',
                'title': 'Lots of animals'
            }, {
                'date': '2018-2-22',
                'nid': '1',
                'title': 'Good food'
            }]
        }, {
            'orders': [{
                'oid': '0',
                'type': 'car',
                'amount': 7,
                'date': '2018-11-13',
                'pid': '0'
            }]
        }, {
            'visitors': [{
                'vid': '0',
                'name': 'John Doe',
                'email': '*****@*****.**'
            }]
        }]

        self.assertEqual(controller.get_all_data_in_bounds("", [0, 99999999]),
                         expected)