import pytest
import unittest
from sqlparse.experiments import view_handler as v

given_views = {'view1':('name','code','A3'),'view2':('code','A2','A3','A4'),'view3':('A1','A2','A4')}
sql = 'select v1.name as nom,V2.code,count(*) from view1 as v1, view2 as v2 where v1.code like "12345" group by nom;'

handler = v.ViewHandler()

class TestViewHandler(unittest.TestCase):

    mentioned_views = list(handler.views_in_from(sql,given_views))
    attributes = list(handler.get_view_attributes(sql,mentioned_views[0]))
	
    def test_views_type(self):
        assert(isinstance(self.mentioned_views,list))
		
    def test_views_mapping(self):
		view1 = self.mentioned_views[0]
		view2 = self.mentioned_views[1]
		assert(view1 == 'view1')
		assert(view2 == 'view2')
		
    def test_views_length(self):
		length = len(self.mentioned_views)
		assert(length == 2)
		
    def test_attributes_belong_to_root(self):
		root_view = given_views[self.mentioned_views[0]]
		assert(self.attributes in root_view)
    
    def test_attributes_mapping(self):
        attr1 = self.attributes[0]
        attr2 = self.attributes[1]
        assert(attr1 == given_views['view1'][0])
        assert(attr2 == given_views['view1'][1])
        
    def test_A3_not_in_attributes(self):
    	check_attr = False
    	if('A3' in self.attributes):
    		check_attr = True
    	assert(check_attr == False)
	
@@ -73,16 +73,32 @@
 ler as v
+%0Aimport sqlparse
 %0A%0Agiven_
@@ -310,16 +310,106 @@
 by nom;'
+%0Asql_tokens = sqlparse.parse(sql)%5B0%5D.tokens%0AtokenList = sqlparse.sql.TokenList(sql_tokens)
 %0A%0Ahandle
@@ -472,20 +472,17 @@
 Case):%0A%0A
-    
+%09
 mentione
@@ -536,20 +536,71 @@
 views))%0A
-    
+%09identifier_list = handler.get_identifiers(tokenList)%0A%09
 attribut
@@ -662,22 +662,101 @@
 ws%5B0%5D))%0A
-%09%0A    
+#---------------------------------------------------------------------------------%09%0A%09
 def test
@@ -774,24 +774,18 @@
 (self):%0A
-        
+%09%09
 assert(i
@@ -821,28 +821,25 @@
 s,list))%0A%09%09%0A
-    
+%09
 def test_vie
@@ -977,28 +977,25 @@
 'view2')%0A%09%09%0A
-    
+%09
 def test_vie
@@ -1074,15 +1074,384 @@
  2)%0A
-%09%09%0A    
+#----------------------------------------------------------------------------------%0A%0A%09def test_get_identifiers_class(self):%0A%09%09wrong_class = True%0A%09%09for token in self.identifier_list:%0A%09%09%09if(isinstance(token, sqlparse.sql.Identifier)):%0A%09%09%09%09wrong_class = False%0A%09%09assert(wrong_class == False)%0A%09%0A#----------------------------------------------------------------------------------%09%0A%09
 def 
@@ -1579,28 +1579,25 @@
 _view)%0A    %0A
-    
+%09
 def test_att
@@ -1619,24 +1619,18 @@
 (self):%0A
-        
+%09%09
 attr1 = 
@@ -1648,24 +1648,18 @@
 utes%5B0%5D%0A
-        
+%09%09
 attr2 = 
@@ -1677,24 +1677,18 @@
 utes%5B1%5D%0A
-        
+%09%09
 assert(a
@@ -1720,24 +1720,18 @@
 1'%5D%5B0%5D)%0A
-        
+%09%09
 assert(a
@@ -1772,20 +1772,17 @@
        %0A
-    
+%09
 def test
@@ -1810,20 +1810,17 @@
 (self):%0A
-    
+%09
 %09check_a
@@ -1831,20 +1831,17 @@
 = False%0A
-    
+%09
 %09if('A3'
@@ -1862,20 +1862,17 @@
 butes):%0A
-    
+%09
 %09%09check_
@@ -1883,20 +1883,17 @@
  = True%0A
-    
+%09
 %09assert(

test for identifiers_list containing only Identifier instances