예제 #1
0
 def test_try_to_generate_nodes_without_any_category(self):
     self.assertEqual(0, ErrorLog.query().count())
     self.assertEqual(0, Node.query().count())
     generate_nodes_through_spreadsheet(graph=self.graph)
     self.assertEqual(0, Node.query().count())
     self.assertEqual(1, ErrorLog.query().count())
     self.assertEqual(1, Style.query(Style.graph == self.graph.key).count())
예제 #2
0
 def test_try_to_generate_nodes_without_any_category(self):
     self.assertEqual(0, ErrorLog.query().count())
     self.assertEqual(0, Node.query().count())
     generate_nodes_through_spreadsheet(graph=self.graph)
     self.assertEqual(0, Node.query().count())
     self.assertEqual(1, ErrorLog.query().count())
     self.assertEqual(1, Style.query(Style.graph == self.graph.key).count())
예제 #3
0
 def test_generate_nodes_with_good_and_bad_data(self):
     self.assertEqual(0, ErrorLog.query().count())
     self.assertEqual(0, Node.query().count())
     generate_nodes_through_spreadsheet(graph=self.graph)
     self.assertEqual(len(GOOD_NODES), Node.query(Node.is_category == True).count())
     self.assertEqual(len(FETCHED_CATEGORIES), Node.query(Node.is_category == False).count())
     self.assertEqual(1, Style.query(Style.graph == self.graph.key).count())
     self.assertEqual(1, ErrorLog.query().count())
예제 #4
0
 def test_generate_nodes_with_good_and_bad_data(self):
     self.assertEqual(0, ErrorLog.query().count())
     self.assertEqual(0, Node.query().count())
     generate_nodes_through_spreadsheet(graph=self.graph)
     self.assertEqual(len(GOOD_NODES),
                      Node.query(Node.is_category == True).count())
     self.assertEqual(len(FETCHED_CATEGORIES),
                      Node.query(Node.is_category == False).count())
     self.assertEqual(1, Style.query(Style.graph == self.graph.key).count())
     self.assertEqual(1, ErrorLog.query().count())
예제 #5
0
 def test_all_graph_related_entities_should_be_deleted_before_updating_the_graph(self):
     self.assertEqual(0, ErrorLog.query().count())
     self.assertEqual(0, Node.query().count())
     self.assertEqual(0, Style.query().count())
     generate_nodes_through_spreadsheet(graph=self.graph)
     categories_before = Node.query(Node.is_category == True).count()
     nodes_before = Node.query(Node.is_category == False).count()
     style_before = Style.query(Style.graph == self.graph.key).count()
     logs_before = ErrorLog.query().count()
     generate_nodes_through_spreadsheet(graph=self.graph)
     self.assertEqual(categories_before, Node.query(Node.is_category == True).count())
     self.assertEqual(nodes_before, Node.query(Node.is_category == False).count())
     self.assertEqual(style_before, Style.query(Style.graph == self.graph.key).count())
     self.assertEqual(logs_before, ErrorLog.query().count())
예제 #6
0
 def test_all_graph_related_entities_should_be_deleted_before_updating_the_graph(
         self):
     self.assertEqual(0, ErrorLog.query().count())
     self.assertEqual(0, Node.query().count())
     self.assertEqual(0, Style.query().count())
     generate_nodes_through_spreadsheet(graph=self.graph)
     categories_before = Node.query(Node.is_category == True).count()
     nodes_before = Node.query(Node.is_category == False).count()
     style_before = Style.query(Style.graph == self.graph.key).count()
     logs_before = ErrorLog.query().count()
     generate_nodes_through_spreadsheet(graph=self.graph)
     self.assertEqual(categories_before,
                      Node.query(Node.is_category == True).count())
     self.assertEqual(nodes_before,
                      Node.query(Node.is_category == False).count())
     self.assertEqual(style_before,
                      Style.query(Style.graph == self.graph.key).count())
     self.assertEqual(logs_before, ErrorLog.query().count())
예제 #7
0
    def test_generate_nodes_with_good_data(self):
        self.assertEqual(0, ErrorLog.query().count())
        self.assertEqual(0, Node.query().count())
        self.assertEqual(0, Style.query().count())
        generate_nodes_through_spreadsheet(graph=self.graph)
        self.assertEqual(len(GOOD_NODES),
                         Node.query(Node.is_category == True).count())
        self.assertEqual(len(FETCHED_CATEGORIES),
                         Node.query(Node.is_category == False).count())
        self.assertEqual(1, Style.query(Style.graph == self.graph.key).count())
        self.assertEqual(0, ErrorLog.query().count())

        # now let's check ALL THE DATA
        node_1 = Node.query(Node.name == "Bruce Dickinson").get()
        self.assertEqual(node_1.name, "Bruce Dickinson")
        self.assertEqual(
            ','.join([category.get().name for category in node_1.categories]),
            "Metal")
        self.assertEqual(node_1.importance, 5)
        self.assertEqual(node_1.short_description, None)
        self.assertEqual(node_1.long_description, None)
        self.assertEqual(node_1.context_url, None)
        self.assertEqual(node_1.credit, None)
        self.assertEqual(node_1.node_style, None)
        self.assertEqual(node_1.label_style, None)

        node_2 = Node.query(Node.name == "Rob Halford").get()
        self.assertEqual(node_2.name, "Rob Halford")
        self.assertEqual(
            ','.join([category.get().name for category in node_2.categories]),
            "Metal")
        self.assertEqual(node_2.importance, 6)
        self.assertEqual(node_2.short_description, "Judas Priest's singer")
        self.assertEqual(node_2.long_description, None)
        self.assertEqual(node_2.context_url, None)
        self.assertEqual(node_2.credit, None)
        self.assertEqual(node_2.node_style, None)
        self.assertEqual(node_2.label_style, None)

        node_3 = Node.query(Node.name == "Freddie Mercury").get()
        self.assertEqual(node_3.name, "Freddie Mercury")
        self.assertEqual(
            ','.join([category.get().name for category in node_3.categories]),
            "Pop,Rock")
        self.assertEqual(node_3.importance, 10)
        self.assertEqual(node_3.short_description, None)
        self.assertEqual(node_3.long_description, None)
        self.assertEqual(node_3.context_url, "http://www.freddiemercury.com/")
        self.assertEqual(node_3.credit, "Foo")
        self.assertEqual(node_3.node_style, "a-style")
        self.assertEqual(node_3.label_style, "b-style")

        style = Style.query(Style.graph == self.graph.key).get()
        self.assertEqual(
            style.styles,
            '.a-class { font-size: 10px; font-family: verdana }\n.b-class { border: 1px solid green; }'
        )
