ctsit / redcap_deployment

Scripted REDCap deployment tools at UF CTSI
BSD 3-Clause "New" or "Revised" License
5 stars 13 forks source link

Unit tests fail when checking `api/` folder #65

Open marlycormar opened 5 years ago

marlycormar commented 5 years ago
ERROR: testApiFolder (__main__.UnauthenticatedAccessTestCase)
Verify that we can access the REDCap api/ folder
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/test.py", line 78, in testApiFolder
    self.assertIn(expected_string, self.weburl.get(self.fullpath))
  File "tests/test.py", line 17, in get
    response = urlopen(URL)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 501: Not Implemented
ChemiKyle commented 3 years ago

Issue is rooted here: https://github.com/ctsit/redcap_deployment/blob/602cb1d26efd8a22c0ae0c841d11e3f5ddcf813f/tests/test.py#L75-L80

If the 501 error is the desired result, replace self.assertIn(expected_string, self.weburl.get(self.fullpath)) with the following:

        with self.assertRaises(urllib.error.HTTPError) as cm:
            self.weburl.get(self.fullpath)
        # self.assertEqual(cm.exception, "HTTP Error 501: 'Not Implemented'")
        # Causes below error
        # AssertionError: <HTTPError 501: 'Not Implemented'> != "HTTP Error 501: 'Not Implemented'"

Given the importance of the API for ETLs, I may make a PR to add an API request test.