Esempio n. 1
0
    def test_update_member_when_marked_for_deletion(self):
        # Ensure the admin is logged in
        self.client.force_login(self.admin)

        # Set the member marked to be deleted
        self.member.marked_for_deletion = True
        self.member.last_updated_by = self.admin2
        self.memberData['marked_for_deletion'] = 'on'

        Member.save(self.member)

        # Remove MemberLogs that were created during this update
        MemberLog.objects.all().delete()

        # The member's data got updated, even tho marked_for_deletion = True!
        updatedFields = {
            'first_name': 'NewFirstName',
        }
        postData = {**self.memberData, **updatedFields}

        # Issue a POST request.
        response = self.client.post('/admin/membership_file/member/' + str(self.member.id) + '/change/', data=postData, follow=True)

        # Ensure that the readonly_fields are ignored
        self.assertEqual(response.status_code, 200)

        # Ensure that the name of the member was unchanged
        self.assertEqual(Member.objects.get(id=self.member.id).first_name, self.memberData['first_name'])

        # Ensure that no memberlog got created
        self.assertEqual(MemberLog.objects.all().count(), 0)
Esempio n. 2
0
    def setUp(self):
        # Called each time before a testcase runs
        # Set up data for each test.
        # Objects are refreshed here and a client (to make HTTP-requests) is created here
        self.client = Client()

        # Create normal user and admin here
        self.admin = User.objects.create_superuser(username="******", password="******", email="")
        self.admin2 = User.objects.create_superuser(username="******", password="******", email="")

        # Create a Member
        self.memberData = {
            "first_name": "HTTPs",
            "last_name": "Committee",
            "date_of_birth": "1970-01-01",
            "email": "*****@*****.**",
            "street": "Veld",
            "house_number": "5",
            "city": "Eindhoven",
            "country": "The Netherlands",
            "member_since": "1970-01-01",
            "educational_institution": "TU/e",
        }
        self.member = Member.objects.create(**self.memberData)

        # Save the models
        User.save(self.admin)
        User.save(self.admin2)
        Member.save(self.member)
Esempio n. 3
0
    def setUp(self):
        # Create a user
        self.user = User.objects.create(username="******",
                                        password="******")

        # Test Member Data
        self.member_data = {
            "initials": "J.D.",
            "first_name": "John",
            "last_name": "Doe",
            "date_of_birth": "1970-01-01",
            "email": "*****@*****.**",
            "street": "Main Street",
            "house_number": "42",
            "city": "New York",
            "country": "U.S.A.",
            "member_since": "1970-01-01",
            "educational_institution": "University of Toronto",
            "user": self.user,
        }
        # The member to test the request methods on
        self.member_to_run_tests_on = Member.objects.create(**self.member_data)

        # Save the models
        Member.save(self.member_to_run_tests_on)
Esempio n. 4
0
    def setUp(self):
        # Called each time before a testcase runs
        # Set up data for each test.
        # Objects are refreshed here and a client (to make HTTP-requests) is created here
        self.client = Client()

        # Create normal user and admin here
        self.user = User.objects.create(username="******", password="******")
        self.user2 = User.objects.create(username="******", password="******")
        self.admin = User.objects.create_superuser(username="******", password="******", email="")

        # Create a Member
        self.memberData = {
            "initials": "F.C.",
            "first_name": "Fantasy",
            "last_name": "Court",
            "date_of_birth": "1970-01-01",
            "email": "*****@*****.**",
            "street": "Veld",
            "house_number": "5",
            "city": "Eindhoven",
            "country": "The Netherlands",
            "member_since": "1970-01-01",
            "educational_institution": "TU/e",
        }
        self.member = Member.objects.create(**self.memberData)
        self.memberData = fillDictKeys(self.emptyMemberDictionary, self.memberData)

        # Save the models
        User.save(self.user)
        User.save(self.user2)
        User.save(self.admin)
        Member.save(self.member)

        # Remove member logs related to self.member
        MemberLog.objects.all().delete()

        # Define test data
        self.email = "*****@*****.**"
        self.data = fillDictKeys(self.emptyMemberDictionary, {
            "user": "",
            "initials": "E.S.R.G.",
            "first_name": "Knights",
            "tussenvoegsel": "of the",
            "last_name": "Kitchen Table",
            "date_of_birth": "1970-01-01",
            "email": self.email,
            "street": "De Lampendriessen",
            "house_number": "31",
            "house_number_addition": "11",
            "city": "Eindhoven",
            "state": "Noord-Brabant",
            "country": "The Netherlands",
            "member_since": "1970-01-01",
            "educational_institution": "TU/e",
        })
        self.numNonEmptyFields = getNumNonEmptyFields(self.data)
Esempio n. 5
0
    def test_delete_member_allowed(self):
        # Ensure the admin is logged in
        self.client.force_login(self.admin)

        # Set the member marked to be deleted
        self.member.marked_for_deletion = True
        self.member.last_updated_by = self.admin2

        Member.save(self.member)

        # Issue a POST request.
        response = self.client.post('/admin/membership_file/member/' + str(self.member.id) + '/delete/', data={"post": "yes"}, follow=True)

        # Ensure that the request is correctly handled
        self.assertEqual(response.status_code, 200)

        # The member should be deleted
        self.assertEqual(0, Member.objects.all().count())
Esempio n. 6
0
    def test_delete_member_marked_for_deletion_by_same_user(self):
        # Ensure the admin is logged in
        self.client.force_login(self.admin)

        # Set the member marked to be deleted
        self.member.marked_for_deletion = True
        self.member.last_updated_by = self.admin

        Member.save(self.member)

        # Issue a POST request.
        response = self.client.post('/admin/membership_file/member/' + str(self.member.id) + '/delete/', data={"post": "yes"}, follow=True)

        # Ensure that a 403 Forbidden response is issued
        self.assertEqual(response.status_code, 403)

        # The member should not be deleted
        self.assertEqual(1, Member.objects.all().count())
Esempio n. 7
0
    def setUp(self):
        # Called each time before a testcase runs
        # Set up data for each test.
        # Objects are refreshed here and a client (to make HTTP-requests) is created here
        self.client = Client()

        # Create a Member
        self.memberData = {
            "first_name": "Luna",
            "last_name": "Fest",
            "date_of_birth": "1970-01-01",
            "email": "*****@*****.**",
            "street": "De Lampendriessen",
            "house_number": "31",
            "city": "Eindhoven",
            "country": "The Netherlands",
            "member_since": "1970-01-01",
            "educational_institution": "TU/e",
        }
        self.member = Member.objects.create(**self.memberData)

        # Save the models
        Member.save(self.member)