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_post_new_guest_membership_for_someone_else__activity_leader(self):
     self.session = \
         self.createAuthorizedSession(control.leader_username, control.leader_password)
     self.url = control.hostURL + 'api/memberships/'
     self.data = {
         'ACT_CDE': control.activity_code_AJG,
         'SESS_CDE': control.session_code,
         'ID_NUM': control.valid_id_number,
         'PART_CDE': 'GUEST',
         'BEGIN_DTE': '06/10/2016',
         'END_DTE': '07/16/2016',
         'COMMENT_TXT': control.comments
     }
     # We will get the actual id when we post.
     # Setting it -1 to check later that we got an id from the post.
     self.createdMembershipID = -1
     response = api.postAsJson(self.session, self.url, self.data)
     if response.status_code == 201:
         if not ('MEMBERSHIP_ID' in response.json()):
             pytest.fail('Expected MEMBERSHIP_ID in json response, got {0}.'\
                 .format(response.json()))
         else:
             self.createdMembershipID = response.json()['MEMBERSHIP_ID']
     else:
         pytest.fail('Expected 201 Created, got {0}.'\
             .format(response.status_code))
     try:
         response.json()
     except ValueError:
         pytest.fail('Expected Json response body, got {0}.'\
             .format(response.text))
     assert response.json()['PART_CDE'] == 'GUEST'
     api.delete(self.session, self.url + str(self.createdMembershipID))
    def test_post_valid_membership_request__as_leader(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.my_id_number,
            'PART_CDE': 'MEMBR',
            'DATE_SENT': '07/06/2016',
            'COMMENT_TXT': control.comments
        }
        # We will get the actual id when we post.
        # Setting it -1 to check later that we got an id from the post.
        self.requestID = -1

        response = api.postAsJson(self.session, self.url, self.data)
        if not response.status_code == 201:
            pytest.fail('Expected 201 Created, got {0}.'\
                .format(response.status_code))
        try:
            response.json()
        except ValueError:
            pytest.fail('Expected json response, got {0}.'\
                .format(response.text))

        #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.my_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)

        #try:
        #    self.requestID = response.json()['REQUEST_ID']
        #    if not response.json()['STATUS'] == REQUEST_STATUS_PENDING:
        #    pytest.fail('Expected Pending status , got {0}.'.format(resposne.json()))
        #    except KeyError:
        #    pytest.fail('Expected REQUEST_ID in response body, got {0}.'.format(response.json()))
        #    We try to delete the request we created
        if self.requestID >= 0:
            api.delete(self.session, self.url + str(self.requestID))
Example #4
0
    def test_post_new_membership_for_someone___activity_leader(self):
        self.session = \
            self.createAuthorizedSession(control.leader_username, control.leader_password)
        self.url = control.hostURL + 'api/memberships/'
        self.createdMembershipID = -1
        # Add a new participant
        self.data = {
            'ACT_CDE': control.activity_code_AJG,
            'SESS_CDE': control.session_code,
            'ID_NUM': control.valid_id_number,
            'PART_CDE': 'MEMBR',
            'BEGIN_DTE': '06/10/2016',
            'END_DTE': '07/16/2016',
            'COMMENT_TXT': control.comments
        }

        response = api.postAsJson(self.session, self.url, self.data)
        if not response.status_code == 201:
            pytest.fail('Expected 201 Created, got {0}.'\
                .format(response.status_code))
        try:
            response.json()
        except ValueError:
            pytest.fail('Expected Json response body, got {0}.'\
                .format(response.text))
        try:
            self.createdMembershipID = response.json()['MEMBERSHIP_ID']
        except KeyError:
            pytest.fail('Expected MEMBERSHIP ID in response, got {0}.'\
                .format(response.json()))

        #checking the correctness of post
        getResponse = api.get(self.session, control.hostURL + \
            'api/memberships/activity/' + str(control.activity_code_AJG))
        self.membershipID = response.json()['MEMBERSHIP_ID']
        req = getResponse.json()
        found = False
        for dic in req:
            reqID = dic['MembershipID']
            if (reqID == self.membershipID):
                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: {0}.'.format(response.json()))

        if self.createdMembershipID >= 0:
            api.delete(self.session, self.url + str(self.createdMembershipID))