예제 #8
0
def create_node(gdb, n, graph):
    original_id = n['_slug']
    n['_slug'] = defaultfilters.slugify(n['_slug'])[:150]
    node_properties = {}
    if original_id != n['_slug']:
        node_properties['id'] = original_id
    node_type_obj = NodeType.objects.filter(name=n['_type'])
    if node_type_obj:
        default_properties = node_type_obj[0].nodeproperty_set.all()
        for dp in default_properties:
            node_properties[dp.key] = dp.value
    for key, value in n.items():
        node_properties[key] = value
    result = search_in_index(gdb, n['_slug'], n['_type'], n['_graph'])
    if result:
        counter = 1
        slug = "%s-%s" % (n['_slug'], counter)
        result = search_in_index(gdb, slug, n['_type'], n['_graph'])
        while result:
            counter += 1
            slug = "%s-%s" % (n['_slug'], counter)
            result = search_in_index(gdb, slug, n['_type'], n['_graph'])
        node_properties['_slug'] = slug
    node = gdb.node(**node_properties)
    node.set('_url', "/".join(node.url.split('/')[-2:]))
    idx = gdb.nodes.indexes.get('sylva_nodes')
    idx['_slug'][node['_slug']] = node
    idx['_type'][node['_type']] = node

 
    idx['_graph'][node['_graph']] = node
    sql_node = Node(graph=graph,
                            node_id=node['_slug'],
                            node_type=node['_type'])
    sql_node.save()
    graph.node_set.add(sql_node)
    return node
예제 #9
0
    def test_generate_nodes_with_good_data(self):
        self.assertEqual(0, ErrorLog.query().count())
        self.assertEqual(0, Node.query().count())
        self.assertEqual(0, Style.query().count())
        generate_nodes_through_spreadsheet(graph=self.graph)
        self.assertEqual(len(GOOD_NODES), Node.query(Node.is_category == True).count())
        self.assertEqual(len(FETCHED_CATEGORIES), Node.query(Node.is_category == False).count())
        self.assertEqual(1, Style.query(Style.graph == self.graph.key).count())
        self.assertEqual(0, ErrorLog.query().count())

        # now let's check ALL THE DATA
        node_1 = Node.query(Node.name == "Bruce Dickinson").get()
        self.assertEqual(node_1.name, "Bruce Dickinson")
        self.assertEqual(','.join([category.get().name for category in node_1.categories]), "Metal")
        self.assertEqual(node_1.importance, 5)
        self.assertEqual(node_1.short_description, None)
        self.assertEqual(node_1.long_description, None)
        self.assertEqual(node_1.context_url, None)
        self.assertEqual(node_1.credit, None)
        self.assertEqual(node_1.node_style, None)
        self.assertEqual(node_1.label_style, None)

        node_2 = Node.query(Node.name == "Rob Halford").get()
        self.assertEqual(node_2.name, "Rob Halford")
        self.assertEqual(','.join([category.get().name for category in node_2.categories]), "Metal")
        self.assertEqual(node_2.importance, 6)
        self.assertEqual(node_2.short_description, "Judas Priest's singer")
        self.assertEqual(node_2.long_description, None)
        self.assertEqual(node_2.context_url, None)
        self.assertEqual(node_2.credit, None)
        self.assertEqual(node_2.node_style, None)
        self.assertEqual(node_2.label_style, None)

        node_3 = Node.query(Node.name == "Freddie Mercury").get()
        self.assertEqual(node_3.name, "Freddie Mercury")
        self.assertEqual(','.join([category.get().name for category in node_3.categories]), "Pop,Rock")
        self.assertEqual(node_3.importance, 10)
        self.assertEqual(node_3.short_description, None)
        self.assertEqual(node_3.long_description, None)
        self.assertEqual(node_3.context_url, "http://www.freddiemercury.com/")
        self.assertEqual(node_3.credit, "Foo")
        self.assertEqual(node_3.node_style, "a-style")
        self.assertEqual(node_3.label_style, "b-style")

        style = Style.query(Style.graph == self.graph.key).get()
        self.assertEqual(
            style.styles,
            '.a-class { font-size: 10px; font-family: verdana }\n.b-class { border: 1px solid green; }'
        )
예제 #10
0
 def save(self, *args, **kwargs):
     if self.address and not self.pk:
         n = Node(address=self.address)
         n.save() 
         self.node_id = n.id
     return super(WalkingLocation, self).save()