def test_copy(self) -> None: """Test JoinedQuery.copy()""" template_query = census.Query('collection') template_query_list = census.Query('join').limit(100) template_join = census.JoinedQuery('join') # Query from non-list query copy_query = census.JoinedQuery.copy(template_query) self.assertEqual( copy_query.data.collection, template_query.data.collection) self.assertFalse(copy_query.data.is_list) self.assertEqual(copy_query.data.hide, template_join.data.hide) self.assertEqual(copy_query.data.show, template_join.data.show) self.assertEqual(copy_query.data.terms, template_join.data.terms) # Query from list query copy_query_list = census.JoinedQuery.copy(template_query_list) self.assertEqual( copy_query_list.data.collection, template_join.data.collection) self.assertTrue(copy_query_list.data.is_list) # Query from list join copy_join_list = census.JoinedQuery.copy(template_join) self.assertEqual( copy_join_list.data.collection, template_join.data.collection) self.assertEqual(copy_join_list.data, template_join.data) # Try copying a collection-less query template_empty_query = census.Query() with self.assertRaises(TypeError): _ = census.JoinedQuery.copy(template_empty_query)
def test_set_outer(self) -> None: """Test JoinedQuery.set_outer()""" join = census.JoinedQuery('collection') self.assertTrue(join.data.is_outer) join.set_outer(False) self.assertFalse(join.data.is_outer) join.set_outer(True) self.assertTrue(join.data.is_outer)
def test_add_join(self) -> None: """Test QueryBase.add_join()""" query = census.QueryBase('collection') join = census.JoinedQuery('join') query.add_join(join) # The joins cannot be compared directly as the add_join method creates # a copy of the join. self.assertDictEqual(query.joins[0].__dict__, join.__dict__)
def test_serialise(self) -> None: """Test JoinedQuery.serialise()""" join = census.JoinedQuery('collection') serialised_data = join.serialise() self.assertEqual(join.data, serialised_data) join.create_join('nested_join') serialised_data = join.serialise() # NOTE: The values of the serialisation are not checked here as any # errors will become apparent as part of the URL generation. self.assertDictEqual(join.data.__dict__, serialised_data.__dict__)
def test_set_fields(self) -> None: """Test JoinedQuery.set_fields()""" join = census.JoinedQuery('collection') self.assertIsNone(join.data.field_on) self.assertIsNone(join.data.field_to) join.set_fields('field1') self.assertEqual(join.data.field_on, 'field1') self.assertEqual(join.data.field_to, 'field1') join.set_fields('field2', 'field3') self.assertEqual(join.data.field_on, 'field2') self.assertEqual(join.data.field_to, 'field3')
def test_copy(self) -> None: """Test Query.copy()""" template_join = census.JoinedQuery('join') template_join_list = census.JoinedQuery('join').set_list(True) template_query = census.Query('collection') # Query from query copy_query = census.Query.copy(template_query) self.assertEqual(copy_query.data, template_query.data) # Query from non-list join copy_join = census.Query.copy(template_join) self.assertEqual( copy_join.data.collection, template_join.data.collection) self.assertEqual(copy_join.data.hide, template_join.data.hide) self.assertEqual(copy_join.data.show, template_join.data.show) self.assertEqual(copy_join.data.terms, template_join.data.terms) # Query from list join copy_join_list = census.Query.copy(template_join_list) self.assertEqual( copy_join_list.data.collection, template_join.data.collection) self.assertEqual(copy_join_list.data.hide, template_join.data.hide) self.assertEqual(copy_join_list.data.show, template_join.data.show) self.assertEqual(copy_join_list.data.terms, template_join.data.terms) self.assertNotEqual(copy_join_list.data.limit, 1)