Example #5
0
    def test_put_edited_membership_member_to_leader___activity_leader(self):
        self.session = \
            self.createAuthorizedSession(control.leader_username, control.leader_password)
        self.url = control.hostURL + 'api/memberships/'
        self.createdMembershipID = -1

        # The membership to modify
        self.predata = {
            'ACT_CDE': control.activity_code_AJG,
            'SESS_CDE': control.session_code,
            'ID_NUM': control.valid_id_number,
            'PART_CDE': 'MEMBR',  # Is a participant at first.
            'BEGIN_DTE': '06/10/2016',  # Old start date
            'END_DTE': '07/16/2016',
            'COMMENT_TXT': control.comments
        }
        r = api.postAsJson(self.session, self.url, self.predata)
        try:
            self.createdMembershipID = r.json()["MEMBERSHIP_ID"]
            # Updated Data
            self.data = {
                'MEMBERSHIP_ID': self.createdMembershipID,
                'ACT_CDE': control.activity_code_AJG,
                'SESS_CDE': control.session_code,
                'ID_NUM': control.valid_id_number,
                'PART_CDE': 'LEAD',  # Upgrade him to director.
                'BEGIN_DTE': '02/10/2016',  # New start date
                'END_DTE': '07/16/2016',
                'COMMENT_TXT': control.comments
            }
        except (KeyError, ValueError):
            pytest.fail('Error in setup.')
        response = api.putAsJson(self.session, self.url + \
            str(self.createdMembershipID), self.data)
        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 response body, got {0}.'\
                .format(response.text))
        try:
            self.createdMembershipID = response.json()['MEMBERSHIP_ID']
        except KeyError:
            pytest.fail('Expected MEMBERSHIP_ID in json response, got {0}.'\
                .format(response.json()))
        assert response.json()['PART_CDE'] == 'LEAD'
        if self.createdMembershipID >= 0:
            api.delete(self.session, self.url + str(self.createdMembershipID))
    def test_deny_someone_joining_my_activity(self):
        self.session = \
            self.createAuthorizedSession(control.leader_username, control.leader_password)
        self.url = control.hostURL + 'api/requests/'
        self.requestID = -1

        #Create a memberships request for the trash club.
        self.data = {
            'ACT_CDE': control.activity_code_AJG,
            'SESS_CDE': control.session_code,
            'ID_NUM': control.my_id_number,
            'PART_CDE': 'MEMBR',
            'DATE_SENT': '07/06/2016',
            'COMMENT_TXT': control.comments
        }
        response = api.postAsJson(self.session, self.url, self.data)
        if not response.status_code == 201:
            pytest.fail('Expected 201 Created, got {0}.'\
                .format(response.status_code))
        try:
            response.json()
        except ValueError:
            pytest.fail('Expected json response, got {0}.'\
                .format(response.text))
        else:
            try:
                self.requestID = response.json()['REQUEST_ID']
            except KeyError:
                pytest.fail('Error in setup. Expected REQUEST_ID in response' + \
                    ', got {0}.'.format(response.json()))
        response = api.postAsJson(self.session, self.url + \
            str(self.requestID) + '/deny', None)
        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 response body, got {0}.'\
                .format(response.text))
        else:
            try:
                if not response.json(
                )['STATUS'] == control.REQUEST_STATUS_DENIED:
                    pytest.fail('Expected approved request, got {0}.'\
                        .format(response.json()))
            except KeyError:
                pytest.fail('Expected STATUS in response bady, got {0}.'\
                    .format(response.json()))
        api.delete(self.session, self.url + str(self.requestID))
Example #7
0
    def test_delete_valid_membership___activity_leader(self):
        self.session = \
            self.createAuthorizedSession(control.leader_username, control.leader_password)
        self.url = control.hostURL + 'api/memberships/'
        self.createdMembershipID = -1

        # Create a Memerships that we'll eventually delete
        self.predata = {
            'ACT_CDE': control.activity_code_AJG,
            'SESS_CDE': control.session_code,
            'ID_NUM': control.valid_id_number,
            'PART_CDE': 'MEMBR',
            'BEGIN_DTE': control.begin_date,
            'END_DTE': control.end_date,
            'COMMENT_TXT': control.comments
        }
        r = api.postAsJson(self.session, self.url, self.predata)
        try:
            self.createdMembershipID = r.json()['MEMBERSHIP_ID']
        except (ValueError, KeyError):
            pytest.fail('Error doing setup')
        response = \
            api.delete(self.session, self.url + str(self.createdMembershipID))
        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 response body, got {0}.'\
                .format(response.text))
        if not ('MEMBERSHIP_ID' in response.json()):
            pytest.fail('Expected MEMBERSHIP_ID in response, got {0}.'\
                .format(response.json()))
