from tests.acceptance.base_acceptance_test import BaseAcceptanceTest
from scalymongo import Document


class IndexTestDocument(Document):
    structure = {
        'number': int,
        'name': unicode,
        'descending': int,
        'ascending': int,
    }
    indexes = [
        {'fields': 'number'},
        {'fields': 'name', 'unique': True},
        {'fields': [('descending', -1), ('ascending', 1)]}
    ]
    __database__ = 'test'
    __collection__ = 'IndexTestDocument'


class TestEnsureIndex(BaseAcceptanceTest):

    @classmethod
    def setup_class(cls):
        BaseAcceptanceTest.setup_class()
        cls.connected_document = cls.connection.models.IndexTestDocument
        cls.connected_document.collection.drop()

        cls.connected_document.ensure_indexes()

        cls.indexes = cls.connected_document.collection.index_information()

    def should_create_index_on_number(self):
        assert self.indexes['number_1'] == {
            'key': [('number', 1)],
            'unique': False,
            'v': 0,
        }

    def should_create_unique_index_on_name(self):
        assert self.indexes['name_1'] == {
            'key': [('name', 1)],
            'unique': True,
            'v': 0,
        }

    def should_create_descending_ascending_index(self):
        assert self.indexes['descending_-1_ascending_1'] == {
            'key': [('descending', -1), ('ascending', 1)],
            'unique': False,
            'v': 0,
        }

@@ -902,38 +902,39 @@
 (self):%0A        
-assert
+index =
  self.indexes%5B'n
@@ -938,29 +938,24 @@
 %5B'number_1'%5D
- == %7B
 %0A           
@@ -947,34 +947,46 @@
 1'%5D%0A        
-    
+assert index%5B
 'key'
-:
+%5D ==
  %5B('number',
@@ -985,25 +985,24 @@
 number', 1)%5D
-,
 %0A           
@@ -994,36 +994,49 @@
 1)%5D%0A        
-    
+assert index.get(
 'unique'
 : False,%0A   
@@ -1027,46 +1027,25 @@
 que'
-:
+,
  False
-,%0A            'v': 0,%0A        %7D
+) is False
 %0A%0A  
@@ -1092,38 +1092,39 @@
 (self):%0A        
-assert
+index =
  self.indexes%5B'n
@@ -1126,29 +1126,24 @@
 es%5B'name_1'%5D
- == %7B
 %0A           
@@ -1135,34 +1135,46 @@
 1'%5D%0A        
-    
+assert index%5B
 'key'
-:
+%5D ==
  %5B('name', 1
@@ -1171,25 +1171,24 @@
 ('name', 1)%5D
-,
 %0A           
@@ -1184,28 +1184,37 @@
         
-    
+assert index%5B
 'unique'
 : True,%0A
@@ -1209,45 +1209,17 @@
 que'
-:
+%5D is
  True
-,%0A            'v': 0,%0A        %7D
 %0A%0A  
@@ -1280,22 +1280,23 @@
         
-assert
+index =
  self.in
@@ -1333,13 +1333,8 @@
 _1'%5D
- == %7B
 %0A   
@@ -1342,18 +1342,30 @@
     
-    
+assert index%5B
 'key'
-:
+%5D ==
  %5B('
@@ -1399,17 +1399,16 @@
 ng', 1)%5D
-,
 %0A       
@@ -1412,20 +1412,33 @@
     
-    
+assert index.get(
 'unique'
 : Fa
@@ -1437,43 +1437,22 @@
 que'
-:
+,
  False
-,%0A            'v': 0,%0A        %7D
+) is False
 %0A

Fix acceptance test for MongoDB 2.0