Ejemplo n.º 1
0
 def delete_mapped(self):
     """Delete project mapped to Program."""
     program = all_models.Program.query.get(self.program_id)
     with factories.single_commit():
         project = factories.ProjectFactory()
         factories.RelationshipFactory(source=project, destination=program)
     return self.api.delete(project)
Ejemplo n.º 2
0
 def update_mapped(self):
     """Update project mapped to Program."""
     program = all_models.Program.query.get(self.program_id)
     with factories.single_commit():
         project = factories.ProjectFactory()
         factories.RelationshipFactory(source=project, destination=program)
     return self.api.put(project, {"title": factories.random_str()})
Ejemplo n.º 3
0
  def setUp(self):
    self.api = api_helper.Api()
    with factories.single_commit():
      source_id = factories.ProjectFactory().id
      destination_id = factories.ProjectFactory().id
      del_source_id = factories.ProjectFactory().id
      del_destination_id = factories.ProjectFactory().id

    self.objects = {
        "source": {"type": "Project", "id": source_id},
        "destination": {"type": "Project", "id": destination_id},
        "deleted_source": {"type": "Project", "id": del_source_id},
        "deleted_destination": {"type": "Project", "id": del_destination_id},
    }

    self.api.delete(all_models.Project, id_=del_source_id)
    self.api.delete(all_models.Project, id_=del_destination_id)
Ejemplo n.º 4
0
    def test_unmapping(self):
        """Test field type validation."""
        with factories.single_commit():
            first_object = factories.ProjectFactory()
            first_type = first_object.type
            first_id = first_object.id
            second_object = factories.ProgramFactory()
            second_type = second_object.type
            second_id = second_object.id

            relationship_1 = factories.RelationshipFactory(
                source=first_object,
                destination=second_object,
                is_external=True).id
            relationship_2 = factories.RelationshipFactory(
                source=second_object,
                destination=first_object,
                is_external=True).id

        body = {
            "first_object_id": first_id,
            "first_object_type": first_type,
            "second_object_id": second_id,
            "second_object_type": second_type,
        }

        response = self.client.post(self.ENDPOINT_URL,
                                    content_type="application/json",
                                    data=json.dumps(body))

        self.assertEqual(200, response.status_code)

        deleted_count = json.loads(response.data)["count"]
        self.assertEqual(2, deleted_count)

        remained_count = Relationship.query.filter(
            sa.or_(
                sa.and_(Relationship.source_type == first_type,
                        Relationship.source_id == first_id,
                        Relationship.destination_type == second_type,
                        Relationship.destination_id == second_id),
                sa.and_(Relationship.source_type == second_type,
                        Relationship.source_id == second_id,
                        Relationship.destination_type == first_type,
                        Relationship.destination_id == first_id))).count()
        self.assertEqual(0, remained_count)

        self.assertEqual(None, Relationship.query.get(relationship_1))
        self.assertEqual(None, Relationship.query.get(relationship_2))
Ejemplo n.º 5
0
    def test_delete(self):
        """Deletion is synchronous and triggers compute_attributes."""
        project = factories.ProjectFactory()

        with mock.patch(
                "ggrc.models.background_task.create_task", ) as create_task:
            result = self.api.delete(project)
            projects = db.session.query(all_models.Project).all()
            event_id = db.session.query(func.max(
                all_models.Event.id)).first()[0]

            self.assert200(result)
            self.assertEqual(len(projects), 0)
            self.assertEqual(
                db.session.query(all_models.BackgroundTask).count(), 0)
            create_task.assert_called_once_with(
                name="compute_attributes",
                url="/_background_tasks/compute_attributes",
                parameters={
                    "revision_ids": None,
                    "event_id": event_id
                },
                method="POST",
                queued_callback=views.compute_attributes)