Example #1
0
    def test_created_at_filtering(self):
        """Test revision could be filtered by created_at."""
        with freeze_time("2019-01-08 12:00:00"):
            control = factories.ControlFactory()
            control_id = control.id
            factories.RevisionFactory(obj=control)

        expected_ids = set()
        with freeze_time("2019-01-08 23:59:59"):
            rev = factories.RevisionFactory(obj=control)
            expected_ids.add(rev.id)

        self.client.get("/login")
        resp = self._get_first_result_set(
            {
                "object_name": "Revision",
                "type": "ids",
                "filters": {
                    "expression": {
                        "op": {
                            "name": "AND"
                        },
                        "left": {
                            "op": {
                                "name": "AND"
                            },
                            "left": {
                                "op": {
                                    "name": "="
                                },
                                "left": "resource_type",
                                "right": "Control"
                            },
                            "right": {
                                "op": {
                                    "name": "="
                                },
                                "left": "resource_id",
                                "right": control_id
                            }
                        },
                        "right": {
                            "op": {
                                "name": ">"
                            },
                            "left": "created_at",
                            "right": "2019-01-08 12:00:00"
                        }
                    }
                }
            }, "Revision", "ids")
        self.assertItemsEqual(resp, expected_ids)
 def test_asmt_state_updating_verifiers_with_map_fields(
     self, map_factory, map_column_name, new_verifier
 ):
   """Test assessment In Progress after updating Verifiers and map fields"""
   with factories.single_commit():
     audit = factories.AuditFactory()
     map_object = map_factory()
     spanpshot = factories.SnapshotFactory(
         parent=audit,
         child_id=map_object.id,
         child_type=map_object.__class__.__name__,
         revision=factories.RevisionFactory()
     )
     assessment = factories.AssessmentFactory(
         audit=audit,
         status=all_models.Assessment.DONE_STATE,
     )
     person = factories.PersonFactory(email="*****@*****.**")
     factories.RelationshipFactory(source=assessment, destination=spanpshot)
     factories.AccessControlPersonFactory(
         ac_list=assessment.acr_name_acl_map["Verifiers"],
         person=person,
     )
   self.assertEqual(
       all_models.Assessment.query.get(assessment.id).status,
       all_models.Assessment.DONE_STATE)
   response = self.import_data(OrderedDict([
       ("object_type", "Assessment"),
       ("Code", assessment.slug),
       ("Verifiers", new_verifier),
       (map_column_name, map_object.slug),
   ]))
   expected_response = {
       "Assessment": {
           "row_warnings": {
               errors.STATE_WILL_BE_IGNORED.format(line=3),
           }
       }
   }
   self._check_csv_response(response, expected_response)
   assessment = all_models.Assessment.query.get(assessment.id)
   verifiers = [v.email for v in assessment.verifiers]
   self.assertEqual(assessment.status, all_models.Assessment.PROGRESS_STATE)
   self.assertEqual(verifiers or [""], [new_verifier])