Esempio n. 1
0
def test_merge_new_attributes():
    existing_event = Event.from_dict({"source_id": "5498d53c5f2d60095267a0bb",
                                      "tags": {"author": ["Saroj"]}})
    new_event = Event.from_dict({"id": existing_event.id,
                                 "tags": {"reviewer": ["Yusuke"]}})
    _merge(existing_event, new_event)
    assert existing_event.tags["reviewer"] == ["Yusuke"]
Esempio n. 2
0
def test_same_values_not_added_twice():
    existing_event = Event.from_dict({"source_id": "5498d53c5f2d60095267a0bb",
                                      "tags": {"author": ["Yusuke"]}})
    new_event = Event.from_dict({"id": existing_event.id,
                                 "tags": {"author": ["Yusuke"]}})
    _merge(existing_event, new_event)
    assert existing_event.tags["author"] == ["Yusuke"]
Esempio n. 3
0
def test_merge_two_attrs_of_type_lists_with_duplicates():
    existing_event = Event.from_dict({"source_id": "5498d53c5f2d60095267a0bb",
                                      "tags": {"author": ["Yusuke", "Sean"]}})
    new_event = Event.from_dict({"id": existing_event.id,
                                 "tags": {"author": ["Yusuke", "Mayur"]}})
    _merge(existing_event, new_event)
    assert existing_event.tags["author"] == ["Yusuke", "Sean", "Mayur"]
Esempio n. 4
0
def test_merge_two_end_times():
    time = datetime.now()
    existing_event = Event.from_dict({"end_time": time})
    new_event = Event.from_dict(
        {"id": existing_event.id, "end_time": time + timedelta(hours=2)})
    _merge(existing_event, new_event)
    assert existing_event.end_time == new_event.end_time
Esempio n. 5
0
def test_merge_diff_values_of_reserved_keys_raises_exception():
    existing_event = Event({"source_id": "5498d53c5f2d60095267a0bb"})
    new_event = Event({
        "id": existing_event.id,
        "source_id": "5498d53c5f2d60095267a0bc"
    })
    with pytest.raises(ValueError):
        _merge(existing_event, new_event)
Esempio n. 6
0
def test_merge_with_already_existing_keys():
    existing_event = Event.from_dict({"source_id": "5498d53c5f2d60095267a0bb",
                                      "tags": {"author": ["Sean"]}})
    new_event = Event.from_dict({"id": existing_event.id,
                                 "source_id": "5498d53c5f2d60095267a0bb",
                                 "tags": {"author": ["Yusuke"]}})
    _merge(existing_event, new_event)
    assert existing_event.tags["author"] == ["Sean", "Yusuke"]
Esempio n. 7
0
def test_merge_two_descriptions():
    existing_event = Event.from_dict({"source_id": "5498d53c5f2d60095267a0bb",
                                      "description":
                                      "This is a Concrete Event."})
    new_event = Event.from_dict({"id": existing_event.id,
                                 "description": "The version is 2.2.3."})
    _merge(existing_event, new_event)
    test_str = "This is a Concrete Event.\nThe version is 2.2.3."
    assert existing_event.description == test_str
Esempio n. 8
0
def test_merge_empty_event_with_new_one():
    existing_event = Event()
    new_event = Event.from_dict({"id": existing_event.id,
                                 "source_id": "5498d53c5f2d60095267a0bc",
                                 "end_time": existing_event.end_time + timedelta(hours=2)})
    _merge(existing_event, new_event)
    assert existing_event.id == new_event.id
    assert existing_event.source_id == new_event.source_id
    assert existing_event.end_time == new_event.end_time
    assert len(attr.asdict(existing_event)) == len(attr.asdict(new_event))
Esempio n. 9
0
def test_merge_detail_urls():
    existing_event = Event.from_dict({"source_id": "5498d53c5f2d60095267a0bb",
                                      "detail_urls":
                                      {"graphite": "http://graphite",
                                       "concrete": "http://concrete"}})

    new_event = Event.from_dict({"id": existing_event.id,
                                 "detail_urls": {"graphite": "http://graphite",
                                                 "concrete": "http://concrete"}})
    _merge(existing_event, new_event)
    ls = {"graphite": "http://graphite",
          "concrete": "http://concrete"}
    assert existing_event.detail_urls == ls