def test_create_group(self): header = self.headers["test1"] endpoint1, endpoint2 = self.generate_group_endpoints(header) body1 = { "name": "New group", "description": "New netflix group with friends" } body2 = {"name": "", "description": ""} response, data = Helpers.post_request(endpoint1, header=header, body=body1) response2, data2 = Helpers.post_request(endpoint2, header=header, body=body1) response3, data3 = Helpers.post_request(endpoint1, header=header, body=body2) self.assertEqual(response.status_code, 200) self.assertIsInstance(data, dict) self.assertEqual(response2.status_code, 404) self.assertIsNone(data2) self.assertEqual(response3.status_code, 400) self.assertEqual(data3["name"], ['Shorter than minimum length 1.'])
def test_add_content(self): header = self.headers["test3"] profile_ids, non_profile_ids = self.get_profile_ids(header) group_search = GroupMembers.query.filter_by(profile_id=profile_ids[0]) group_ids = [] for group in group_search: group_ids.append(group.groups.group_id) non_group_ids = [i for i in range(1, 11) if i not in group_ids] group_content_ids = [] group_content_search = Group.query.get(group_ids[0]) for content in group_content_search.content: group_content_ids.append(content.content_id) non_group_content_ids = [ i for i in range(1, 31) if i not in group_content_ids ] endpoint1 = f"/groups/{group_ids[0]}/content?profile_id={profile_ids[0]}" # noqa: E501 endpoint2 = f"/groups/{non_group_ids[0]}/content?profile_id={profile_ids[0]}" # noqa: E501 body1 = {"content_id": f"{non_group_content_ids[0]}"} body2 = {"content_id": f"{random.choice(group_content_ids)}"} body3 = {"content_id": "31"} response, data = Helpers.post_request(endpoint1, header=header, body=body1) data_content = [] for content in data["groups"]["content"]: data_content.append(content["content_id"]) response2, data2 = Helpers.post_request(endpoint2, header=header, body=body1) response3, data3 = Helpers.post_request(endpoint1, header=header, body=body2) response4, data4 = Helpers.post_request(endpoint1, header=header, body=body3) self.assertEqual(response.status_code, 200) self.assertTrue(non_group_content_ids[0] in data_content) self.assertEqual(response2.status_code, 401) self.assertIsNone(data2) self.assertEqual(response3.status_code, 401) self.assertIsNone(data3) self.assertEqual(response4.status_code, 404) self.assertIsNone(data4)
def test_admin_login(self): endpoint = "admin/login" body1 = {"username": "******", "password": "******"} body2 = {"username": "******", "password": "******"} response, data = Helpers.post_request(endpoint, body=body1) response2, data2 = Helpers.post_request(endpoint, body=body2) self.assertEqual(response.status_code, 200) self.assertIn("token", data) self.assertIsInstance(data["token"], str) self.assertEqual(response2.status_code, 401) self.assertIsNone(data2)
def test_users_register(self): endpoint = "/users/register" body = { "email": "*****@*****.**", "password": "******", "subscription_status": "1"} response, data = Helpers.post_request(endpoint, body=body) response2, data2 = Helpers.post_request(endpoint, body=body) self.assertEqual(response.status_code, 200) self.assertEqual(data["user_id"], 6) self.assertEqual(data["email"], "*****@*****.**") self.assertEqual(data["subscription_status"], True) self.assertEqual(response2.status_code, 401) self.assertIsNone(data2)
def test_create_content(self): endpoint = "/admin/content" header = self.headers["Admin1"] body1 = {"title": "Movie 1", "genre": "Action", "year": "2019"} body2 = {"title": "", "genre": "", "year": ""} response, data = Helpers.post_request(endpoint, header=header, body=body1) response2, data2 = Helpers.post_request(endpoint, header=header, body=body2) self.assertEqual(response.status_code, 200) self.assertEqual(data["content_id"], 31) self.assertEqual(response2.status_code, 400)
def test_create_profile(self): endpoint = "/profiles/create" body = {"name": "New profile", "restrictions": "M"} body2 = {"name": "New profile", "restrictions": "A"} response, data = Helpers.post_request(endpoint, body=body, header=self.headers["test3"]) response2, data2 = Helpers.post_request(endpoint, body=body2, header=self.headers["test4"]) self.assertEqual(response.status_code, 200) self.assertEqual(response2.status_code, 400) self.assertIsInstance(data, dict) self.assertEqual(data["profile_id"], 11) self.assertEqual(data["name"], "New profile") self.assertEqual(data["restrictions"], "M")
def test_users_login(self): endpoint = "/users/login" body = { "email": "*****@*****.**", "password": "******" } body2 = { "email": "*****@*****.**", "password": "******" } response, data = Helpers.post_request(endpoint, body=body) response2, data2 = Helpers.post_request(endpoint, body=body2) self.assertEqual(response.status_code, 200) self.assertIn("token", data) self.assertIsInstance(data["token"], str) self.assertEqual(response2.status_code, 401) self.assertIsNone(data2)
def test_join_group(self): header = self.headers["test5"] profile_id_search = self.get_profile_ids(header) selected_profile_id = random.choice(profile_id_search[0]) selected_non_profile_id = random.choice(profile_id_search[1]) group_endpoint = f"/groups/?profile_id={selected_profile_id}" groups = [] group_search = Helpers.get_request(group_endpoint, header=header) for group in group_search[1]: groups.append(group["groups"]["group_id"]) non_groups = [i for i in range(1, 11) if i not in groups] body1 = {"profile_id": f"{selected_profile_id}"} body2 = {"profile_id": f"{selected_non_profile_id}"} endpoint1 = f"/groups/{non_groups[0]}/join" endpoint2 = f"/groups/{groups[0]}/join" response, data = Helpers.post_request(endpoint1, header=header, body=body1) response2, data2 = Helpers.post_request(endpoint2, header=header, body=body1) response3, data3 = Helpers.post_request(endpoint1, header=header, body=body2) self.assertEqual(response.status_code, 200) self.assertEqual(data["profile_id"], selected_profile_id) self.assertIsInstance(data, dict) self.assertEqual(response2.status_code, 401) self.assertIsNone(data2) self.assertEqual(response3.status_code, 404) self.assertIsNone(data3)