コード例 #1
0
 def _merge_relationship(self, relationship_type, from_person, to_person):
     relationship = Relationship.type(relationship_type.name)
     tx = self._graph.begin()
     from_node = Node(Person.label(), **from_person.as_dict())
     to_node = Node(Person.label(), **to_person.as_dict())
     new_relationship = relationship(from_node, to_node)
     tx.merge(new_relationship, Person.label(), Person.key())
     tx.push(new_relationship)
     tx.commit()
コード例 #2
0
 def test_create_person(self, flask_test_client, person_repository):
     response = flask_test_client.post(url_string(), data=create_new_person_daren(),
                                       content_type='application/json')
     persons = person_repository.find_list(['*****@*****.**'])
     assert response.status_code == 200
     data = response_json(response)['data']['create_person']['updated_person']
     assert_equals([data], Person.sort_list_as_dict(persons))
コード例 #3
0
 def test_find_grandparents(self, flask_test_client, person_repository):
     response = flask_test_client.post(url_string(), data=query('grandparents', '*****@*****.**'),
                                       content_type='application/json')
     persons = person_repository.find_list(['*****@*****.**', '*****@*****.**'])
     assert response.status_code == 200
     data = response_json(response)['data']['grandparents']
     assert_equals([data], Person.sort_list_as_dict(persons))
コード例 #4
0
 def test_find_cousins(self, flask_test_client, person_repository):
     response = flask_test_client.post(url_string(), data=query('cousins', '*****@*****.**'),
                                       content_type='application/json')
     persons = person_repository.find_list(['*****@*****.**', '*****@*****.**', '*****@*****.**'])
     assert response.status_code == 200
     data = response_json(response)['data']['cousins']
     assert_equals([data], Person.sort_list_as_dict(persons))
コード例 #5
0
 def test_find_siblings(self, flask_test_client, person_repository):
     response = flask_test_client.post(url_string(), data=query('siblings', '*****@*****.**'),
                                       content_type='application/json')
     persons = person_repository.find_list(['*****@*****.**', '*****@*****.**', '*****@*****.**'])
     assert response.status_code == 200
     data = response_json(response)['data']['siblings']
     assert_equals([data], Person.sort_list_as_dict(persons))
コード例 #6
0
    def test_find_person(self, flask_test_client, person_repository):
        response = flask_test_client.post(url_string(), data=query('person', '*****@*****.**'),
                                          content_type='application/json')

        assert response.status_code == 200
        persons = person_repository.find_list(['*****@*****.**'])
        data = response_json(response)['data']['person']
        assert_equals([data], Person.sort_list_as_dict(persons))
コード例 #7
0
 def has_all_properties(cls, **person_input):
     attributes = Person.all_properties()
     invalid_attributes = []
     for attribute in attributes:
         if attribute not in person_input:
             invalid_attributes.append((attribute, ValidationResult.ABSENT))
         elif attribute in person_input and not person_input[attribute]:
             invalid_attributes.append(
                 (attribute, ValidationResult.INVALID))
     return invalid_attributes
コード例 #8
0
    def update_or_create(self, person_input_dict):
        email_validation_result = PersonInputValidator.validate_email(
            **person_input_dict)
        if email_validation_result == ValidationResult.ABSENT or \
                email_validation_result == ValidationResult.INVALID:
            self._logger.warning(
                "valid email is required to insert or update person")
            raise ValueError(
                "valid email is required to insert or update person")

        birthday_validation_result = PersonInputValidator.validate_birthday(
            **person_input_dict)
        if not birthday_validation_result.ABSENT and birthday_validation_result.INVALID:
            self._logger.warning("provided birthday must be valid iso date")
            raise ValueError("provided birthday must be valid iso date")

        person = self.find(person_input_dict['email'])
        property_dict = {}
        if not person:
            properties_validation = PersonInputValidator.has_all_properties(
                **person_input_dict)
            if len(properties_validation) > 0:
                properties = Person.all_properties()
                self._logger.warning("new person requires all properties: " +
                                     ",".join(properties))
                raise ValueError("new person requires all properties: " +
                                 ",".join(properties))
        else:
            property_dict = person.as_dict()

        for key, value in person_input_dict.items():
            property_dict[key] = value
        tx = self._graph.begin()
        node = Node(Person.label(), **property_dict)
        tx.merge(node, Person.label(), Person.key())
        tx.push(node)
        tx.commit()
        return self.find(property_dict['email'])
コード例 #9
0
    def _scan_result_set(self, result_set):
        result = []
        while result_set.forward():
            current = result_set.current
            for value in current.values():
                result.append(
                    Person(email=value['email'],
                           first_name=value['first_name'],
                           last_name=value['last_name'],
                           phone_number=value['phone_number'],
                           address=value['address'],
                           birthday=value['birthday']))

        return result
コード例 #10
0
 def find(self, email):
     person = Person(email=email).find(self._graph)
     return person
コード例 #11
0
ファイル: query.py プロジェクト: frankiennamdi/family-tree
def list_to_schema(persons):
    person_dicts_sorted = Person.sort_list_as_dict(persons)
    return [PersonSchema(**person_dict) for person_dict in person_dicts_sorted]