Exemple #1
0
class TestIndexedTable__add():

	def setup_method(self):
		self.schema = {"primary_key":"_id"}
		self.file_name = "users.json"
		self.table = IndexedTable(name="users",schema=self.schema)
		self.first_item = get_test_data("users")[0]

	#schema testing	
	def test_when_schema_primary_key_doesnt_exist_in_table_raises_invalid_schema_exception(self):
	 	schema = {"primary_key":"whatnow?"}
	 	table = IndexedTable(name="users", schema=schema)
	 	expect(lambda : table.add(self.first_item)).to(raise_error(InvalidSchemaException))

	
	#loading and indexing
	@patch('zearch.database.BasicIndex')
	def test_when_schema_primary_key_does_exist_in_table_creates_an_index_per_column_in_file(self,mock_index_cls):
		self.table.add(self.first_item)
		num_fields = 19
		mock_constructor_calls = [call for call in mock_index_cls.mock_calls if call == call()]
		expect(len(mock_constructor_calls)).to(equal(num_fields))

	@patch('zearch.database.BasicIndex')
	def test_when_schema_primary_key_does_exist_in_table_hydrates_the_index_with_values_from_that_column(self,mock_index_cls):
		self.table.add(self.first_item)
		indexes = self.table.indexes
		for field in ['_id', 'tags','organization_id']:
			expect(indexes[field].add.mock_calls).to(contain(call(self.first_item,self.first_item[field])))
Exemple #2
0
class TestIndexedTable__fields():
	def setup_method(self):
		self.schema = {"primary_key":"_id"}
		self.file_name = "users.json"
		self.table = IndexedTable(name="users",schema=self.schema)
		self.first_item = get_test_data("users")[0]
		self.table.add(self.first_item)

	def test_fields_returns_all_fields_for_this_table(self):
		expect(self.table.fields()).to(equal(self.first_item.keys()))
Exemple #3
0
	def test_when_schema_primary_key_doesnt_exist_in_table_raises_invalid_schema_exception(self):
	 	schema = {"primary_key":"whatnow?"}
	 	table = IndexedTable(name="users", schema=schema)
	 	expect(lambda : table.add(self.first_item)).to(raise_error(InvalidSchemaException))