Exemple #1
0
 def test_full_list_with_unauthorized_user(self):
     PartyRelationshipFactory.create(project=self.prj,
                                     party1=self.party1,
                                     party2=self.party2)
     response = self.request()
     assert response.status_code == 403
     assert response.content['detail'] == PermissionDenied.default_detail
 def test_left_and_right_project_ids(self):
     with pytest.raises(exceptions.ProjectRelationshipError):
         project1 = ProjectFactory()
         project2 = ProjectFactory()
         PartyRelationshipFactory.create(
             party1__project=project1,
             party2__project=project2
         )
 def test_left_and_right_project_ids(self):
     with pytest.raises(exceptions.ProjectRelationshipError):
         project1 = ProjectFactory()
         project2 = ProjectFactory()
         PartyRelationshipFactory.create(
             party1__project=project1,
             party2__project=project2
         )
Exemple #4
0
 def test_full_list(self):
     PartyRelationshipFactory.create_batch(2,
                                           project=self.prj,
                                           party1=self.party1,
                                           party2=self.party2)
     response = self.request(user=self.user)
     assert response.status_code == 200
     assert len(response.content['results']) == 2
 def test_party_relationship_invalid_attribute(self):
     project = ProjectFactory.create(name='TestProject')
     QuestionnaireFactory.create(project=project)
     content_type = ContentType.objects.get(app_label='party',
                                            model='partyrelationship')
     create_attrs_schema(project=project,
                         dict=party_relationship_xform_group,
                         content_type=content_type,
                         errors=[])
     assert 1 == Schema.objects.all().count()
     with pytest.raises(KeyError):
         PartyRelationshipFactory.create(project=project,
                                         attributes={
                                             'invalid_attribute': 'yes',
                                         })
 def test_party_relationship_invalid_attribute(self):
     project = ProjectFactory.create(name='TestProject')
     QuestionnaireFactory.create(project=project)
     content_type = ContentType.objects.get(
         app_label='party', model='partyrelationship')
     create_attrs_schema(
         project=project, dict=party_relationship_xform_group,
         content_type=content_type, errors=[])
     assert 1 == Schema.objects.all().count()
     with pytest.raises(KeyError):
         PartyRelationshipFactory.create(
             project=project,
             attributes={
                 'invalid_attribute': 'yes',
             }
         )
    def setup_models(self):
        self.user = UserFactory.create()
        assign_policies(self.user)

        self.org = OrganizationFactory.create(slug="namati")
        self.prj = ProjectFactory.create(slug="test-project", organization=self.org, access="public")
        self.party1 = PartyFactory.create(project=self.prj, name="Landowner")
        self.party2 = PartyFactory.create(project=self.prj, name="Leaser")
        self.rel = PartyRelationshipFactory.create(project=self.prj, party1=self.party1, party2=self.party2)
Exemple #8
0
 def test_str(self):
     project = ProjectFactory.build(name='TestProject')
     relationship = PartyRelationshipFactory.build(project=project,
                                                   party1__project=project,
                                                   party1__name='Simba',
                                                   party2__project=project,
                                                   party2__name='Mufasa',
                                                   type='C')
     assert str(relationship) == (
         "<PartyRelationship: <Simba> is-child-of <Mufasa>>")
 def test_str(self):
     project = ProjectFactory.build(name='TestProject')
     relationship = PartyRelationshipFactory.build(
         project=project,
         party1__project=project,
         party1__name='Simba',
         party2__project=project,
         party2__name='Mufasa',
         type='C')
     assert str(relationship) == (
         "<PartyRelationship: <Simba> is-child-of <Mufasa>>")
Exemple #10
0
 def test_repr(self):
     project = ProjectFactory.build(slug='prj')
     party1 = PartyFactory.build(id='abc123', project=project)
     party2 = PartyFactory.build(id='def456', project=project)
     relationship = PartyRelationshipFactory.build(id='abc123',
                                                   project=project,
                                                   party1=party1,
                                                   party2=party2,
                                                   type='C')
     assert repr(relationship) == ('<PartyRelationship id=abc123'
                                   ' party1=abc123 party2=def456'
                                   ' project=prj type=C>')
    def setup_models(self):
        self.user = UserFactory.create()
        assign_policies(self.user)

        self.org = OrganizationFactory.create(slug='namati')
        self.prj = ProjectFactory.create(
            slug='test-project', organization=self.org, access='public')
        self.party1 = PartyFactory.create(project=self.prj, name='Landowner')
        self.party2 = PartyFactory.create(project=self.prj, name='Leaser')
        self.rel = PartyRelationshipFactory.create(
            project=self.prj, party1=self.party1, party2=self.party2)
        self.party3 = PartyFactory.create(project=self.prj, name='Leaser')
    def setup_models(self):
        self.user = UserFactory.create()
        assign_policies(self.user)

        self.org = OrganizationFactory.create(slug='namati')
        self.prj = ProjectFactory.create(slug='test-project',
                                         organization=self.org,
                                         access='public')
        self.party1 = PartyFactory.create(project=self.prj, name='Landowner')
        self.party2 = PartyFactory.create(project=self.prj, name='Leaser')
        self.rel = PartyRelationshipFactory.create(project=self.prj,
                                                   party1=self.party1,
                                                   party2=self.party2)
 def test_repr(self):
     project = ProjectFactory.build(slug='prj')
     party1 = PartyFactory.build(id='abc123', project=project)
     party2 = PartyFactory.build(id='def456', project=project)
     relationship = PartyRelationshipFactory.build(
         id='abc123',
         project=project,
         party1=party1,
         party2=party2,
         type='C')
     assert repr(relationship) == ('<PartyRelationship id=abc123'
                                   ' party1=abc123 party2=def456'
                                   ' project=prj type=C>')