Example #8
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 #9
0
 def test_post_new_leader_membership_for_someone___activity_leader(self):
     self.session = \
         self.createAuthorizedSession(control.leader_username, control.leader_password)
     self.url = control.hostURL + 'api/memberships/'
     self.createdMembershipID = -1
     # Add a new leader
     self.data = {
         'ACT_CDE': control.activity_code_AJG,
         'SESS_CDE': control.session_code,
         'ID_NUM': control.valid_id_number,
         'PART_CDE': 'LEAD',
         'BEGIN_DTE': control.begin_date,
         'END_DTE': control.end_date,
         'COMMENT_TXT': control.comments
     }
     response = api.postAsJson(self.session, self.url, self.data)
     if not response.status_code == 201:
         pytest.fail('Expected 201, got {0}.'.format(response.status_code))
     try:
         response.json()
     except ValueError:
         pytest.fail('Expected Json response body, got {0}.'\
             .format(response.text))
     try:
         self.createdMembershipID = response.json()['MEMBERSHIP_ID']
         if self.createdMembershipID < 0:  # The creation was not successful
             pytest.fail('Expected valid memberhsip ID, got {0}.'\
                 .format(self.createdMembershipID))
         else:
             #checking if the correctness of post
             getResponse = api.get(self.session, control.hostURL + \
                 'api/memberships/activity/' + str(control.activity_code_AJG))
             self.membershipID = response.json()['MEMBERSHIP_ID']
             req = getResponse.json()
             found = False
             for dic in req:
                 reqID = dic['MembershipID']
                 if (reqID == self.membershipID):
                     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('MembershipID not found:', self.membershipID)
             d = api.delete(self.session, self.url + \
                 str(self.createdMembershipID))
             if not d.status_code == 200:
                 pytest.fail('Error in cleanup. Expected , got {0}.'\
                     .format(d.status_code))
     except KeyError:
         pytest.fail('Expected MEMBERSHIP ID in response, got {0}.'\
             .format(response.json()))
    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.')
Example #11
0
    def test_date_submitted_changed(self):
        self.session = self.createAuthorizedSession(control.username,
                                                    control.password)
        self.url = control.hostURL + 'api/housing/apartment/applications'
        self.data = {
            'ApplicationID':
            -1,
            'EditorProfile': {
                'AD_Username': control.leader_username,
            },
            'Applicants': [
                {
                    'Profile': {
                        'AD_Username': control.leader_username,
                        'Class': 'Junior',
                    },
                },
            ],
            'ApartmentChoices': [
                {
                    'HallRank': 1,
                    'HallName': 'Tavilla'
                },
            ],
        }
        appIDResponse = api.postAsJson(self.session, self.url, self.data)

        appID = appIDResponse.content

        self.url = control.hostURL + 'api/housing/apartment/applications/' + str(
            appID) + '/submit'
        self.data = {}
        response = api.put(self.session, self.url, self.data)

        if not response.status_code == 200:
            pytest.fail('Expected 200 OK, got {0}.'\
                .format(response.status_code))

        # clean up
        self.url = control.hostURL + 'api/housing/apartment/applications/' + str(
            appID)
        response = api.delete(self.session, self.url)
    def test_myschedule_post(self):
        self.session = self.createAuthorizedSession(control.username,
                                                    control.password)
        self.url = control.hostURL + 'api/myschedule/'
        self.data = {
            'GORDON_ID': str(control.my_id_number),
            'LOCATION': control.location,
            'DESCRIPTION': control.description,
            'TUE_CDE': 'T',
            'IS_ALLDAY': 1,
        }
        response = api.postAsJson(self.session, self.url, self.data)
        if not response.status_code == 201:
            pytest.fail('Expected 201 Created, got {0}.'\
                .format(response.status_code))
        try:
            response.json()
        except ValueError:
            pytest.fail('Expected Json response body, got {0}.'\
                .format(response.text))
        assert response.json()["GORDON_ID"] == str(control.my_id_number)
        assert response.json()["LOCATION"] == control.location
        assert response.json()["DESCRIPTION"] == control.description

        # delete the test post
        # Expected Status Code -- 200 OK.
        try:
            self.GordonID = response.json()["GORDON_ID"]
            if self.GordonID == str(control.my_id_number):
                response = api.delete(self.session, self.url + \
                    str(response.json()["EVENT_ID"]))
        except KeyError:
            pytest.fail('Expected REQUEST_ID in response body, got {0}.'\
                .format(response.json()))
        if not response.status_code == 200:
            pytest.fail('Expected 200 OK, got {0}.'\
                .format(response.status_code))
    def test_delete_membership_request(self):
        self.session = \
            self.createAuthorizedSession(control.leader_username, control.leader_password)
        self.url = control.hostURL + 'api/requests/'
        self.predata = {}
        self.requestID = -1

        self.predata = {
            'ACT_CDE': control.activity_code_AJG,
            'SESS_CDE': control.session_code,
            'PART_CDE': 'MEMBR',
            'ID_NUM': control.leader_id_number,
            'DATE_SENT': '07/19/2016',
            'COMMENT_TXT': control.comments
        }
        response = api.postAsJson(self.session, self.url, self.predata)
        if not response.status_code == 201:
            pytest.fail('Error in setup. Expected 201 Created, got {0}.'\
                .format(response.status_code))
        else:
            self.requestID = response.json()['REQUEST_ID']
        response = \
            api.delete(self.session, self.url + '/' + str(self.requestID))
        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 response body, got {0}.'\
                .format(response.text))
        try:
            response.json()['REQUEST_ID']
        except KeyError:
            pytest.fail('Expected REQUEST_ID in response body, got {0}.'\
                .format(response.json()))
