예제 #1
0
    def test_delete_user_by_id(self):
        with self.app.app_context():
            # delete user
            self.assertTrue(user_q.delete(self.TEST_USER))

            # verify query result
            self.assertFalse(user_q.get_one(self.TEST_USER))

            # reset db
            database.init()
예제 #2
0
    def setUpClass(cls):
        cls.db_file_handle, cls.db_path = tempfile.mkstemp()

        cls.app = achiever.create_app({
            'TESTING': True,
            'DATABASE': cls.db_path,
        })

        with cls.app.app_context():
            database.init()
예제 #3
0
    def setUp(self):
        # create tempory database tile
        self.db_file_handle, self.db_path = tempfile.mkstemp()

        self.app = achiever.create_app({
            'TESTING': True,
            'DATABASE': self.db_path,
        })

        # populate database with testing info
        with self.app.app_context():
            database.init()
예제 #4
0
    def setUpClass(cls):
        cls.db_file_handle, cls.db_path = tempfile.mkstemp()

        cls.app = achiever.create_app({
            'TESTING': True,
            'DATABASE': cls.db_path,
            'PRESERVE_CONTEXT_ON_EXCEPTION': False,
        })

        with cls.app.app_context():
            # populate the database
            database.init()
예제 #5
0
    def setUpClass(cls):
        # create app, temporary file
        cls.db_file_handle, cls.db_path = tempfile.mkstemp()

        cls.app = achiever.create_app({
            'TESTING': True,
            'DATABASE': cls.db_path,
        })

        # populate database
        with cls.app.app_context():
            database.init()
            user = user_q.get_by_username("test_user")

        # test user id
        cls.TEST_USER = user["user_id"]
예제 #6
0
    def setUp(self):

        # prepare testing variables
        self.NEW_STAFF_DATA = {
            "first_name": "Ted",
            "last_name": "George",
            "cert": "RBT",
            "tier": 1,
            "color": 3,
            "supervisor": 1,
            "attendance": {
                "mon": 1,
                "tue": 1,
                "wed": 1,
                "thu": 1,
                "fri": 0,
            },
            "clients": ["AS", "LS"],
            "hours": {
                "mon": "08:00-18:00",
                "tue": "08:00-18:00",
                "wed": "08:00-18:00",
                "thu": "08:00-18:00",
                "fri": "08:00-18:00",
            },
        }
        self.TEST_STAFF_ID = 1
        self.TEST_SUPERVISOR_ID = 1
        self.CLIENT1_INITIALS = "AS"
        self.CLIENT1_ID = 2
        self.CLIENT2_INITIALS = "LS"
        self.CLIENT2_ID = 1

        # create app and database
        self.db_file_handle, self.db_path = tempfile.mkstemp()

        self.app = achiever.create_app({
            'TESTING': True,
            'DATABASE': self.db_path,
        })

        with self.app.app_context():
            # populate database
            database.init()
예제 #7
0
    def test_update_user(self):
        with self.app.app_context():
            # updated data
            user_info = {
                "username": "******",
                "first_name": "TEST_FIRST_NAME",
                "last_name": "TEST_LAST_NAME",
                "email": "*****@*****.**",
                "user_id": self.TEST_USER
            }
            # update user
            self.assertTrue(user_q.update(user_info))

            # test query results
            user = user_q.get_one(self.TEST_USER)
            self.assertEqual(user["username"], user_info["username"])
            self.assertEqual(user["first_name"], user_info["first_name"])
            self.assertEqual(user["last_name"], user_info["last_name"])
            self.assertEqual(user["email"], user_info["email"])

            # reset db
            database.init()
예제 #8
0
    def setUpClass(cls):
        cls.db_file_handle, cls.db_path = tempfile.mkstemp()

        cls.app = achiever.create_app({
            'TESTING': True,
            'DATABASE': cls.db_path,
        })

        with cls.app.app_context():
            # populate database
            database.init()

            # insert second client
            db = database.connect()
            db.execute(
                "INSERT INTO clients "
                "(initials, total_hours, supervisor, color, mon, tue, wed, thu, fri) "
                "VALUES ('DV', '15', '1', '2', '1', '1', '1', '0', '1')"
            )

            db.commit()
            database.close()
예제 #9
0
 def tearDown(self):
     with self.app.app_context():
         database.init()
