Exemple #1
0
    def test_add_surname(self):
        app = Application()

        with mock.patch.object(app, "add") as mockadd:
            app.run("cmd add NAME SURNAME    333   ")

        mockadd.assert_called_with("NAME SURNAME", "333")
    def test_missing(self):
        app = Application()

        with pytest.raises(ValueError) as err:
            app.add("NAME", None)

        assert str(err.value) == "A valid phone number is required"
Exemple #3
0
def test_clear():
    app = Application()
    app._contacts == [("NAME", "NUM")]

    app._clear()

    assert app._contacts == []
    def test_invalid(self):
        app = Application()

        with pytest.raises(ValueError) as err:
            app.add("NAME", "not_a_number")

        assert str(err.value) == "Invalid phone number: not_a_number"
    def test_short(self):
        app = Application()

        with pytest.raises(ValueError) as err:
            app.add("NAME", "19")

        assert str(err.value) == "Invalid phone number: 19"
Exemple #6
0
    def test_load(self):
        app = Application()

        with open("./contacts.json", "w+") as f:
            json.dump({"_contacts": [("NAME SURNAME", "3333")]}, f)

        app.load()

        assert app._contacts == [("NAME SURNAME", "3333")]
def test_adding_contacts(name):
    app = Application()

    app.run(f"contacts add {name} 3456789")

    name = name.strip()
    if name:
        assert app._contacts == [(name, "3456789")]
    else:
        assert app._contacts == []
Exemple #8
0
    def test_save(self):
        app = Application()
        app._contacts = [("NAME SURNAME", "3333")]

        try:
            os.unlink("./contacts.json")
        except FileNotFoundError:
            pass

        app.save()

        with open("./contacts.json") as f:
            assert json.load(f) == {"_contacts": [["NAME SURNAME", "3333"]]}
Exemple #9
0
def test_application():
    app = Application()

    assert app._contacts == []
    assert hasattr(app, "run")
Exemple #10
0
    def test_invalid(self):
        app = Application()

        with pytest.raises(ValueError):
            app.run("contacts invalid")
Exemple #11
0
    def test_nocmd(self):
        app = Application()

        with pytest.raises(ValueError):
            app.run("nocmd")
Exemple #12
0
    def test_empty(self):
        app = Application()

        with pytest.raises(ValueError):
            app.run("")
def test_loading(benchmark):
    app = Application()
    app._contacts = [(f"Name {n}", "number") for n in range(1000)]
    app.save()

    benchmark(app.load)
    def test_basic(self):
        app = Application()

        app.add("NAME", "323232")

        assert app._contacts == [("NAME", "323232")]
    def test_international(self):
        app = Application()

        app.add("NAME", "+39323232")

        assert app._contacts == [("NAME", "+39323232")]
    def test_special(self):
        app = Application()

        app.add("Emergency", "911")

        assert app._contacts == [("Emergency", "911")]