Ejemplo n.º 1
0
    def assertManyReferenceHaveImportMetadata(self, actual, expected,
                                              property_name: str):
        actual_refs = sorted(expect.prop_of(actual, property_name).all(),
                             key=lambda ref: ref.import_metadata.external_id)

        expected_refs = sorted(expect.prop_of(expected, property_name))

        self.assertEqual(len(actual_refs), len(expected_refs),
                         "reference lists have same size")

        for i in range(0, len(expected_refs)):
            self.assertHasImportMetadata(actual_refs[i], expected_refs[i])
Ejemplo n.º 2
0
    def assertPropertyEqual(self,
                            actual: Mappable,
                            expected: Mappable,
                            property_name: str,
                            assertion: Callable = None):
        actual_value = expect.prop_of(actual, property_name)
        expected_value = expect.prop_of(expected, property_name)

        if assertion is not None:
            assertion(actual_value, expected_value)
        else:
            self.assertEqual(actual_value, expected_value,
                             "property '%s' value" % property_name)
Ejemplo n.º 3
0
    def assertEmbeddedListEqual(self, actual, expected, property_name: str,
                                comparator):
        actual_items = sorted(list(
            expect.prop_of(actual, property_name).all()),
                              key=lambda e: e.import_metadata.external_id)

        expected_items: List[dict] = sorted(expect.prop_of(
            expected, property_name),
                                            key=lambda e: e["id"])

        self.assertEqual(len(actual_items), len(expected_items))
        for i in range(0, len(expected_items)):
            comparator(actual_items[i], expected_items[i])
Ejemplo n.º 4
0
    def assertHasImportMetadata(self, actual: Mappable, external_id: int):
        metadata = expect.prop_of(actual, "import_metadata")

        self.assertPropertyEqualValue(metadata, "affiliated_store",
                                      self.affiliated_store)
        self.assertPropertyEqualValue(metadata, "external_id", external_id)
        self.assertPropertyNotNone(metadata, "last_updated")
Ejemplo n.º 5
0
    def assertAgencyImport(self, actual: Mappable, expected: Mappable):
        self.assertPropertyNotNone(actual, "id")
        self.assertPropertyEqual(actual, expected, "title")
        self.assertPropertyEqual(actual, expected, "short_name")
        self.assertHasImportMetadata(actual, expected["id"])

        icon = expect.prop_of(actual, "icon")
        self.assertHasImportMetadata(icon, expected["icon"])
Ejemplo n.º 6
0
    def assertPropertyEqualOrNotNone(self, actual: Mappable,
                                     expected: Mappable, property_name: str):
        actual_value = expect.prop_of(actual, property_name)
        expected_value = expect.maybe_prop_of(expected, property_name)

        if expected_value.is_empty:
            self.assertIsNotNone(actual_value,
                                 "property '%s' not None" % property_name)
        else:
            self.assertEqual(actual_value, expected_value.value,
                             "property '%s'" % property_name)
Ejemplo n.º 7
0
    def assertCustomFieldImport(self, actual: Mappable, expected: Mappable):
        self.assertPropertyNotNone(actual, "id")
        self.assertPropertyEqual(actual, expected, "section")
        self.assertPropertyEqual(actual, expected, "display_name")
        self.assertPropertyEqual(actual, expected, "label")
        self.assertPropertyEqual(actual, expected, "description")
        self.assertPropertyEqual(actual, expected, "tooltip")
        self.assertPropertyEqual(actual, expected, "is_required")
        self.assertPropertyEqual(actual, expected, "admin_only")
        self.assertPropertyEqual(actual, expected, "properties")
        self.assertPropertyEqual(actual, expected, "all_listing_types")
        self.assertHasImportMetadata(actual, expected["id"])

        field_type = expect.prop_of(actual, "type")
        self.assertHasImportMetadata(field_type, expected["type"])
Ejemplo n.º 8
0
    def assertPropertyNotNone(self, actual: Mappable, property_name: str):
        actual_value = expect.prop_of(actual, property_name)

        self.assertIsNotNone(actual_value,
                             "property '%s' not None" % property_name)
Ejemplo n.º 9
0
    def assertPropertyEqualValue(self, actual: Mappable, property_name: str,
                                 expected_value: any):
        actual_value = expect.prop_of(actual, property_name)

        self.assertEqual(actual_value, expected_value,
                         "property '%s' value" % property_name)
Ejemplo n.º 10
0
def find_by_internal_id(iterable, internal_id):
    for item in iterable:
        if expect.prop_of(item, "id") == internal_id:
            return item
    return None
Ejemplo n.º 11
0
 def assertReferenceHasImportMetadata(self, actual, expected,
                                      property_name: str):
     reference = expect.prop_of(actual, property_name)
     self.assertHasImportMetadata(reference, expected[property_name])