Difference between revisions of "DgraphAndWeaviateTest"

From BITPlan Wiki
Jump to navigation Jump to search
Line 34: Line 34:
 
<source lang='bash'>
 
<source lang='bash'>
 
scripts/dgraph -k
 
scripts/dgraph -k
 +
</source>
 +
== Example unit test ==
 +
<source lang='python'>
 +
def testDgraph(self):
 +
        cg=Dgraph(debug=True)
 +
        cg.drop_all()
 +
        schema='''
 +
        name: string @index(exact) .
 +
        weight: float .
 +
        height: float .
 +
type Pokemon {
 +
  name
 +
  weight
 +
  height
 +
}'''
 +
        cg.addSchema(schema)
 +
        pokemonList=[{'name':'Pikachu', 'weight':  6, 'height': 0.4 },
 +
                  {'name':'Arbok',  'weight': 65, 'height': 3.5 },
 +
                  {'name':'Raichu',  'weight': 30, 'height': 0.8 },
 +
                  {'name':'Sandan',  'weight': 12, 'height': 0.6 }]
 +
        cg.addData(obj=pokemonList)
 +
        graphQuery='''{
 +
# list of pokemons
 +
  pokemons(func: has(name)) {
 +
    name
 +
    weight
 +
    height
 +
  }
 +
}'''
 +
        queryResult=cg.query(graphQuery)
 +
        self.assertTrue('pokemons' in queryResult)
 +
        pokemons=queryResult['pokemons']
 +
        self.assertEqual(4,len(pokemons))
 +
        cg.close()
 +
        pass
 
</source>
 
</source>
 
== Example test session ==
 
== Example test session ==
 
see https://travis-ci.org/github/WolfgangFahl/DgraphAndWeaviateTest/jobs/715131236
 
see https://travis-ci.org/github/WolfgangFahl/DgraphAndWeaviateTest/jobs/715131236

Revision as of 08:21, 11 August 2020

OsProject

OsProject
edit
id  DgraphAndWeaviateTest
state  
owner  Wolfgang Fahl
title  DgraphAndWeaviateTest
url  https://github.com/WolfgangFahl/DgraphAndWeaviateTest
version  0.0.1
description  
date  2020/08/05
since  
until  

This is sample project to test Python based access to Dgraph and Weaviate

Installation

https://github.com/WolfgangFahl/DgraphAndWeaviateTest
cd DgraphAndWeaviateTest
scripts/install

Dgraph Installation

docker based pull:

scripts/dgraph -p

Dgraph start

docker based start of

  • alpha
  • ratel
  • zero
scripts/dgraph

Dgraph stop

scripts/dgraph -k

Example unit test

def testDgraph(self):
        cg=Dgraph(debug=True)
        cg.drop_all()
        schema='''
        name: string @index(exact) .
        weight: float .
        height: float .
type Pokemon {
   name
   weight
   height
}'''
        cg.addSchema(schema)
        pokemonList=[{'name':'Pikachu', 'weight':  6, 'height': 0.4 },
                  {'name':'Arbok',   'weight': 65, 'height': 3.5 }, 
                  {'name':'Raichu',  'weight': 30, 'height': 0.8 }, 
                  {'name':'Sandan',  'weight': 12, 'height': 0.6 }]
        cg.addData(obj=pokemonList)
        graphQuery='''{
# list of pokemons
  pokemons(func: has(name)) {
    name
    weight
    height
  }
}'''
        queryResult=cg.query(graphQuery)
        self.assertTrue('pokemons' in queryResult)
        pokemons=queryResult['pokemons']
        self.assertEqual(4,len(pokemons))
        cg.close()
        pass

Example test session

see https://travis-ci.org/github/WolfgangFahl/DgraphAndWeaviateTest/jobs/715131236