예제 #1
0
def build_info(keys: str = Header(...),
               keyvalues: str = Header(...),
               maxbuilds: str = Header(...),
               token: str = Header(...)):
    # TODO get either address or longitude or longitude of building
    # TODO return all information as well as risk assessment
    # TODO return tips to make better
    """
    Return list of buildings and their values based on the keys used.
    
    """

    endpoint = 'build-info'
    return_dict = {'success': False}
    try:
        print("Executing {} endpoint".format(endpoint))
        role = registration.Login.validate_jwt_token(token)['roles']
        keys, keyvalues = keys.split('|'), keyvalues.split('|')
        if len(keys) == 0 or len(keyvalues) == 0:
            raise Exception('No query key found')
        build_obj = Building(role, keys[1:], keyvalues[1:], maxbuilds)

        return_dict['result'] = build_obj.retrieve_from_db()
        return_dict['success'] = True
        return JSONResponse(content=return_dict)

    except CustomException as ce:
        error_code, error = str(ce).split(':')
        return print_exception(error, error_code, endpoint, return_dict)

    except Exception as e:
        return print_exception(str(e), 400, endpoint, return_dict)
class TestingOfficeAllocation(unittest.TestCase):

    def setUp(self):
        self.amity = Building()
        self.fellow = Fellow("jubril")
        self.amity.read_file("data/input.txt")

    def test_can_add_office(self):
        """
        Test if an office can be added
        """
        self.amity.add_room("Codango", 'offices')
        self.assertIn('Codango', self.amity.rooms['offices'])

    def test_can_add_livingspace(self):
        """
        Test if a living space can be added
        """
        self.amity.add_room("Troupon", 'livingspaces')
        self.assertIn('Troupon', self.amity.rooms['livingspaces'])

    def test_can_prepopulate(self):
        """
        Test if offices and living space can be prepopulated
        """
        self.amity.pre_populate()
        self.assertEquals('Kiln', self.amity.rooms['offices'][0].name)
        self.assertEquals(len(self.amity.rooms['offices']), 10)
        self.assertEquals('Carat', self.amity.rooms['livingspaces'][0].name)
        self.assertEquals(len(self.amity.rooms['livingspaces']), 10)

    def test_file_was_read(self):
        """
        Test to see if the file was read
        """
        self.assertEqual(len(self.amity.people), 35)

    def test_list_of_unallocated_people(self):
        """
        Test to see get list of unallocated people
        """
        self.assertIsNotNone(self.amity.get_a_list_of_unallocated_people())

    def test_get_allocation_details(self):
        """
        Test to get the list of office allocations
        """
        self.assertIsNone(self.amity.get_allocation_details())
        self.assertIsNone(self.amity.get_living_space_details())

    def test_get_members_for_a_particular_office(self):
        """
        Test to get the members of a particular office
        """
        self.assertIsNone(self.amity.get_members_for_a_particular_office("Kiln"))

    def test_allocate(self):
        self.amity.pre_populate()
        self.amity.allocate()
        self.assertGreater(len(self.amity.allocated_offices), 0)
        self.assertGreater(len(self.amity.allocated_rooms), 0)
        self.assertIsNone(self.amity.allocate())

    def test_add_person(self):
        self.assertIsNone(self.amity.add_person("Chitech Aji", "STAFF"))

    def test_remove_employee_from_office(self):
        self.amity.pre_populate()
        self.amity.read_file("data/input.txt")
        self.amity.allocate()
        self.assertIsNone(self.amity.remove_from_room("AHMED AKUBE"))

    def test_get_employee_roommates(self):
        self.amity.pre_populate()
        self.amity.read_file("data/input.txt")
        self.amity.allocate()
        self.assertIsNotNone(self.amity.get_person_details("AHMED AKUBE"))
 def setUp(self):
     self.amity = Building()
     self.fellow = Fellow("jubril")
     self.amity.read_file("data/input.txt")