Example #14
0
    def test_application_deleted(self):
        self.session = self.createAuthorizedSession(control.username,
                                                    control.password)
        self.url = control.hostURL + 'api/housing/apartment/applications'
        self.data = {
            'ApplicationID':
            -1,
            'EditorProfile': {
                'AD_Username': control.leader_username,
            },
            'Applicants': [
                {
                    'Profile': {
                        'AD_Username': control.leader_username,
                        'Class': 'Junior',
                    },
                },
                {
                    'Profile': {
                        'AD_Username': control.username,
                        'Class': 'Senior',
                    },
                },
            ],
            'ApartmentChoices': [{
                'HallRank': 1,
                'HallName': 'Tavilla'
            }, {
                'HallRank': 2,
                'HallName': 'Conrad'
            }, {
                'HallRank': 3,
                'HallName': 'Hilton'
            }],
        }
        appIDResponse = api.postAsJson(self.session, self.url, self.data)

        appID = appIDResponse.content

        self.url = control.hostURL + 'api/housing/apartment/applications/' + str(
            appID)
        response = api.delete(self.session, self.url)

        if not response.status_code == 200:
            pytest.fail('Expected 200 OK, got {0}.'\
                .format(response.status_code))

        # make sure the referenced rows have been deleted too
        # (no endpoint exists to just get a list of hall choices,
        # it is not verified here that the application hall choices are deleted)

        self.url = control.hostURL + 'api/housing/apartment/' + control.leader_username
        response = api.get(self.session, self.url)

        if not response.status_code == 404:
            pytest.fail('Expected 404 Not Found, got {0}.'\
                .format(response.status_code))

        self.url = control.hostURL + 'api/housing/apartment/' + control.username
        response = api.get(self.session, self.url)

        if not response.status_code == 404:
            pytest.fail('Expected 404 Not Found, got {0}.'\
                .format(response.status_code))
    def Test_Allow_someone_to_join_my_activity___activity_leader(self):
        self.session = \
            self.createAuthorizedSession(control.leader_username, control.leader_password)
        self.url = control.hostURL + 'api/requests/'
        self.requestID = -1
        self.membershipID = -1

        #Create a memberships request for the trash club.
        self.data = {
            'ACT_CDE': control.activity_code_AJG,
            'SESS_CDE': control.session_code,
            'ID_NUM': control.my_id_number,
            'PART_CDE': 'MEMBR',
            'DATE_SENT': '07/06/2016',
            'COMMENT_TXT': control.comments
        }
        response = api.postAsJson(self.session, self.url, self.data)
        if not response.status_code == 201:
            pytest.fail('Error in setup. Expected 201 Created, got {0}.'\
                .format(response.status_code))
        try:
            response.json()
        except ValueError:
            pytest.fail('Error in setup. Expected json response, got {0}.'\
                .format(response.text))
        try:
            self.requestID = response.json()['REQUEST_ID']
        except KeyError:
            pytest.fail('Error in setup. Expected REQUEST_ID in response, ' + \
                'got {0}.'.format(response.json()))

        response = api.postAsJson(self.session, self.url + \
            str(self.requestID) + '/approve', None)
        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 response body, got {0}.'\
                .format(response.text))
        try:
            self.membershipID = response.json()['MEMBERSHIP_ID']
            if self.requestID < 0:
                pytest.fail('Error in cleanup for {0}. Expected valid ' + \
                    'request ID, got {1}.'.format(self.requestID))
            else:
                d = api.delete(self.session, self.url + str(self.requestID))
                if not d.status_code == 200:
                    pytest.fail('Error in cleanup for {0}. Expected 200 OK ' + \
                        'when deleting request, got {1}.'\
                            .format(d.status_code))
            if self.membershipID < 0:  # membership creation was not successful
                pytest.fail('Error in cleanup. Expected valid membership ID' + \
                    ', got {0}.'.format(self.membershipID))
            else:
                api.delete(self.session, control.hostURL + 'api/memberships/' + \
                    str(self.membershipID))
                if not d.status_code == 200:
                    pytest.fail('Error in cleanup. Expected 200 OK when ' + \
                        'deleting membership, got {0}.'.format(d.status_code))
        except KeyError:
            pytest.fail('Expected MEMBERSHIP_ID in response bady, got {0}.'\
                .format(response.json()))