def test_requestEventsIcal(self):
     nm = NetworkManager()
     server = UniAppServer(('localhost', 0), TestableHandler, nm)
     server.updateNewsFeed()
     res = self._test(MockRequest(b'/events/iCal?id=901'), server)
     self.assertTrue('text/calendar' in str(res))
     self.assertTrue('BEGIN:VCALENDAR' in str(res))
    def setUp(self) -> None:
        self.maxDiff = None
        self.nm = NetworkManager()
        self.parser = NewsAndEventsParser(self.nm)

        # read files containing news and eventsfeed
        with open(join(TEST_DIRECTORY, NEWSFEED_FILE), 'r') as f:
            self.newsfeed = f.read()

        with open(join(TEST_DIRECTORY, EVENTSFEED_FILE), 'r') as f:
            self.eventsfeed = f.read()

        with open(join(TEST_DIRECTORY, EXAMPLE_NEWSFEED_FILE), 'r') as f:
            self.exampleNewsfeed = f.read()

        with open(join(TEST_DIRECTORY, EXAMPLE_EVENTSFEED_FILE), 'r') as f:
            self.exampleEventfeed = f.read()

        with open(join(TEST_DIRECTORY, EMPTY_NEWSFEED_FILE), 'r') as f:
            self.emptyNewsfeed = f.read()

        with open(join(TEST_DIRECTORY, EMPTY_EVENTSFEED_FILE), 'r') as f:
            self.emptyEventfeed = f.read()

        with open(join(TEST_DIRECTORY, CATEGORY_NEWSFEED_FILE), 'r') as f:
            self.categoryNewsfeed = f.read()

        # setup constants for comparison
        with open(join(TEST_DIRECTORY, NEWS_CONTENT_FILE), 'r') as f:
            self.NEWS_ITEM_0_CONTENT = f.read()

        with open(join(TEST_DIRECTORY, EVENT_CONTENT_FILE), 'r') as f:
            self.EVENT_ITEM_1_CONTENT = f.read()
 def test_requestMensaFilters(self):
     nm = NetworkManager()
     server = UniAppServer(('localhost', 0), TestableHandler, nm)
     server.updateMensa()
     res = self._test(MockRequest(b'/mensa/filters?language=de'), server)
     self.assertTrue('application/json' in str(res))
     self.assertTrue('locations' in str(res))
     self.assertTrue('notices' in str(res))
 def test_requestMensaDetails(self):
     nm = NetworkManager()
     server = UniAppServer(('localhost', 0), TestableHandler, nm)
     server.updateMensa()
     res = self._test(MockRequest(b'/mensa/mealDetail?meal=0&language=de'),
                      server)
     self.assertTrue('application/json' in str(res))
     self.assertTrue('Hackst' in str(res))
 def test_requestMensaSB(self):
     nm = NetworkManager()
     server = UniAppServer(('localhost', 0), TestableHandler, nm)
     server.updateMensa()
     res = self._test(
         MockRequest(b'/mensa/mainScreen?location=sb&language=de'), server)
     self.assertTrue('application/json' in str(res))
     self.assertTrue('Komplettmen' in str(res))
 def test_requestMap(self):
     nm = NetworkManager()
     server = UniAppServer(('localhost', 0), TestableHandler, nm)
     server.updateMap()
     res = self._test(MockRequest(b'/map?lastUpdated=2019-01-20'), server)
     self.assertTrue('application/json' in str(res))
     self.assertTrue('campus' in str(res))
     self.assertTrue('latitude' in str(res))
 def test_requestDirectoryPersonDetails(self):
     nm = NetworkManager()
     server = UniAppServer(('localhost', 0), TestableHandler, nm)
     res = self._test(
         MockRequest(b'/directory/personDetails?pid=-1&language=de'),
         server)
     self.assertTrue('application/json' in str(res))
     self.assertTrue('firstname' in str(res))
     self.assertTrue('gender' in str(res))
 def test_requestDirectorySearch(self):
     nm = NetworkManager()
     server = UniAppServer(('localhost', 0), TestableHandler, nm)
     res = self._test(
         MockRequest(b'/directory/search?page=0&pageSize=10&query=zeller'),
         server)
     self.assertTrue('application/json' in str(res))
     self.assertTrue('name' in str(res))
     self.assertTrue('Zeller' in str(res))
 def test_requestMensaInfo(self):
     nm = NetworkManager()
     server = UniAppServer(('localhost', 0), TestableHandler, nm)
     server.updateMensa()
     res = self._test(MockRequest(b'/mensa/info?location=sb&language=de'),
                      server)
     self.assertTrue('application/json' in str(res))
     self.assertTrue('name' in str(res))
     self.assertTrue('description' in str(res))
 def test_requestDirectoryHelpfulNumbers(self):
     nm = NetworkManager()
     server = UniAppServer(('localhost', 0), TestableHandler, nm)
     server.updateHelpfulNumbers()
     res = self._test(MockRequest(b'/directory/helpfulNumbers?language=de'),
                      server)
     self.assertTrue('application/json' in str(res))
     self.assertTrue('numbersLastChanged' in str(res))
     self.assertTrue('numbers' in str(res))
 def test_requestMore(self):
     nm = NetworkManager()
     server = UniAppServer(('localhost', 0), TestableHandler, nm)
     server.updateMap()
     res = self._test(
         MockRequest(b'/more?lastUpdated=2019-01-20&language=de'), server)
     self.assertTrue('application/json' in str(res))
     self.assertTrue('linksLastChanged' in str(res))
     self.assertTrue('language' in str(res))
     self.assertTrue('name' in str(res))
 def test_requestNewsMainScreen(self):
     nm = NetworkManager()
     server = UniAppServer(('localhost', 0), TestableHandler, nm)
     server.updateNewsFeed()
     res = self._test(
         MockRequest(
             b'/news/mainScreen?page=0&pageSize=10&filter=1,2,3&negFilter=4'
         ), server)
     self.assertTrue('application/json' in str(res))
     self.assertTrue('itemCount' in str(res))
     self.assertTrue('items' in str(res))
 def test_requestEventsMainScreen(self):
     nm = NetworkManager()
     server = UniAppServer(('localhost', 0), TestableHandler, nm)
     server.updateNewsFeed()
     res = self._test(
         MockRequest(
             b'/events/mainScreen?year=2020&month=03&filter=0,1,2,3,4,5,6,7,8,13&negFilter=20'
         ), server)
     self.assertTrue('application/json' in str(res))
     self.assertTrue('items' in str(res))
     self.assertTrue('Semestertermine' in str(res))
     self.assertTrue('Veranstaltungen' in str(res))