Exemple #14
0
 def test_set_attributes(self):
     # add attribute schema
     content_type = ContentType.objects.get(app_label='party',
                                            model='partyrelationship')
     sch = Schema.objects.create(content_type=content_type, selectors=())
     attr_type = AttributeType.objects.get(name="text")
     Attribute.objects.create(schema=sch,
                              name='description',
                              long_name='Description',
                              required=False,
                              index=1,
                              attr_type=attr_type)
     relationship = PartyRelationshipFactory.create(
         attributes={'description': 'Mad Hatter attends Tea Party'})
     assert relationship.attributes[
         'description'] == 'Mad Hatter attends Tea Party'
 def test_set_attributes(self):
     # add attribute schema
     content_type = ContentType.objects.get(
         app_label='party', model='partyrelationship')
     sch = Schema.objects.create(content_type=content_type, selectors=())
     attr_type = AttributeType.objects.get(name="text")
     Attribute.objects.create(
         schema=sch, name='description', long_name='Description',
         required=False, index=1, attr_type=attr_type
     )
     relationship = PartyRelationshipFactory.create(
         attributes={
             'description':
             'Mad Hatter attends Tea Party'
         })
     assert relationship.attributes[
         'description'] == 'Mad Hatter attends Tea Party'
Exemple #16
0
 def test_party_relationship_schema(self):
     project = ProjectFactory.create(name='TestProject')
     QuestionnaireFactory.create(project=project)
     content_type = ContentType.objects.get(
         app_label='party', model='partyrelationship')
     create_attrs_schema(
         project=project, dict=party_relationship_xform_group,
         content_type=content_type, errors=[])
     pr = PartyRelationshipFactory.create(
         project=project, attributes={
             'notes': 'Some additional textual info'}
     )
     assert 1 == Schema.objects.all().count()
     schema = Schema.objects.get(content_type=content_type)
     assert schema is not None
     assert schema.selectors == [
         project.organization.pk, project.pk, project.current_questionnaire]
     assert 'notes' in pr.attributes.attributes
 def test_party_relationship_schema(self):
     project = ProjectFactory.create(name='TestProject')
     QuestionnaireFactory.create(project=project)
     content_type = ContentType.objects.get(
         app_label='party', model='partyrelationship')
     create_attrs_schema(
         project=project, dict=party_relationship_xform_group,
         content_type=content_type, errors=[])
     pr = PartyRelationshipFactory.create(
         project=project, attributes={
             'notes': 'Some additional textual info'}
     )
     assert 1 == Schema.objects.all().count()
     schema = Schema.objects.get(content_type=content_type)
     assert schema is not None
     assert schema.selectors == [
         project.organization.pk, project.pk, project.current_questionnaire]
     assert 'notes' in pr.attributes.attributes
Exemple #18
0
 def test_project_relationship_invalid(self):
     with pytest.raises(exceptions.ProjectRelationshipError):
         project = ProjectFactory()
         PartyRelationshipFactory.create(party1__project=project)
Exemple #19
0
 def test_relationship_type(self):
     relationship = PartyRelationshipFactory(type='M')
     assert relationship.type == 'M'
     assert relationship.get_type_display() == 'is-member-of'
Exemple #20
0
 def test_project_reverse_relationship(self):
     relationship = PartyRelationshipFactory()
     assert len(relationship.project.party_relationships.all()) == 1
Exemple #21
0
 def test_party_reverse_relationship(self):
     relationship = PartyRelationshipFactory(
         party1__name='Mad Hatter', party2__name='Mad Hatters Tea Party')
     party1_name = str(relationship.party2.relationships_set.all()[0])
     assert party1_name == '<Party: Mad Hatter>'
Exemple #22
0
 def test_relationships_creation(self):
     relationship = PartyRelationshipFactory(
         party1__name='Mad Hatter', party2__name='Mad Hatters Tea Party')
     party2_name = str(relationship.party1.relationships.all()[0])
     assert party2_name == '<Party: Mad Hatters Tea Party>'
 def test_relationship_type(self):
     relationship = PartyRelationshipFactory(type='M')
     assert relationship.type == 'M'
     assert relationship.get_type_display() == 'is-member-of'
 def test_project_relationship_invalid(self):
     with pytest.raises(exceptions.ProjectRelationshipError):
         project = ProjectFactory()
         PartyRelationshipFactory.create(party1__project=project)