def update_project(project_id, body):
    project = Project.from_dict(body)
    with Transaction() as t:
        admin_repo = AdminRepo(t)
        admin_repo.update_project(project_id, project)
        t.commit()

        return '', 204
Example #2
0
    def test_update_project_success(self):
        updated_dict = self._FULL_PROJECT_DICT.copy()
        updated_dict[p.PROJ_NAME_KEY] = 'test_proj'
        with Transaction() as t:
            admin_repo = AdminRepo(t)

            input = p.Project.from_dict(updated_dict)
            # existing project 8 in test db
            admin_repo.update_project(8, input)

            with t.dict_cursor() as cur:
                cur.execute("SELECT * "
                            "FROM barcodes.project "
                            "WHERE project_id = 8")
                obs_dict = dict(cur.fetchone())

                updated_dict["project_id"] = 8
                updated_dict[p.DB_PROJ_NAME_KEY] = \
                    updated_dict.pop(p.PROJ_NAME_KEY)
                self.assertEqual(obs_dict, updated_dict)
Example #3
0
    def _set_up_and_query_projects(self, t, include_stats, is_active_val):
        updated_dict = self._FULL_PROJECT_DICT.copy()
        updated_dict[p.PROJ_NAME_KEY] = 'test_proj'
        input = p.Project.from_dict(updated_dict)

        admin_repo = AdminRepo(t)
        # existing project 8 in test db
        admin_repo.update_project(8, input)

        set_up_sql = """
            -- add some additional scans to project 8 so can test that
            -- computed statistics based on latest scans are choosing all
            -- (and only) the scans that they should:
            -- add a scan w an earlier timestamp (though added into db
            -- later) than existing one showing that this barcode USED TO
            -- have a problem but no longer does.
            insert into barcodes.barcode_scans
            (barcode, scan_timestamp, sample_status)
            VALUES ('000007640', '2012-11-01', 'no-registered-account');

            -- add a second *sample-is-valid* scan for the same barcode
            -- so can ensure that sample status count are distinct
            insert into barcodes.barcode_scans
            (barcode, scan_timestamp, sample_status)
            VALUES ('000007640', '2012-12-01', 'sample-is-valid');

            -- add two additional scans for a different barcode: a valid
            -- scan followed by a problem scan, thus indicting this sample
            -- currently has a problem.
            insert into barcodes.barcode_scans
            (barcode, scan_timestamp, sample_status)
            VALUES ('000070796', '2020-07-01', 'sample-is-valid');

            insert into barcodes.barcode_scans
            (barcode, scan_timestamp, sample_status)
            VALUES ('000070796', '2020-09-01', 'no-registered-account');

            UPDATE barcodes.project SET is_active = FALSE
            WHERE project_id = 2;
        """
        with t.cursor() as cur:
            cur.execute(set_up_sql)

        output = admin_repo.get_projects(include_stats, is_active_val)

        updated_dict["project_id"] = 8
        computed_stats = \
            {p.NUM_FULLY_RETURNED_KITS_KEY: 1,
             p.NUM_KITS_KEY: 5,
             p.NUM_KITS_W_PROBLEMS_KEY: 1,
             'num_no_associated_source': 0,
             'num_no_collection_info': 0,
             'num_no_registered_account': 1,
             'num_received_unknown_validity': 0,
             'num_sample_is_valid': 4,
             p.NUM_PARTIALLY_RETURNED_KITS_KEY: 2,
             p.NUM_SAMPLES_KEY: 20,
             p.NUM_SAMPLES_RECEIVED_KEY: 5,
             p.NUM_UNIQUE_SOURCES_KEY: 4}

        updated_dict[p.COMPUTED_STATS_KEY] = \
            computed_stats if include_stats else {}

        return updated_dict, output