예제 #10
0
    def test_edit_staff(self):

        with self.client:
            # ensure login is required
            response = self.client.get("/staff/edit/1", follow_redirects=True)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(request.path, "/auth/login")

            # login
            response = self.login("test_user", "test_password")
            self.assertEqual(response.status_code, 200)
            self.assertEqual(request.path, "/")
            self.assertIn(b"What is Achieve?", response.data)
            """ Test GET requests """
            response = self.client.get("/staff/edit/1")
            self.assertEqual(response.status_code, 200)
            self.assertEqual(request.path, "/staff/edit/1")
            self.assertIn(b"Edit Staff", response.data)
            self.assertIn(b"Mark", response.data)
            self.assertIn(b"Hammel", response.data)
            self.assertIn(b"LS", response.data)
            self.assertIn(b"Becky", response.data)
            self.assertIn(b"08:30", response.data)
            self.assertIn(b"17:30", response.data)

            response = self.client.get("/staff/edit/100",
                                       follow_redirects=True)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(request.path, "/staff/")
            self.assertIn(b"Staff member not found.", response.data)
            self.assertIn(b"All Staff", response.data)

            response = self.client.get("/staff/edit/string")
            self.assertEqual(response.status_code, 404)

            response = self.client.get("/staff/edit/!#@")
            self.assertEqual(response.status_code, 404)

            response = self.client.get("/staff/edit/")
            self.assertEqual(response.status_code, 404)
            """ Test DELETE requests """
            self.assertTrue(staff_q.get_team_id(1, 1))
            json_data = {"staff_cli_team_id": 1}
            response = self.client.delete("/staff/edit/1", json=json_data)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(b'{"status": 0}', response.data)
            self.assertIsNone(staff_q.get_team_id(1, 1))

            database.init()

            json_data = {"staff_cli_team_id": ""}
            response = self.client.delete("/staff/edit/1", json=json_data)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(b'{"status": 1}', response.data)
            self.assertTrue(staff_q.get_team_id(1, 1))

            json_data = {}
            response = self.client.delete("/staff/edit/1", json=json_data)
            self.assertEqual(response.status_code, 200)
            self.assertEqual(b'{"status": 1}', response.data)
            self.assertTrue(staff_q.get_team_id(1, 1))

            ### Test POST Requests ###
            """ Test successful  POST """

            # verify original data
            current_staff = staff_q.get_details(1)
            self.assertEqual(current_staff["first_name"], "Mark")
            self.assertEqual(current_staff["last_name"], "Hammel")
            self.assertEqual(current_staff["fri"], 1)

            # update data
            response = self.client.post("/staff/edit/1",
                                        data=self.NEW_STAFF_DATA)
            self.assertEqual(response.status_code, 200)
            self.assertIn(b"All Staff Information Updated.", response.data)

            # verify database has been updated
            current_staff = staff_q.get_details(1)
            self.assertEqual(current_staff["first_name"], "Ted")
            self.assertEqual(current_staff["last_name"], "George")
            self.assertEqual(current_staff["fri"], 0)
            self.assertEqual(current_staff["friday"], "08:00-18:00")

            clients = staff_q.get_clients(1)
            self.assertEqual(clients[0]["initials"], "LS")
            self.assertEqual(clients[1]["initials"], "AS")

            supervisor = superv_q.get_details(current_staff["supervisor"])
            self.assertEqual(supervisor["first_name"], "Katie")

            # verify data is rendered on page
            self.assertIn(b"Ted", response.data)
            self.assertIn(b"George", response.data)
            self.assertIn(b"BT", response.data)
            self.assertIn(b"Katie Frank", response.data)
            self.assertIn(b"Red", response.data)
            self.assertIn(b"LS", response.data)
            self.assertIn(b"AS", response.data)
            self.assertIn(b"08:00", response.data)
            self.assertIn(b"18:00", response.data)

            # reset db
            database.init()
            """ Test failed POST """

            # verify original data
            current_staff = staff_q.get_details(1)
            self.assertEqual(current_staff["first_name"], "Mark")
            self.assertEqual(current_staff["last_name"], "Hammel")
            self.assertEqual(current_staff["fri"], 1)
            self.assertEqual(current_staff["friday"], "08:30-17:30")
            self.assertEqual(current_staff["supervisor"], 1)

            # POST invalid data
            response = self.client.post("/staff/edit/1",
                                        data=self.INVALID_STAFF_DATA)
            self.assertEqual(response.status_code, 200)

            # verify database contains no change
            current_staff = staff_q.get_details(1)
            self.assertEqual(current_staff["first_name"], "Mark")
            self.assertEqual(current_staff["last_name"], "Hammel")
            self.assertEqual(current_staff["fri"], 1)
            self.assertEqual(current_staff["friday"], "08:30-17:30")
            self.assertEqual(current_staff["supervisor"], 1)

            clients = staff_q.get_clients(1)
            self.assertEqual(clients[0]["initials"], "LS")
            self.assertEqual(len(clients), 1)

            # verify page renders correctly
            self.assertNotIn(b"All Staff Information Updated.", response.data)
            self.assertIn(b"First and last name are required", response.data)
            self.assertIn(b"Full name must be less then 64 characters",
                          response.data)
            self.assertIn(b"Invalid RBT certification data.", response.data)
            self.assertIn(b"Invalid Tier data.", response.data)
            self.assertIn(b"Invalid category data.", response.data)
            self.assertIn(b"Supervisor with id: 100 not found.", response.data)
            self.assertIn(b"Invalid attendance data.", response.data)
            self.assertIn(b"Invalid time format: (08:00-) for: mon",
                          response.data)
            self.assertIn(b"Start time cannot be later then end time for: tue",
                          response.data)
            self.assertIn(b"Invalid time format: (-18:00) for: wed",
                          response.data)
            self.assertIn(b"Invalid time format: (08:00-24:00) for: fri",
                          response.data)
            self.assertIn(
                b"Staff must be absent on thu since their hours are empty",
                response.data)