示例#14
0
 def setUp(self) -> None:
     networkManager = NetworkManager()
     self.server = UniAppServer(('localhost', 3000), RequestHandler,
                                networkManager)
     self.maxDiff = None
 def test_requestEventsDetails(self):
     nm = NetworkManager()
     server = UniAppServer(('localhost', 0), TestableHandler, nm)
     server.updateNewsFeed()
     res = self._test(MockRequest(b'/events/details?id=901'), server)
     self.assertTrue('text/html' in str(res))
 def test_requestNewsCategories(self):
     nm = NetworkManager()
     server = UniAppServer(('localhost', 0), TestableHandler, nm)
     server.updateNewsFeed()
     res = self._test(MockRequest(b'/news/categories'), server)
     self.assertTrue('application/json' in str(res))
 def test_webviewError(self):
     nm = NetworkManager()
     server = UniAppServer(('localhost', 0), TestableHandler, nm)
     server.updateNewsFeed()
     res = self._test(MockRequest(b'/news/details?id=40000'), server)
     self.assertTrue('text/html' in str(res))
 def test_error400(self):
     nm = NetworkManager()
     server = UniAppServer(('localhost', 0), TestableHandler, nm)
     res = self._test(MockRequest(b'/this/is/not/allowed'), server)
     self.assertTrue('This request is invalid.' in str(res))
示例#19
0
class TestThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        time.sleep(10)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='UniSaarApp Server. '
                                                 'See the README on the Github for more information.')
    parser.add_argument('-v', '--verbose', action="store_true", help='Prints update messages.')
    args = parser.parse_args()

    nm = NetworkManager()
    server = UniAppServer((SERVER_ADDRESS, SERVER_PORT), RequestHandler, nm)
    mensaUpdateThread = UpdateMensaThread(server, args.verbose)
    newsFeedUpdateThread = UpdateNewsFeedThread(server, args.verbose)
    mapUpdateThread = UpdateMapThread(server, args.verbose)
    helpfulNumbersUpdateThread = UpdateHelpfulNumbersThread(server, args.verbose)
    mensaUpdateThread.start()
    newsFeedUpdateThread.start()
    mapUpdateThread.start()
    helpfulNumbersUpdateThread.start()
    serverThread = ServerThread(server)
    serverThread.start()
    while True:
        if mensaUpdateThread.is_alive() is not True:
            mensaUpdateThread = UpdateMensaThread(server, args.verbose)
            mensaUpdateThread.start()