Пример #1
0
    def test_15_public_indexing(self):
        # Check that public records are indexed correctly

        source = PublicAPCFixtureFactory.example()
        pub = PublicAPC(source)

        apc_record1 = PublicAPCFixtureFactory.apc_record()
        apc_record2 = PublicAPCFixtureFactory.apc_record()

        del apc_record1["amount_inc_vat_gbp"]
        apc_record1["amount_ex_vat_gbp"] = 1000
        apc_record1["vat_gbp"] = 200
        apc_record1["additional_costs"] = 100

        apc_record2["amount_inc_vat_gbp"] = 2400
        apc_record2["amount_ex_vat_gbp"] = 2000
        apc_record2["vat_gbp"] = 400
        apc_record2["additional_costs"] = 200

        pub.apc_records = [apc_record1, apc_record2]
        pub.prep()

        # first check that the amount_inc_vat_gbp was calculated or kept
        assert pub.apc_records[0]["amount_inc_vat_gbp"] == 1200

        # now check all the indexed amounts add up
        assert pub.data.get("index", {}).get("additional_costs") == 300
        assert pub.data.get("index", {}).get("vat") == 600
        assert pub.data.get("index", {}).get("amount_ex_vat") == 3000
        assert pub.data.get("index", {}).get("amount_inc_vat") == 3600
        assert pub.data.get("index", {}).get("grand_total") == 3900
Пример #2
0
    def test_09_remove_permanent(self):
        # Separate an incoming Request from its corresponding PublicAPC, leaving no owners, thus deleting the record

        source = RequestFixtureFactory.example()
        req = Request(source)
        req.owner = "test"

        # create a record with 2 distinct apcs from different owners
        source2 = PublicAPCFixtureFactory.example()
        pub = PublicAPC(source2)
        pub.remove_apcs_by_owner("abcdefg")  # clear the existing apc record

        apc_record = PublicAPCFixtureFactory.apc_record()
        del apc_record["ref"]  # do this so that the ref gets created correctly later
        pub.add_apc_for_owner("test", apc_record)  # add a new, known one

        pub.save(blocking=True)

        # now request the removal
        PublicApi.remove(req)
        time.sleep(2)

        dao = PublicAPC()
        pub2 = dao.pull(pub.id)
        assert pub2 is None
Пример #3
0
    def test_08_public_apc_methods(self):
        # Check all the PublcAPC object methods

        pub = PublicAPC()

        assert len(pub.get_apc_refs("11111")) == 0

        pub.set_apc_ref("11111", "aaaaa")
        assert pub.get_apc_refs("11111")[0] == "aaaaa"

        pub.set_apc_ref("22222", "bbbbb")
        assert len(pub.get_apc_refs("22222")) == 1

        pub.remove_apc_refs("11111")
        assert len(pub.get_apc_refs("22222")) == 1
        assert len(pub.get_apc_refs("11111")) == 0

        assert "11111" not in pub.list_owners()
        assert "22222" in pub.list_owners()

        pub.remove_apc_refs("22222")

        assert len(pub.get_apcs_by_owner("11111")) == 0

        apc_record = PublicAPCFixtureFactory.apc_record()

        first = deepcopy(apc_record)
        first["ref"] = "aaaaa"
        pub.add_apc_for_owner("11111", first)

        assert len(pub.get_apc_refs("11111")) == 1
        assert pub.get_apc_refs("11111")[0] == "aaaaa"
        assert len(pub.get_apcs_by_owner("11111")) == 1
        assert pub.get_apcs_by_owner("11111")[0]["ref"] == "aaaaa"

        second = deepcopy(apc_record)
        second["ref"] = "bbbbb"
        pub.add_apc_for_owner("22222", second)

        assert len(pub.get_apc_refs("22222")) == 1
        assert pub.get_apc_refs("22222")[0] == "bbbbb"
        assert len(pub.get_apcs_by_owner("22222")) == 1
        assert pub.get_apcs_by_owner("22222")[0]["ref"] == "bbbbb"

        assert len(pub.apc_records) == 2

        pub.remove_apcs_by_owner("11111")
        assert len(pub.apc_records) == 1
        assert pub.apc_records[0]["ref"] == "bbbbb"
        assert len(pub.get_apc_refs("22222")) == 1
        assert pub.get_apc_refs("22222")[0] == "bbbbb"
        assert len(pub.get_apcs_by_owner("22222")) == 1
        assert pub.get_apcs_by_owner("22222")[0]["ref"] == "bbbbb"

        pub.remove_apcs_by_owner("22222")
        assert len(pub.apc_records) == 0
        assert len(pub.get_apc_refs("11111")) == 0
        assert len(pub.get_apc_refs("22222")) == 0