예제 #11
0
    def test_update_staff(self):
        with self.app.app_context():
            # NOTE: assumes validation occured previously

            # confirm current staff info (sanity check)
            staff = staff_q.get_details(self.TEST_STAFF_ID)
            self.assertEqual(staff["first_name"], "Mark")

            # change staff data
            staff = self.NEW_STAFF_DATA
            del staff["clients"]
            staff["supervisor"] = 2
            staff["cert"] = "BT"
            staff["attendance"]["mon"] = 0

            # update database info
            self.assertEqual(staff_q.update(staff, self.TEST_STAFF_ID), [])
            staff = staff_q.get_details(self.TEST_STAFF_ID)

            self.assertEqual(staff["first_name"], "Ted")
            self.assertEqual(staff["last_name"], "George")
            self.assertEqual(staff["certification"], "BT")
            self.assertEqual(staff["tier"], 1)
            self.assertEqual(staff["color"], 3)
            self.assertEqual(staff["supervisor"], 2)
            self.assertEqual(staff["mon"], 0)
            self.assertEqual(staff["tue"], 1)
            self.assertEqual(staff["wed"], 1)
            self.assertEqual(staff["thu"], 1)
            self.assertEqual(staff["fri"], 0)
            self.assertEqual(staff["monday"], "08:00-18:00")
            self.assertEqual(staff["tuesday"], "08:00-18:00")
            self.assertEqual(staff["wednesday"], "08:00-18:00")
            self.assertEqual(staff["thursday"], "08:00-18:00")
            self.assertEqual(staff["friday"], "08:00-18:00")

            # reset changes
            database.init()

            # test sql error
            staff = self.NEW_STAFF_DATA
            staff["first_name"] = None
            result = staff_q.update(staff, self.TEST_STAFF_ID)
            staff = staff_q.get_details(self.TEST_STAFF_ID)

            # confirm lack of database changes
            self.assertEqual(result, ["Staff Information update failed."])
            self.assertEqual(staff["first_name"], "Mark")
            self.assertEqual(staff["last_name"], "Hammel")
            self.assertEqual(staff["certification"], "RBT")
            self.assertEqual(staff["tier"], 2)
            self.assertEqual(staff["color"], 2)
            self.assertEqual(staff["supervisor"], 1)
            self.assertEqual(staff["mon"], 1)
            self.assertEqual(staff["tue"], 0)
            self.assertEqual(staff["wed"], 1)
            self.assertEqual(staff["thu"], 1)
            self.assertEqual(staff["fri"], 1)
            self.assertEqual(staff["monday"], "08:30-17:30")
            self.assertEqual(staff["tuesday"], "08:30-17:30")
            self.assertEqual(staff["wednesday"], "08:30-17:30")
            self.assertEqual(staff["thursday"], "08:30-17:30")
            self.assertEqual(staff["friday"], "08:30-17:30")