def test_leave(self): # same as removeMember # test leave not logged in signinAs(self.client, None) leave_response = self.client.post('/api/communities.leave', urlencode({"community_id": self.COMMUNITY.id, "user_id": self.USER1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(leave_response["success"]) # test leave logged as different user signinAs(self.client, self.USER) leave_response = self.client.post('/api/communities.leave', urlencode({"community_id": self.COMMUNITY.id, "user_id": self.USER1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(leave_response["success"]) # test leave user not in team signinAs(self.client, self.USER1) leave_response = self.client.post('/api/communities.leave', urlencode({"community_id": self.COMMUNITY2.id, "user_id": self.USER1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(leave_response["success"]) # test leave logged as admin signinAs(self.client, self.SADMIN) leave_response = self.client.post('/api/communities.leave', urlencode({"community_id": self.COMMUNITY.id, "user_id": self.USER1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(leave_response["success"]) # test leave logged as same user signinAs(self.client, self.USER1) leave_response = self.client.post('/api/communities.leave', urlencode({"community_id": self.COMMUNITY.id, "user_id": self.USER1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(leave_response["success"])
def setUpClass(self): print("\n---> Testing Testimonials <---\n") self.client = Client() self.USER, self.CADMIN, self.SADMIN = createUsers() signinAs(self.client, self.SADMIN) setupCC(self.client) COMMUNITY_NAME = "test_testimonials" self.COMMUNITY = Community.objects.create( **{ 'subdomain': COMMUNITY_NAME, 'name': COMMUNITY_NAME.capitalize(), 'accepted_terms_and_conditions': True }) admin_group_name = f"{self.COMMUNITY.name}-{self.COMMUNITY.subdomain}-Admin-Group" self.COMMUNITY_ADMIN_GROUP = CommunityAdminGroup.objects.create( name=admin_group_name, community=self.COMMUNITY) self.COMMUNITY_ADMIN_GROUP.members.add(self.CADMIN) self.TESTIMONIAL1 = Testimonial.objects.create(title="testimonial1") self.TESTIMONIAL1.save()
def setUpClass(self): print("\n---> Testing Vendors <---\n") self.client = Client() self.USER, self.CADMIN, self.SADMIN = createUsers() signinAs(self.client, self.SADMIN) setupCC(self.client) COMMUNITY_NAME = "test_vendors" self.COMMUNITY = Community.objects.create( **{ 'subdomain': COMMUNITY_NAME, 'name': COMMUNITY_NAME.capitalize(), 'accepted_terms_and_conditions': True }) admin_group_name = f"{self.COMMUNITY.name}-{self.COMMUNITY.subdomain}-Admin-Group" self.COMMUNITY_ADMIN_GROUP = CommunityAdminGroup.objects.create( name=admin_group_name, community=self.COMMUNITY) self.COMMUNITY_ADMIN_GROUP.members.add(self.CADMIN) self.VENDOR1 = Vendor.objects.create(name="vendor1") self.VENDOR1.communities.set([self.COMMUNITY]) self.VENDOR2 = Vendor.objects.create(name="vendor2") self.VENDOR2.communities.set([self.COMMUNITY]) self.VENDOR1.save() self.VENDOR2.save()
def test_list(self): signinAs(self.client, self.USER1) list_response = self.client.post('/api/communities.list', urlencode({}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(list_response["success"]) self.assertIs(1, len(list_response['data'])) self.assertEqual(self.COMMUNITY.name, list_response['data'][0]['name'])
def test_events_date_update(self): # test not logged signinAs(self.client, None) response = self.client.post('/api/events.date.update', urlencode({"community_id": self.COMMUNITY.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(response["success"])
def test_rsvp_remove(self): # test not logged signinAs(self.client, None) response = self.client.post('/api/events.rsvp.remove', urlencode({"event_id": self.EVENT1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(response["success"]) # test logged as user signinAs(self.client, self.USER) response = self.client.post('/api/events.rsvp.remove', urlencode({"event_id": self.EVENT1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(response["success"])
def test_sadmin_list(self): # test not logged in signinAs(self.client, None) list_response = self.client.post( '/api/testimonials.listForSuperAdmin', urlencode({}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(list_response["success"]) # test logged in as user signinAs(self.client, self.USER) list_response = self.client.post( '/api/testimonials.listForSuperAdmin', urlencode({}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(list_response["success"]) # test logged as cadmin signinAs(self.client, self.CADMIN) list_response = self.client.post( '/api/testimonials.listForSuperAdmin', urlencode({}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(list_response["success"]) # test logged in as sadmin signinAs(self.client, self.SADMIN) list_response = self.client.post( '/api/testimonials.listForSuperAdmin', urlencode({}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(list_response["success"])
def test_list_CAdmin(self): # test list for cadmin not logged in signinAs(self.client, None) list_response = self.client.post('/api/communities.listForCommunityAdmin', urlencode({}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(list_response["success"]) # test list for cadmin logged as user signinAs(self.client, self.USER) list_response = self.client.post('/api/communities.listForCommunityAdmin', urlencode({}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(list_response["success"]) # test list for cadmin logged as cadmin signinAs(self.client, self.CADMIN) # cadmin can list for any community? list_response = self.client.post('/api/communities.listForCommunityAdmin', urlencode({}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(list_response["success"]) # test list for cadmin logged as cadmin not in community # cadmin can list for any community? list_response = self.client.post('/api/communities.listForCommunityAdmin', urlencode({}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(list_response["success"]) # test list for cadmin logged as sadmin signinAs(self.client, self.SADMIN) list_response = self.client.post('/api/communities.listForCommunityAdmin', urlencode({}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(list_response["success"])
def test_update(self): # try to update the community without being signed in signinAs(self.client, None) new_name = "QAnon followers" update_response = self.client.post('/api/communities.update', urlencode({"id": self.COMMUNITY.id, "name": new_name}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(update_response["success"]) # try to update the community signed in but not a team or community admin signinAs(self.client, self.USER) new_name = "Isolationists" update_response = self.client.post('/api/communities.update', urlencode({"id": self.COMMUNITY.id, "name": new_name}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(update_response["success"]) #update the community as a CADMIN of the correct community signinAs(self.client, self.CADMIN) new_name = "Arlingtonians" update_response = self.client.post('/api/communities.update', urlencode({"id": self.COMMUNITY.id, "name": new_name}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(update_response["success"]) self.assertEqual(new_name, update_response["data"]["name"]) #update the community as a SADMIN signinAs(self.client, self.SADMIN) new_name = "Arlington Rocks" update_response = self.client.post('/api/communities.update', urlencode({"id": self.COMMUNITY2.id, "name": new_name}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(update_response["success"]) self.assertEqual(new_name, update_response["data"]["name"])
def test_create(self): # same as add # attempt to create community if not signed in signinAs(self.client, None) name = "Cooler World" subdomain = "planetearth" create_response = self.client.post('/api/communities.create', urlencode({ "name": name, "subdomain": subdomain}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(create_response["success"]) # attempt to create team if regular user signed in signinAs(self.client, self.USER1) create_response = self.client.post('/api/communities.create', urlencode({"name": name, "subdomain": subdomain}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(create_response["success"]) # attempt to create community when signed in as a CADMIN signinAs(self.client, self.CADMIN) create_response = self.client.post('/api/communities.create', urlencode({"name": name, "subdomain": subdomain}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(create_response["success"]) # attempt to create community when signed in as a SADMIN # first without accepting terms and conditions signinAs(self.client, self.SADMIN) create_response = self.client.post('/api/communities.create', urlencode({"name": name, "subdomain": subdomain}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(create_response["success"]) # ok, accept terms and conditions # damn you still cant create a community unless you have templates of all the page settings create_response = self.client.post('/api/communities.create', urlencode({"name": name, "subdomain": subdomain, "accepted_terms_and_conditions":True}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(create_response["success"])
def test_rsvp_update(self): # test not logged signinAs(self.client, None) rsvp_response = self.client.post('/api/events.rsvp.update', urlencode({"event_id": self.EVENT1.id, "status":"RSVP"}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(rsvp_response["success"]) # test logged as user signinAs(self.client, self.USER) rsvp_response = self.client.post('/api/events.rsvp.update', urlencode({"event_id": self.EVENT1.id, "status":"RSVP"}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(rsvp_response["success"]) self.assertEqual(rsvp_response["data"]["status"], "RSVP") # test logged as user, but an invalid status #signinAs(self.client, self.USER) #rsvp_response = self.client.post('/api/events.rsvp.update', urlencode({"event_id": self.EVENT1.id, "status":"Volunteering"}), content_type="application/x-www-form-urlencoded").toDict() #self.assertFalse(rsvp_response["success"]) # test logged as cadmin signinAs(self.client, self.CADMIN) rsvp_response = self.client.post('/api/events.rsvp.update', urlencode({"event_id": self.EVENT1.id, "status": "Interested"}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(rsvp_response["success"]) self.assertEqual(rsvp_response["data"]["status"], "Interested") # test logged as sadmin signinAs(self.client, self.SADMIN) response = self.client.post('/api/events.rsvp.update', urlencode({"event_id": self.EVENT1.id, "status": "Not Going"}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(response["success"])
def test_list_SAdmin(self): # test list for sadmin not logged in signinAs(self.client, None) list_response = self.client.post( '/api/teams.listForSuperAdmin', urlencode({"community_id": self.COMMUNITY.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(list_response["success"]) # test list for sadmin logged as user signinAs(self.client, self.USER) list_response = self.client.post( '/api/teams.listForSuperAdmin', urlencode({"community_id": self.COMMUNITY.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(list_response["success"]) # test list for sadmin logged as cadmin signinAs(self.client, self.CADMIN) list_response = self.client.post( '/api/teams.listForSuperAdmin', urlencode({"community_id": self.COMMUNITY.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(list_response["success"]) # test list for sadmin logged as sadmin signinAs(self.client, self.SADMIN) list_response = self.client.post( '/api/teams.listForSuperAdmin', urlencode({"community_id": self.COMMUNITY.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(list_response["success"])
def test_info(self): # test info not logged in signinAs(self.client, None) info_response = self.client.post( '/api/actions.info', urlencode({"id": self.ACTION1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(info_response["success"]) # test info logged as user signinAs(self.client, self.USER) info_response = self.client.post( '/api/actions.info', urlencode({"id": self.ACTION1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(info_response["success"]) # test info logged as cadmin signinAs(self.client, self.CADMIN) info_response = self.client.post( '/api/actions.info', urlencode({"id": self.ACTION1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(info_response["success"]) # test info logged as sadmin signinAs(self.client, self.SADMIN) info_response = self.client.post( '/api/actions.info', urlencode({"id": self.ACTION1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(info_response["success"])
def test_copy(self): # test copy not logged in signinAs(self.client, None) copy_response = self.client.post( '/api/actions.copy', urlencode({"action_id": self.ACTION2.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(copy_response["success"]) # test copy as user signinAs(self.client, self.USER) copy_response = self.client.post( '/api/actions.copy', urlencode({"action_id": self.ACTION2.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(copy_response["success"]) # test copy as cadmin signinAs(self.client, self.CADMIN) copy_response = self.client.post( '/api/actions.copy', urlencode({"action_id": self.ACTION2.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(copy_response["success"]) # test copy as sadmin signinAs(self.client, self.SADMIN) copy_response = self.client.post( '/api/actions.copy', urlencode({"action_id": self.ACTION2.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(copy_response["success"])
def test_info(self): # test not logged signinAs(self.client, None) response = self.client.post('/api/events.info', urlencode({"event_id": self.EVENT1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(response["success"]) self.assertEqual(response["data"]["name"], self.EVENT1.name) # test logged as user signinAs(self.client, self.USER) response = self.client.post('/api/events.info', urlencode({"event_id": self.EVENT1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(response["success"]) self.assertEqual(response["data"]["name"], self.EVENT1.name) # test logged as cadmin signinAs(self.client, self.CADMIN) response = self.client.post('/api/events.info', urlencode({"event_id": self.EVENT1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(response["success"]) self.assertEqual(response["data"]["name"], self.EVENT1.name) # test logged as sadmin signinAs(self.client, self.SADMIN) response = self.client.post('/api/events.info', urlencode({"event_id": self.EVENT1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(response["success"]) self.assertEqual(response["data"]["name"], self.EVENT1.name) # test no event id given response = self.client.post('/api/events.info', urlencode({}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(response["success"])
def test_list(self): print("test_list") signinAs(self.client, self.USER1) list_response = self.client.post( '/api/teams.list', urlencode({ "community_id": self.COMMUNITY.id, "user_id": self.USER1.id }), content_type="application/x-www-form-urlencoded").toDict() # only one team approved self.assertTrue(list_response["success"]) self.assertIs(1, len(list_response['data'])) self.assertEqual(self.TEAM1.name, list_response['data'][0]['name'])
def setUpClass(self): print("\n---> Testing Carbon Equivalencies <---\n") self.client = Client() self.USER, self.CADMIN, self.SADMIN = createUsers() signinAs(self.client, self.SADMIN) setupCC(self.client) equivalency = {"name": "trees", "value": "41"} self.CARBON_EQUIVALENCY = CarbonEquivalency.objects.create( **equivalency) self.CARBON_EQUIVALENCY.save()
def setUpClass(self): print("\n---> Testing Events <---\n") self.client = Client() self.USER, self.CADMIN, self.SADMIN = createUsers() signinAs(self.client, self.SADMIN) setupCC(self.client) COMMUNITY_NAME = "test_events" self.COMMUNITY = Community.objects.create(**{ 'subdomain': COMMUNITY_NAME, 'name': COMMUNITY_NAME.capitalize(), 'accepted_terms_and_conditions': True }) admin_group_name = f"{self.COMMUNITY.name}-{self.COMMUNITY.subdomain}-Admin-Group" self.COMMUNITY_ADMIN_GROUP = CommunityAdminGroup.objects.create(name=admin_group_name, community=self.COMMUNITY) self.COMMUNITY_ADMIN_GROUP.members.add(self.CADMIN) self.startTime = datetime.now() self.endTime = datetime.now() self.EVENT1 = Event.objects.create(community=self.COMMUNITY, name="event1", start_date_and_time=self.startTime, end_date_and_time=self.endTime, is_published=True) self.EVENT2 = Event.objects.create(community=self.COMMUNITY, name="event2", start_date_and_time=self.startTime, end_date_and_time=self.endTime, is_published=True) self.EVENT3 = Event.objects.create(community=self.COMMUNITY, name="event3", start_date_and_time=self.startTime, end_date_and_time=self.endTime, is_published=True) self.EVENT4 = Event.objects.create(community=self.COMMUNITY, name="event4", start_date_and_time=self.startTime, end_date_and_time=self.endTime, is_published=True) self.EVENT1.save() self.EVENT2.save() self.EVENT3.save() self.EVENT4.save() # a recurring event, to test the date updating self.EVENT5 = Event.objects.create(community=self.COMMUNITY, name="event5", start_date_and_time=self.startTime, end_date_and_time=self.endTime, is_published=True) self.EVENT5.is_recurring = True self.EVENT5.recurring_details = { "recurring_type": "week", "separation_count": 1, "day_of_week": "Sunday", #"week_of_month": week_of_month, #"final_date": str(final_date) } self.EVENT5.save() self.RSVP = EventAttendee.objects.create(user=self.USER, event=self.EVENT1, status="GOING").save()
def test_message_admin(self): # implement validator # test message admin not logged in signinAs(self.client, None) message_response = self.client.post( '/api/teams.messageAdmin', urlencode({ "user_name": self.USER.full_name, "team_id": self.TEAM5.id, "title": "test message", "email": self.USER.email, "message": "test message" }), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(message_response["success"]) # test message admin logged as user signinAs(self.client, self.USER) message_response = self.client.post( '/api/teams.messageAdmin', urlencode({ "user_name": self.USER.full_name, "team_id": self.TEAM5.id, "title": "test message", "email": self.USER.email, "message": "test message" }), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(message_response["success"]) # test message admin logged as user on team signinAs(self.client, self.USER5) message_response = self.client.post( '/api/teams.messageAdmin', urlencode({ "user_name": self.USER.full_name, "team_id": self.TEAM5.id, "title": "test message", "email": self.USER.email, "message": "test message" }), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(message_response["success"]) # test message admin bad args signinAs(self.client, self.USER5) message_response = self.client.post( '/api/teams.messageAdmin', urlencode({ "these": self.USER.full_name, "args": self.TEAM5.id, "make": "test message", "no": self.USER.email, "sense!": "test message" }), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(message_response["success"])
def test_create(self): # same as add # attempt to create team if not signed in signinAs(self.client, None) name = "Foo Bar" create_response = self.client.post( '/api/teams.create', urlencode({ "name": name, "primary_community_id": self.COMMUNITY.id, "communities": str(self.COMMUNITY.id), "admin_emails": self.USER1.email }), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(create_response["success"]) # attempt to create team if regular user signed in signinAs(self.client, self.USER1) create_response = self.client.post( '/api/teams.create', urlencode({ "name": name, "primary_community_id": self.COMMUNITY.id, "communities": str(self.COMMUNITY.id), "admin_emails": self.USER1.email }), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(create_response["success"]) # attempt to create team spanning 2 communities name = "Foo Bar1" communities = str(self.COMMUNITY.id) + ',' + str(self.COMMUNITY2.id) create_response = self.client.post( '/api/teams.create', urlencode({ "name": name, "community_id": self.COMMUNITY.id, "communities": communities, "admin_emails": self.USER1.email }), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(create_response["success"]) self.assertEqual(name, create_response['data']['name'])
def test_create(self): # test not logged in signinAs(self.client, None) create_response = self.client.post('/api/users.create', urlencode({"accepts_terms_and_conditions": True, "email": "*****@*****.**", "full_name": "test name", "preferred_name": "test_name", "is_vendor": False, "community_id": self.COMMUNITY.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(create_response["success"]) # test not logged in, specify color pref signinAs(self.client, None) color = "10fo80" create_response = self.client.post('/api/users.create', urlencode({"accepts_terms_and_conditions": True, "email": "*****@*****.**", "full_name": "test name", "preferred_name": "test_name", "is_vendor": False, "community_id": self.COMMUNITY.id, "color": color}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(create_response["success"]) self.assertEqual(create_response["data"]["preferences"]["color"], color) # test creating user with a profile picture create_response = self.client.post('/api/users.create', urlencode({"accepts_terms_and_conditions": True, "email": "*****@*****.**", "full_name": "test name", "preferred_name": "test_name", "is_vendor": False, "community_id": self.COMMUNITY.id, "profile_picture": self.PROFILE_PICTURE}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(create_response["success"]) pic = create_response["data"].get("profile_picture", None) self.assertNotEqual(pic, None) # test logged as user signinAs(self.client, self.USER) create_response = self.client.post('/api/users.create', urlencode({"accepts_terms_and_conditions": True, "email": "*****@*****.**", "full_name": "test name1", "preferred_name": "test_name1", "is_vendor": False, "community_id": self.COMMUNITY.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(create_response["success"]) # test logged as admin signinAs(self.client, self.SADMIN) create_response = self.client.post('/api/users.create', urlencode({"accepts_terms_and_conditions": True, "email": "*****@*****.**", "full_name": "test name2", "preferred_name": "test_name2", "is_vendor": False, "community_id": self.COMMUNITY.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(create_response["success"])
def test_get(self): # test not logged signinAs(self.client, None) response = self.client.get( '/api/data.carbonEquivalency.get', urlencode({}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(response["success"]) self.assertGreater(len(response["data"]), 0) # test logged as user signinAs(self.client, self.USER) response = self.client.get( '/api/data.carbonEquivalency.get', urlencode({}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(response["success"]) self.assertGreater(len(response["data"]), 0) # test logged as cadmin signinAs(self.client, self.CADMIN) response = self.client.get( '/api/data.carbonEquivalency.get', urlencode({}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(response["success"]) self.assertGreater(len(response["data"]), 0) # test logged as sadmin signinAs(self.client, self.SADMIN) response = self.client.get( '/api/data.carbonEquivalency.get', urlencode({}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(response["success"]) self.assertGreater(len(response["data"]), 0) # test get one signinAs(self.client, self.USER) response = self.client.post( '/api/data.carbonEquivalency.get', urlencode({"id": self.CARBON_EQUIVALENCY.id}), content_type="application/x-www-form-urlencoded") response = response.toDict() self.assertTrue(response["success"])
def setUpClass(self): print("\n---> Testing User Profiles <---\n") self.client = Client() self.USER, self.CADMIN, self.SADMIN = createUsers() signinAs(self.client, self.SADMIN) setupCC(self.client) COMMUNITY_NAME = "test_users" self.COMMUNITY = Community.objects.create(**{ 'subdomain': COMMUNITY_NAME, 'name': COMMUNITY_NAME.capitalize(), 'accepted_terms_and_conditions': True }) admin_group_name = f"{self.COMMUNITY.name}-{self.COMMUNITY.subdomain}-Admin-Group" self.COMMUNITY_ADMIN_GROUP = CommunityAdminGroup.objects.create(name=admin_group_name, community=self.COMMUNITY) self.COMMUNITY_ADMIN_GROUP.members.add(self.CADMIN) self.REAL_ESTATE_UNIT = RealEstateUnit.objects.create() self.REAL_ESTATE_UNIT.save() self.USER2 = UserProfile.objects.create(email="*****@*****.**", full_name="user2test2", preferred_name="user2test2") self.ACTION = Action.objects.create() self.ACTION2 = Action.objects.create() self.ACTION3 = Action.objects.create() self.ACTION4 = Action.objects.create() response = self.client.post('/api/users.actions.completed.add', urlencode({"user_id": self.USER2.id, "action_id": self.ACTION.id, "household_id": self.REAL_ESTATE_UNIT.id}), content_type="application/x-www-form-urlencoded").toDict() self.client.post('/api/users.actions.completed.add', urlencode({"user_id": self.USER2.id, "action_id": self.ACTION2.id, "household_id": self.REAL_ESTATE_UNIT.id}), content_type="application/x-www-form-urlencoded") self.client.post('/api/users.actions.completed.add', urlencode({"user_id": self.USER2.id, "action_id": self.ACTION3.id, "household_id": self.REAL_ESTATE_UNIT.id}), content_type="application/x-www-form-urlencoded") self.ACTION.save() self.ACTION2.save() self.ACTION3.save() self.ACTION4.save() self.USER_ACTION_REL = UserActionRel.objects.filter(user=self.USER2, action=self.ACTION).first() self.USER_ACTION_REL2 = UserActionRel.objects.filter(user=self.USER2, action=self.ACTION2).first() self.USER_ACTION_REL3 = UserActionRel.objects.filter(user=self.USER2, action=self.ACTION3).first() self.PROFILE_PICTURE = createImage("https://www.whitehouse.gov/wp-content/uploads/2021/04/P20210303AS-1901-cropped.jpg")
def test_create(self): # test not logged signinAs(self.client, None) response = self.client.post('/api/events.create', urlencode({"community_id": self.COMMUNITY.id, "name": "test_none", "start_date_and_time": self.startTime, "end_date_and_time": self.endTime}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(response["success"]) # test logged as user signinAs(self.client, self.USER) response = self.client.post('/api/events.create', urlencode({"community_id": self.COMMUNITY.id, "name": "test_user", "start_date_and_time": self.startTime, "end_date_and_time": self.endTime}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(response["success"]) # test logged as cadmin signinAs(self.client, self.CADMIN) response = self.client.post('/api/events.create', urlencode({"community_id": self.COMMUNITY.id, "name": "test_cadmin", "start_date_and_time": self.startTime, "end_date_and_time": self.endTime}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(response["success"]) self.assertEqual(response["data"]["name"], "test_cadmin") # test logged as sadmin signinAs(self.client, self.SADMIN) response = self.client.post('/api/events.create', urlencode({"community_id": self.COMMUNITY.id, "name": "test_sadmin", "start_date_and_time": self.startTime, "end_date_and_time": self.endTime}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(response["success"]) self.assertEqual(response["data"]["name"], "test_sadmin") # test bad args signinAs(self.client, self.SADMIN) response = self.client.post('/api/events.create', urlencode({"community_id": self.COMMUNITY.id, "name": "test_bad_args"}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(response["success"])
def test_info(self): # first test for no user signed in signinAs(self.client, None) # successfully retrieve information about a community, even if not signed in info_response = self.client.post('/api/communities.info', urlencode({"community_id": self.COMMUNITY.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(info_response["success"]) self.assertEqual(self.COMMUNITY.name, info_response['data']['name']) signinAs(self.client, self.USER) # don't retrieve information about a community which is not published info_response = self.client.post('/api/communities.info', urlencode({"community_id": self.COMMUNITY2.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(info_response["success"]) # test for Community Admin signinAs(self.client, self.CADMIN) # don't retrieve information about an unpublished community if you;'re a cadmin # Need to be in sandbox info_response = self.client.post('/api/communities.info', urlencode({"community_id": self.COMMUNITY2.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(info_response["success"]) # if no ID passed, return error info_response = self.client.post('/api/communities.info', urlencode({}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(info_response["success"])
def test_create(self): # test not logged in signinAs(self.client, None) create_response = self.client.post( '/api/testimonials.create', urlencode({"title": "none_logged"}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(create_response["success"]) # test logged in as user signinAs(self.client, self.USER) create_response = self.client.post( '/api/testimonials.create', urlencode({"title": "user_logged"}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(create_response["success"]) self.assertEqual(create_response["data"]["title"], "user_logged") # test logged in as admin signinAs(self.client, self.SADMIN) create_response = self.client.post( '/api/testimonials.create', urlencode({"title": "admin_logged"}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(create_response["success"]) self.assertEqual(create_response["data"]["title"], "admin_logged")
def test_info(self): # test not logged in signinAs(self.client, None) info_response = self.client.post( '/api/testimonials.info', urlencode({"testimonial_id": self.TESTIMONIAL1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(info_response["success"]) self.assertEqual(info_response["data"]["title"], self.TESTIMONIAL1.title) # test logged in as user signinAs(self.client, self.USER) info_response = self.client.post( '/api/testimonials.info', urlencode({"testimonial_id": self.TESTIMONIAL1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(info_response["success"]) self.assertEqual(info_response["data"]["title"], self.TESTIMONIAL1.title) # test logged in as admin signinAs(self.client, self.SADMIN) info_response = self.client.post( '/api/testimonials.info', urlencode({"testimonial_id": self.TESTIMONIAL1.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(info_response["success"]) self.assertEqual(info_response["data"]["title"], self.TESTIMONIAL1.title)
def test_rank(self): # test not logged in signinAs(self.client, None) rank_response = self.client.post( '/api/testimonials.rank', urlencode({ "testimonial_id": self.TESTIMONIAL1.id, "rank": 1 }), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(rank_response["success"]) # test logged in as user signinAs(self.client, self.USER) rank_response = self.client.post( '/api/testimonials.rank', urlencode({ "testimonial_id": self.TESTIMONIAL1.id, "rank": 1 }), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(rank_response["success"]) # test logged in as admin signinAs(self.client, self.SADMIN) rank_response = self.client.post( '/api/testimonials.rank', urlencode({ "testimonial_id": self.TESTIMONIAL1.id, "rank": 1 }), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(rank_response["success"])
def test_delete(self): # create testimonials in method because they will be deleted testimonial = Testimonial.objects.create(title="testimonial_to_delete") testimonial.save() # test not logged in signinAs(self.client, None) delete_response = self.client.post( '/api/testimonials.delete', urlencode({"testimonial_id": testimonial.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(delete_response["success"]) # test logged in as user signinAs(self.client, self.USER) delete_response = self.client.post( '/api/testimonials.delete', urlencode({"testimonial_id": testimonial.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(delete_response["success"]) # test logged in as admin signinAs(self.client, self.SADMIN) delete_response = self.client.post( '/api/testimonials.delete', urlencode({"testimonial_id": testimonial.id}), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(delete_response["success"])
def test_update(self): # test not logged in signinAs(self.client, None) update_response = self.client.post( '/api/testimonials.update', urlencode({ "testimonial_id": self.TESTIMONIAL1.id, "is_approved": True }), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(update_response["success"]) # test logged in as user signinAs(self.client, self.USER) update_response = self.client.post( '/api/testimonials.update', urlencode({ "testimonial_id": self.TESTIMONIAL1.id, "is_approved": True }), content_type="application/x-www-form-urlencoded").toDict() self.assertFalse(update_response["success"]) # test logged in as admin signinAs(self.client, self.SADMIN) update_response = self.client.post( '/api/testimonials.update', urlencode({ "testimonial_id": self.TESTIMONIAL1.id, "is_approved": True }), content_type="application/x-www-form-urlencoded").toDict() self.assertTrue(update_response["success"]) self.assertTrue(update_response["data"]["is_approved"])