def test_not_post_membership_request_for_someone_else(self):
        self.session = self.createAuthorizedSession(control.username,
                                                    control.password)
        self.url = control.hostURL + 'api/requests/'
        self.data = {
            'ACT_CDE': control.activity_code_AJG,
            'SESS_CDE': control.session_code,
            'ID_NUM': control.valid_id_number,
            'PART_CDE': control.member_positions,
            'DATE_SENT': '07/06/2016',
            'COMMENT_TXT': control.comments
        }
        # We will get the actual id when we post.
        self.requestID = -1
        response = api.post(self.session, self.url, self.data)

        if response.status_code == 201:
            try:
                self.requestID = response.json()['REQUEST_ID']
                if self.requestID >= 0:
                    api.delete(self.session, self.url + str(self.requestID))
                    pytest.fail(
                        'Request {0} was created even though it was supposed to be unauthorized'
                        .format(self.requestID))
            except (ValueError, KeyError):
                pytest.fail('Error in test')
        elif not response.status_code == 401:
            pytest.fail('Expected 401 Unauthorized, got {0}.'\
                .format(response.status_code))
Example #2
0
    def test_is_on_whitelist(self):
        self.session = self.createAuthorizedSession(control.username,
                                                    control.password)
        self.url = control.hostURL + 'api/housing/admin'
        # add test user to whitelist
        self.data = {}
        api.post(self.session,
                 self.url + '/' + str(control.my_id_number) + '/', self.data)
        # check that user is on the whitelist
        response = api.get(self.session, self.url)
        # remove
        api.delete(self.session,
                   self.url + '/' + str(control.my_id_number) + '/')

        if not response.status_code == 200:
            pytest.fail('Expected 200 OK, got {0}.'\
                .format(response.status_code))
Example #3
0
 def test_post_reset_image(self):
     self.session = self.createAuthorizedSession(control.username, control.password)
     self.url = control.hostURL + 'api/profiles/image/reset/'
     self.data = {
         'ID': control.my_id_number,
         'FILE_PATH': control.FILE_PATH_PROFILE,
         'FILE_NAME': ""
     }
     self.requestID = -1
     response = api.post(self.session, self.url, self.data)
     if not response.status_code == 200:
         pytest.fail('Expected 200 Created, got {0}.'\
             .format(response.status_code))
Example #4
0
 def test_post_wellness_asymptomatic_student(self):
     self.session = self.createAuthorizedSession(control.username,
                                                 control.password)
     self.url = control.hostURL + 'api/wellness/'
     self.data = {
         'answerValid': True,
         'timestamp': datetime,
         'userAnswer': False
     }
     response = api.post(self.session, self.url, self.data)
     if not response.status_code == 201:
         pytest.fail('Expected 201 OK, got {0}.'\
             .format(response.status_code))
