Exemplo n.º 1
0
    def testDeleteIndexes_deleteAll(self):
        current_indexes = [
            index_api.BuildIndexProto(
                index_api.NO_ANCESTOR, 'Cat', self.Project(), [
                    datastore_index.Property(name=str('name'),
                                             direction='asc'),
                    datastore_index.Property(name=str('age'), direction='asc')
                ]),
            index_api.BuildIndexProto(
                index_api.ALL_ANCESTORS, 'Cat', self.Project(), [
                    datastore_index.Property(name=str('name'),
                                             direction='desc'),
                    datastore_index.Property(name=str('age'), direction='asc')
                ])
        ]
        self.projects_indexes.List.Expect(
            request=self.messages.DatastoreProjectsIndexesListRequest(
                projectId=self.Project()),
            response=self.messages.GoogleDatastoreAdminV1ListIndexesResponse(
                indexes=current_indexes))

        f = self.Touch(self.temp_path, 'index.yaml', 'indexes:\n')
        self.WriteInput('y\n')
        self.Run('datastore indexes cleanup ' + f)
        expected_indexes_to_be_deleted = {
            index_api.ApiMessageToIndexDefinition(index)[0]
            for index in current_indexes
        }
        self.delete_indexes.assert_called_once_with(
            'fakeproject', expected_indexes_to_be_deleted)
Exemplo n.º 2
0
 def testDeleteIndexes_deleteOne(self):
     current_indexes = [
         index_api.BuildIndexProto(
             index_api.NO_ANCESTOR, 'Cat', self.Project(), [
                 datastore_index.Property(name=str('name'),
                                          direction='asc'),
                 datastore_index.Property(name=str('age'),
                                          direction='desc'),
                 datastore_index.Property(name=str('y'), direction='asc')
             ]),
         index_api.BuildIndexProto(
             index_api.ALL_ANCESTORS, 'Cat', self.Project(), [
                 datastore_index.Property(name=str('name'),
                                          direction='desc'),
                 datastore_index.Property(name=str('age'), direction='asc')
             ])
     ]
     current_indexes[0].indexId = str('123')
     current_indexes[1].indexId = str('456')
     self.projects_indexes.List.Expect(
         request=self.messages.DatastoreProjectsIndexesListRequest(
             projectId=self.Project()),
         response=self.messages.GoogleDatastoreAdminV1ListIndexesResponse(
             indexes=current_indexes))
     self.MakeApp()
     self.WriteInput('y\n')
     self.Run('datastore indexes cleanup ' + self.FullPath('index.yaml'))
     expected_indexes_to_be_deleted = {
         index_api.ApiMessageToIndexDefinition(current_indexes[1])[0]
     }
     self.delete_indexes.assert_called_once_with(
         'fakeproject', expected_indexes_to_be_deleted)
Exemplo n.º 3
0
    def testDeleteIndexes_withKeyProperty(self):
        current_indexes = [
            index_api.BuildIndexProto(
                index_api.NO_ANCESTOR, 'Cat', self.Project(), [
                    datastore_index.Property(name=str('name'),
                                             direction='asc'),
                    datastore_index.Property(name=str('age'), direction='desc')
                ]),
            index_api.BuildIndexProto(
                index_api.NO_ANCESTOR, 'Cat', self.Project(), [
                    datastore_index.Property(name=str('name'),
                                             direction='asc'),
                    datastore_index.Property(name=str('city'),
                                             direction='desc')
                ])
        ]
        self.projects_indexes.List.Expect(
            request=self.messages.DatastoreProjectsIndexesListRequest(
                projectId=self.Project()),
            response=self.messages.GoogleDatastoreAdminV1ListIndexesResponse(
                indexes=current_indexes))
        self.MakeApp()
        self.WriteConfig(('index.yaml', """
    indexes:
    - kind: Cat
      ancestor: no
      properties:
      - name: name
      - name: age
        direction: desc
    - kind: Cat
      ancestor: no
      properties:
      - name: name
      - name: city
        direction: desc
      - name: __key__
    """))

        self.WriteInput('y\n')
        self.Run('datastore indexes cleanup ' + self.FullPath('index.yaml'))
        expected_indexes_to_be_deleted = set([])
        self.delete_indexes.assert_called_once_with(
            'fakeproject', expected_indexes_to_be_deleted)
Exemplo n.º 4
0
 def testIndexProtoToDefinitionRoundTrip(self):
   proto = index_api.BuildIndexProto(
       index_api.ALL_ANCESTORS, KIND, PROJECT_ID, [
           datastore_index.Property(name=str('prop1'), direction=str('asc')),
           datastore_index.Property(name=str('prop2'), direction=str('desc')),
       ])
   self.assertEqual(
       proto,
       self._IndexDefinitionToApiMessage(
           PROJECT_ID,
           index_api.ApiMessageToIndexDefinition(proto)[1]))
Exemplo n.º 5
0
 def testDeleteIndexes_nothingToDelete(self):
     current_indexes = [
         index_api.BuildIndexProto(
             index_api.NO_ANCESTOR, 'Cat', self.Project(), [
                 datastore_index.Property(name=str('name'),
                                          direction='asc'),
                 datastore_index.Property(name=str('age'),
                                          direction='desc'),
                 datastore_index.Property(name=str('y'), direction='asc')
             ]),
     ]
     self.projects_indexes.List.Expect(
         request=self.messages.DatastoreProjectsIndexesListRequest(
             projectId=self.Project()),
         response=self.messages.GoogleDatastoreAdminV1ListIndexesResponse(
             indexes=current_indexes))
     self.MakeApp()
     self.WriteInput('y\n')
     self.Run('datastore indexes cleanup ' + self.FullPath('index.yaml'))
     self.delete_indexes.assert_called_once_with('fakeproject', set([]))
Exemplo n.º 6
0
 def testCreate_indexAlreadyExists(self, create_indexes):
     self.projects_indexes.List.Expect(
         request=self.messages.DatastoreProjectsIndexesListRequest(
             projectId=self.Project()),
         response=self.messages.GoogleDatastoreAdminV1ListIndexesResponse(
             indexes=[
                 index_api.BuildIndexProto(
                     index_api.NO_ANCESTOR, 'Cat', self.Project(), [
                         datastore_index.Property(name=str('name'),
                                                  direction=str('asc')),
                         datastore_index.Property(name=str('age'),
                                                  direction=str('desc')),
                     ])
             ]))
     self.strict = False
     self.MakeApp()
     self.WriteInput('y\n')
     self.WriteConfig(('index.yaml', """
 indexes:
 - kind: Cat
   ancestor: no
   properties:
   - name: name
   - name: age
 - kind: Cat
   ancestor: no
   properties:
   - name: name
   - name: age
     direction: desc
 """))
     self.Run('datastore indexes create ' + self.FullPath('index.yaml'))
     create_indexes.assert_called_once_with(
         'fakeproject', {
             index_api.BuildIndex(False, str('Cat'), [(str('name'), 'asc'),
                                                      (str('age'), 'asc')])
         })