def test_get_solution_ids(self): query = 'MATCH (n:Solution) OPTIONAL MATCH (n)-[r]-() DELETE n, r' db.cypher_query(query) pleb = Pleb(email=str(uuid1()), first_name="test", last_name="test", username=str(uuid1())).save() pleb2 = Pleb(email=str(uuid1()), first_name="test", last_name="test", username=str(uuid1())).save() solution = Solution(content=uuid1(), owner_username=self.pleb.username).save() solution2 = Solution(content=uuid1(), owner_username=pleb.username).save() solution3 = Solution(content=uuid1(), owner_username=pleb2.username).save() self.question.solutions.connect(solution) self.question.solutions.connect(solution2) self.question.solutions.connect(solution3) solutions = self.question.get_solution_ids() self.assertEqual(len(solutions), 3) self.assertIn(solution.object_uuid, solutions) self.assertIn(solution2.object_uuid, solutions) self.assertIn(solution3.object_uuid, solutions)
def test_three_solutions_different_authors(self): pleb = Pleb(email=str(uuid1()), first_name="test", last_name="test", username=str(uuid1())).save() pleb2 = Pleb(email=str(uuid1()), first_name="test", last_name="test", username=str(uuid1())).save() solution = Solution(content=uuid1(), owner_username=self.pleb.username).save() solution2 = Solution(content=uuid1(), owner_username=pleb.username).save() solution3 = Solution(content=uuid1(), owner_username=pleb2.username).save() self.question.solutions.connect(solution) self.question.solutions.connect(solution2) self.question.solutions.connect(solution3) authors = self.question.get_conversation_authors() self.assertIn(self.pleb.first_name, authors) self.assertIn(self.pleb.last_name, authors) self.assertIn(pleb.first_name, authors) self.assertIn(pleb.last_name, authors) self.assertIn(pleb2.first_name, authors) self.assertIn(pleb2.last_name, authors) self.assertEqual(authors.count(','), 2)
def test_is_following_was_following(self): test_pleb = Pleb(username=str(uuid1())).save() rel = self.pleb.following.connect(test_pleb) rel.active = False rel.save() res = test_pleb.is_following(self.pleb.username) self.assertFalse(res)
def setUp(self): settings.CELERY_ALWAYS_EAGER = True self.email = "*****@*****.**" res = create_user_util_test(self.email, task=True) self.assertNotEqual(res, False) wait_util(res) self.pleb = Pleb.nodes.get(email=self.email) self.user = User.objects.get(email=self.email) try: pleb = Pleb.nodes.get( email='*****@*****.**', username="******") pleb.delete() user = User.objects.get( email='*****@*****.**', username="******") user.delete() except (Pleb.DoesNotExist, User.DoesNotExist): pass self.fake_user = User.objects.create_user( first_name='test', last_name='test', email='*****@*****.**', password='******', username='******') self.fake_user.save() self.fake_pleb = Pleb(email=self.fake_user.email, username=self.fake_user.username).save()
def test_post_with_comments_from_friend(self): test_user = Pleb(email=str(uuid1()) + '@gmail.com', username=str(uuid1())[:32]) test_user.save() test_post = Post(content='test', object_uuid=str(uuid1()), owner_username=self.pleb.username, wall_owner_username=self.pleb.username) test_post.save() wall = self.pleb.wall.all()[0] test_post.posted_on_wall.connect(wall) wall.posts.connect(test_post) test_post.owned_by.connect(self.pleb) my_comment = Comment(content='test comment', object_uuid=str(uuid1()), owner_username=self.pleb.username) my_comment.save() my_comment.owned_by.connect(test_user) test_post.comments.connect(my_comment) request = self.factory.get('/%s' % self.pleb.username) request.user = self.user profile_page = ProfileView.as_view() response = profile_page(request, self.pleb.username) self.assertIn(response.status_code, [status.HTTP_200_OK, status.HTTP_302_FOUND]) test_user.delete() test_post.delete() my_comment.delete()
def test_multiple_posts_multiple_comments_friends(self): wall = self.pleb.get_wall() pleb_array = [] post_array = [] comment_array = [] for item in range(0, 2): test_pleb = Pleb(email=str(uuid1())[:32], username=str(uuid1())[:32]) test_pleb.save() pleb_array.append(test_pleb) for number in range(0, 10): test_post = Post(content='test', object_uuid=str(uuid1()), owner_username=self.pleb.username, wall_owner_username=self.pleb.username) test_post.save() test_post.posted_on_wall.connect(wall) wall.posts.connect(test_post) test_post.owned_by.connect(test_pleb) post_array.append(test_post) for num in range(0, 1): my_comment = Comment(content='test comment', object_uuid=str(uuid1()), owner_username=self.pleb.username) my_comment.save() my_comment.owned_by.connect(test_pleb) test_post.comments.connect(my_comment) comment_array.append(my_comment) my_comment = Comment(content='test comment', object_uuid=str(uuid1()), owner_username=self.pleb.username) my_comment.save() my_comment.owned_by.connect(self.pleb) test_post.comments.connect(my_comment) comment_array.append(my_comment) test_post = Post(content='test', object_uuid=str(uuid1()), owner_username=self.pleb.username, wall_owner_username=self.pleb.username) test_post.save() test_post.posted_on_wall.connect(wall) wall.posts.connect(test_post) test_post.owned_by.connect(self.pleb) request = self.factory.get('/%s' % self.pleb.username) request.user = self.user profile_page = ProfileView.as_view() response = profile_page(request, self.pleb.username) self.assertIn(response.status_code, [status.HTTP_200_OK, status.HTTP_302_FOUND]) for item in pleb_array: item.delete() for post in post_array: post.delete() for comment in comment_array: comment.delete() test_post.delete()
def setUp(self): query = "MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r" db.cypher_query(query) try: self.pleb2 = Pleb.nodes.get( username=settings.INTERCOM_USER_ID_DEVON) except (Pleb.DoesNotExist, DoesNotExist): self.pleb2 = Pleb(username=settings.INTERCOM_USER_ID_DEVON).save() self.unit_under_test_name = 'accounting' self.email = "*****@*****.**" self.pleb = create_user_util_test(self.email) self.user = User.objects.get(email=self.email) self.url = "http://testserver" self.quest = Quest(about='Test Bio', owner_username=self.pleb.username).save() self.quest.editors.connect(self.pleb) self.quest.moderators.connect(self.pleb) cache.clear() self.stripe = stripe self.stripe.api_key = settings.STRIPE_SECRET_KEY stripe.api_version = settings.STRIPE_API_VERSION self.intercom_url = "https://api.intercom.io/admins"
def test_follow(self): test_pleb = Pleb(username=str(uuid1())).save() res = test_pleb.follow(self.pleb.username) self.assertTrue(res) self.assertTrue(test_pleb.is_following(self.pleb.username))
def test_is_following_not_following(self): test_pleb = Pleb(username=str(uuid1())).save() res = test_pleb.is_following(self.pleb.username) self.assertFalse(res)
def test_unfollow(self): test_pleb = Pleb(username=str(uuid1())).save() res = test_pleb.unfollow(self.pleb.username) self.assertFalse(res)
def create_user_util_test(email, first_name="test", last_name="test", password="******", birthday=None, task=False): from plebs.serializers import generate_username """ For test purposes only :param task: :return: :param first_name: :param last_name: :param email: :param password: :param birthday: :return: """ if birthday is None: birthday = datetime.now(pytz.utc) - timedelta(days=18 * 365) try: user = User.objects.get(email=email) username = user.username except User.DoesNotExist: username = generate_username(first_name, last_name) user = User.objects.create_user(first_name=first_name, last_name=last_name, email=email, password=password, username=username) user.save() try: pleb = Pleb.get(username=user.username, cache_buster=True) except (Pleb.DoesNotExist, DoesNotExist): try: pleb = Pleb(email=user.email, first_name=user.first_name, last_name=user.last_name, username=user.username, date_of_birth=birthday) pleb.save() except (CypherException, IOError): return False except (CypherException, IOError): raise False if task: res = spawn_task(task_func=create_wall_task, task_param={"username": user.username}) spawn_task(task_func=generate_oauth_info, task_param={ 'username': user.username, 'password': password }, countdown=20) if isinstance(res, Exception) is True: return res else: return { "task_id": res, "username": username, "user": user, "pleb": pleb } return pleb