Example #5
0
 def test_post_ID_image(self):
     self.session = self.createAuthorizedSession(control.username, control.password)
     self.url = control.hostURL + 'api/profiles/IDimage/'
     self.data = {
         'file': open(control.FILE_PATH_ID, 'r')
     }
     
     response = api.postAsFormData(self.session, self.url, self.data)
     if not response.status_code == 200:
         pytest.fail('Expected 200 OK, got {0}.'\
             .format(response.status_code))
         
     d = api.post(self.session, self.url + 'reset/', self.data)
     if not d.status_code == 200:
         pytest.fail('There was a problem performing cleanup')
    def test_post_membership_request_for_someone_else(self):
        self.session = \
            self.createAuthorizedSession(control.leader_username, control.leader_password)
        self.url = control.hostURL + 'api/requests/'
        self.data = {
            'ACT_CDE': control.activity_code_AJG,
            'SESS_CDE': control.session_code,
            'ID_NUM': control.valid_id_number,
            'PART_CDE': 'MEMBR',
            'DATE_SENT': '07/06/2016',
            'COMMENT_TXT': control.comments
        }
        # We will get the actual id when we post.
        self.requestID = -1
        response = api.post(self.session, self.url, self.data)
        if response.status_code == 201:
            try:
                self.requestID = response.json()['REQUEST_ID']
            except (ValueError, KeyError):
                pytest.fail('Error in test')

        #checking if the correctness of post\
        self.session = \
            self.createAuthorizedSession(control.leader_username, control.leader_password)
        getResponse = api.get(self.session, control.hostURL + \
            'api/requests/activity/' + str(control.activity_code_AJG))
        self.requestID = response.json()['REQUEST_ID']
        req = getResponse.json()
        found = False
        for dic in req:
            reqID = dic['RequestID']
            if (reqID == self.requestID):
                found = True
                try:
                    assert dic['ActivityCode'] == control.activity_code_AJG
                    assert dic['SessionCode'] == control.session_code
                    assert dic['IDNumber'] == control.valid_id_number
                except ValueError:
                    pytest.fail('Expected Json response body, got{0}.'\
                        .format(getResponse.json()))
        if not found:
            pytest.fail('requestID not found:', self.requestID)

        #delete the test post
        d = api.delete(self.session, self.url + str(self.requestID))
        if d.status_code != 200:
            pytest.fail('Unauthorized resource not deleted.')
 def test_authenticate_with_valid_credentials___activity_leader(self):
     self.session = requests.Session()
     self.url = control.hostURL + 'token'
     self.token_payload = { 'username':control.leader_username, \
         'password':control.leader_password, 'grant_type':'password' }
     response = api.post(self.session, self.url, self.token_payload)
     if not response.status_code == 200:
         pytest.fail('Expected 200 OK, got {0}.'\
             .format(response.status_code))
     try:
         response.json()
     except ValueError:
         pytest.fail('Expected Json, got {0}.'.format(response.text))
     if not 'access_token' in response.json():
         pytest.fail('Expected access token in response, got {0}.'\
             .format(response.json()))
     assert response.json()["token_type"] == "bearer"
Example #8
0
 def test_post_guest_reset_image(self):
     self.session = self.createGuestSession()
     self.url = control.hostURL + 'api/profiles/image/reset/'
     self.data = {
         'ID': control.my_id_number,
         'FILE_PATH': control.FILE_PATH_PROFILE,
         'FILE_NAME': ""
     }
     self.requestID = -1
     response = api.post(self.session, self.url, self.data)
     if not response.status_code == 401:
         pytest.fail('Expected 401 Created, got {0}.'\
             .format(response.status_code))
     try:
         assert response.json()['Message'] == control.AUTHORIZATION_DENIED
     except ValueError:
         pytest.fail('Expected Json response body, got{0}.'\
             .format(response.text))
Example #9
0
    def test_post_wellness_asymptomatic_guest(self):
        self.session = self.createGuestSession()
        self.url = control.hostURL + 'api/wellness/'
        self.data = {
            'answerValid': True,
            'timestamp': datetime,
            'userAnswer': False
        }
        response = api.post(self.session, self.url, self.data)

        if not response.status_code == 401:
            pytest.fail('Expected 401 Unauthorized Error, got {0}.'\
                .format(response.status_code))
        try:
            assert response.json()['Message'] == control.AUTHORIZATION_DENIED
        except ValueError:
            pytest.fail('Expected Json response body, got{0}.'\
                .format(response.text))
Example #10
0
 def test_post_wellness_question_guest(self):
     self.session = self.createAuthorizedSession(control.username,
                                                 control.password)
     self.url = control.hostURL + 'api/wellness/question'
     self.data = {
         'yesPrompt': 'Trying to change',
         'question': 'No questions',
         'noPrompt': 'Have a nice day of testing'
     }
     response = api.post(self.session, self.url, self.data)
     if not response.status_code == 405:
         pytest.fail('Expected 405 Not Found, got {0}.'\
             .format(response.status_code))
     try:
         assert response.json()['Message'] == \
             "The requested resource does not support http method 'POST'."
     except ValueError:
         pytest.fail('Expected Json response body, got {0}.'\
             .format(response.text))