Пример #4
0
    def test_06_publish_update(self):
        # Publish an update to an existing PublicAPC

        merge_source = PublicAPCFixtureFactory.record_merge_source()
        merge_target = PublicAPCFixtureFactory.record_merge_target()
        apc_record = PublicAPCFixtureFactory.apc_record()
        result = PublicAPCFixtureFactory.record_merge_result()

        del merge_source["jm:apc"]
        del merge_target["jm:apc"]
        del result["jm:apc"]

        first = deepcopy(apc_record)
        second = deepcopy(apc_record)
        third = deepcopy(apc_record)

        first["organisation_name"] = "First"
        del first["ref"]
        second["organisation_name"] = "Second"
        del second["ref"]
        third["organisation_name"] = "Third"
        del third["ref"]

        req = Request()
        req.record = merge_source
        req.add_apc_record(first)
        req.owner = "11111"

        pub = PublicAPC()
        pub.record = merge_target
        pub.add_apc_for_owner("22222", second)
        pub.add_apc_for_owner("11111", third)
        pub.save(blocking=True)

        PublicApi.publish(req)

        dao = PublicAPC()
        pub2 = dao.pull(pub.id)

        # first check that the apcs are as we would expect
        one = pub2.get_apcs_by_owner("11111")
        two = pub2.get_apcs_by_owner("22222")

        assert len(one) == 1
        assert len(two) == 1
        assert one[0]["organisation_name"] == "First"
        assert two[0]["organisation_name"] == "Second"

        # now check that the metadata merge proceeded correctly
        record = pub2.record
        del record["jm:apc"]
        assert record == result
Пример #5
0
    def test_07_separate_records(self):
        # Separate an incoming Request from its corresponding PublicAPC

        apc_record = PublicAPCFixtureFactory.apc_record()

        req = Request()
        req.owner = "test"

        pub = PublicAPC()
        pub.add_apc_for_owner("test", apc_record)
        pub.add_apc_for_owner("test", apc_record)

        assert len(pub.apc_records) == 2

        PublicApi.separate_records(req, pub)

        assert not pub.has_apcs()
Пример #6
0
    def test_08_remove_separate(self):
        # Separate an incoming Request from its corresponding PublicAPC, leaving only one owner behind

        source = RequestFixtureFactory.example()
        req = Request(source)
        req.owner = "test"

        # create a record with 2 distinct apcs from different owners
        source2 = PublicAPCFixtureFactory.example()
        apc_record = PublicAPCFixtureFactory.apc_record()
        del apc_record["ref"]  # do this so that the ref gets created correctly later
        pub = PublicAPC(source2)
        pub.add_apc_for_owner("test", apc_record)
        pub.save(blocking=True)

        # now request the removal
        PublicApi.remove(req)
        time.sleep(2)

        dao = PublicAPC()
        pub2 = dao.pull(pub.id)

        assert len(pub2.get_apcs_by_owner("test")) == 0
        assert len(pub2.get_apcs_by_owner("abcdefg")) == 1
Пример #7
0
    def test_04_merge_public_apcs(self):
        # Merge two PublicAPC records together

        source_source = PublicAPCFixtureFactory.example()
        target_source = PublicAPCFixtureFactory.example()

        # first try a merge with no apc records (this shouldn't ever happen in normal operation)
        ss1 = deepcopy(source_source)
        del ss1["record"]["jm:apc"]
        source1 = PublicAPC(ss1)

        ts1 = deepcopy(target_source)
        del ts1["record"]["jm:apc"]
        target1 = PublicAPC(ts1)

        result = PublicApi.merge_public_apcs(source1, target1)
        assert len(result.apc_records) == 0

        # next try a merge with only apc records in the source (again, shouldn't really happen in real life)
        ss2 = deepcopy(source_source)
        source2 = PublicAPC(ss2)

        ts2 = deepcopy(target_source)
        del ts2["record"]["jm:apc"]
        target2 = PublicAPC(ts2)

        result = PublicApi.merge_public_apcs(source2, target2)
        assert len(result.apc_records) == 1

        # next try a merge with only apc records in the target (also shouldn't happen in real life)
        ss3 = deepcopy(source_source)
        source3 = PublicAPC(ss3)

        ts3 = deepcopy(target_source)
        del ts3["record"]["jm:apc"]
        target3 = PublicAPC(ts3)

        result = PublicApi.merge_public_apcs(source3, target3)
        assert len(result.apc_records) == 1

        # finally try a merge with the following criteria:
        # replacements apcs and new apcs in the source record
        # existing apcs and other apcs in the target record
        apc_record = PublicAPCFixtureFactory.apc_record()

        first = deepcopy(apc_record)
        first["ref"] = "aaaaa"
        second = deepcopy(apc_record)
        second["ref"] = "bbbbb"
        ss4 = deepcopy(source_source)
        del ss4["record"]["jm:apc"]
        source4 = PublicAPC(ss4)
        source4.add_apc_for_owner("11111", first)
        source4.add_apc_for_owner("11111", second)

        third = deepcopy(apc_record)
        third["ref"] = "ccccc"
        fourth = deepcopy(apc_record)
        fourth["ref"] = "ddddd"
        ts4 = deepcopy(target_source)
        del ts4["record"]["jm:apc"]
        target4 = PublicAPC(ts4)
        target4.add_apc_for_owner("11111", third)
        target4.add_apc_for_owner("22222", fourth)

        result = PublicApi.merge_public_apcs(source4, target4)
        assert len(result.apc_records) == 3

        ones = result.get_apcs_by_owner("11111")
        assert len(ones) == 2
        refs = [o.get("ref") for o in ones]
        assert "aaaaa" in refs
        assert "bbbbb" in refs
        assert "ccccc" not in refs
        assert "ddddd" not in refs

        twos = result.get_apcs_by_owner("22222")
        assert len(twos) == 1
        refs = [o.get("ref") for o in twos]
        assert "aaaaa" not in refs
        assert "bbbbb" not in refs
        assert "ccccc" not in refs
        assert "ddddd" in refs