<commit_before>import main
import unittest
import copy
import json
from pymongo import MongoClient

def areDicsEqual(dic1, dic2):
	if len(dic1) != len(dic2):
		print(dic1)
		print(dic2)
		return False
	for k in dic1:
		if k not in dic2:
			print(dic1)
			print(dic2)
			return False

		# Incase one was an ObjectID and the other was a string representation of the object id, cast both to string for evaluation
		if str(dic1[k]) != str(dic2[k]):
			print(dic1)
			print(dic2)
			return False
	return True

class NYCSLTestCase(unittest.TestCase):
	def setUp(self):
		main.db = MongoClient().test
		self.db = main.db
		self.app = main.app.test_client()

	def tearDown(self):
		MongoClient().drop_database("test")

DUMMY_USER = {"email": "<EMAIL>", "name": "<NAME>", "school": "Horace Mann", "password": "<PASSWORD>"}

class UserTestCase(NYCSLTestCase):
	def testGetAll(self):
		assert b'[]' in self.app.get("/users").data

		exampleUser = copy.deepcopy(DUMMY_USER)
		self.db.user.insert_one(exampleUser)
		newUser = json.loads(self.app.get("/users").data.decode("utf-8"))[0]
		assert areDicsEqual(exampleUser, newUser)
	def testGet(self):
		assert self.app.get("/users/1").status_code == 404

		exampleUser = copy.deepcopy(DUMMY_USER)
		self.db.user.insert_one(exampleUser)
		newUser = json.loads(self.app.get("/users/"+str(exampleUser['_id'])).data.decode("utf-8"))
		assert areDicsEqual(exampleUser, newUser)
	def testPost(self):
		exampleUser = copy.deepcopy(DUMMY_USER)

		assert self.db.user.find_one(exampleUser) is None

		req = self.app.post("/users", data=json.dumps(exampleUser), content_type="application/json")
		assert req.status_code == 201

		returnedUser = json.loads(req.data.decode("utf-8"))
		returnedUser.pop("_id")
		returnedUser.pop("isVerified")

		assert areDicsEqual(exampleUser, returnedUser)
		assert self.db.user.find_one(exampleUser) is not None
	def testPut(self):
		exampleUser = copy.deepcopy(DUMMY_USER)<commit_msg>add to tests<commit_after>import main
import unittest
import copy
import json
from pymongo import MongoClient

def areDicsEqual(dic1, dic2):
	if len(dic1) != len(dic2):
		print(dic1)
		print(dic2)
		return False
	for k in dic1:
		if k not in dic2:
			print(dic1)
			print(dic2)
			return False

		# Incase one was an ObjectID and the other was a string representation of the object id, cast both to string for evaluation
		if str(dic1[k]) != str(dic2[k]):
			print(dic1)
			print(dic2)
			return False
	return True

class NYCSLTestCase(unittest.TestCase):
	def setUp(self):
		main.db = MongoClient().test
		self.db = main.db
		self.app = main.app.test_client()

	def tearDown(self):
		MongoClient().drop_database("test")

DUMMY_USER = {"email": "<EMAIL>", "name": "<NAME>", "school": "Horace Mann", "password": "<PASSWORD>"}

class UserTestCase(NYCSLTestCase):
	def testGetAll(self):
		assert b'[]' in self.app.get("/users").data

		exampleUser = copy.deepcopy(DUMMY_USER)
		self.db.user.insert_one(exampleUser)
		newUser = json.loads(self.app.get("/users").data.decode("utf-8"))[0]
		assert areDicsEqual(exampleUser, newUser)
	def testGet(self):
		assert self.app.get("/users/1").status_code == 404

		exampleUser = copy.deepcopy(DUMMY_USER)
		self.db.user.insert_one(exampleUser)
		newUser = json.loads(self.app.get("/users/"+str(exampleUser['_id'])).data.decode("utf-8"))
		assert areDicsEqual(exampleUser, newUser)
	def testPost(self):
		exampleUser = copy.deepcopy(DUMMY_USER)

		assert self.db.user.find_one(exampleUser) is None

		req = self.app.post("/users", data=json.dumps(exampleUser), content_type="application/json")
		assert req.status_code == 201

		returnedUser = json.loads(req.data.decode("utf-8"))
		assert "_id" in returnedUser
		returnedUser.pop("_id")
		assert "isVerified" in returnedUser
		returnedUser.pop("isVerified")

		assert areDicsEqual(exampleUser, returnedUser)
		assert self.db.user.find_one(exampleUser) is not None
	def testPut(self):
		exampleUser = copy.deepcopy(DUMMY_USER)
{'fraction_non_alphanumeric': 0.13996968165740273, 'fraction_numerical': 0.012632642748863061, 'mean_word_length': 4.953383458646616, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3168247', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1421, 'n_words': 307}