Example #1
0
def test_missing_arg():
    try:
        # Miss password
        _main("-l mylogin -p password collection-delete".split(" "))
        assert False, "Should have exited here!"
    except DocoptExit as e:
        # docopt breaks exit code management with its DocoptExit class
        assert "Usage:" in e.code
    except Exception as e:
        assert False, "Should have raised a DocoptExit and not %s" % e
Example #2
0
def test_noarg(capsys):
    try:
        _main([])
        assert False, "Should have exited here!"
    except SystemExit as e:
        out, err = capsys.readouterr()

        assert not e.code
        assert "Usage:" in out
        assert "Available commands are:" in out
Example #3
0
def test_help_command(capsys):
    try:
        _main(['help', 'collection-delete'])
        assert False, "Should have exited here!"
    except SystemExit as e:
        out, err = capsys.readouterr()

        assert not e.code
        assert "Usage:" in out
        assert "Available options:" not in out
        assert "Available commands are:" not in out
        assert "collection-delete" in out
Example #4
0
def test_invalid_login(capsys):
    debug_test()
    debug_test("Test a failed authentication...")

    try:
        _main(("-l bggcli -p fake collection-import %s" % COLLECTION_CSV_PATH).split(" "))
    except SystemExit as e:
        out, err = capsys.readouterr()

        assert e.code == 1
        assert "Authenticating" in out
        assert "Authentication failed" in err
        debug_test()
        debug_test("Failed authentication test is OK!")
Example #5
0
def test_invalid_login(capsys):
    debug_test()
    debug_test("Test a failed authentication...")

    try:
        _main(("-l bggcli -p fake collection-import %s" %
               COLLECTION_CSV_PATH).split(" "))
    except SystemExit as e:
        out, err = capsys.readouterr()

        assert e.code == 1
        assert "Authenticating" in out
        assert "Authentication failed" in err
        debug_test()
        debug_test("Failed authentication test is OK!")
Example #6
0
def test_collection(tmpdir):
    """
    End-2-end test to verify collection-delete/export/import services
    """

    debug_test()
    debug_test("End-to-end test is executed in %s" % tmpdir)

    #
    debug_test()
    debug_test("1. Ensure the collection is empty")
    with WebDriver('test_collection-empty') as web_driver:
        if not CollectionPage(web_driver.driver).is_empty(LOGIN):
            try:
                _main([
                    '-v', '--login', LOGIN, '--password', PASSWORD,
                    'collection-delete', '--force', COLLECTION_CSV_PATH
                ])
            except BaseException as e:
                assert False, "Delete command should not fail: %s" % e

            assert CollectionPage(web_driver.driver).is_empty(
                LOGIN), 'Collection should be empty!'
            debug_test("-> [ok (collection was not empty)]")
        else:
            debug_test("-> [ok (collection was empty)]")

    debug_test()
    debug_test("2. Import collection")
    _main([
        '-v', '--login', LOGIN, '--password', PASSWORD, 'collection-import',
        COLLECTION_CSV_PATH
    ])
    debug_test("-> [ok]")

    #
    debug_test()
    debug_test("3. Export collection as CSV")
    actual_file = tmpdir.join('actual-collection.csv').strpath
    assert not os.path.exists(actual_file)
    _main([
        '-v', '--login', LOGIN, '--password', PASSWORD, 'collection-export',
        actual_file
    ])
    assert os.path.isfile(actual_file)
    debug_test("-> [ok]")

    #
    debug_test()
    debug_test("4. Compare CSV files")
    compare_csv_files(actual_file, COLLECTION_CSV_PATH)
    debug_test("Comparison OK!")

    debug_test()
    debug_test("End-to-end test on collection commands is successful!")
Example #7
0
def test_collection(tmpdir):
    """
    End-2-end test to verify collection-delete/export/import services
    """

    debug_test()
    debug_test("End-to-end test is executed in %s" % tmpdir)

    #
    debug_test()
    debug_test("1. Ensure the collection is empty")
    with WebDriver('test_collection-empty') as web_driver:
        if not CollectionPage(web_driver.driver).is_empty(LOGIN):
            try:
                _main(['-v', '--login', LOGIN, '--password', PASSWORD,
                      'collection-delete', '--force', COLLECTION_CSV_PATH])
            except BaseException as e:
                assert False, "Delete command should not fail: %s" % e

            assert CollectionPage(web_driver.driver).is_empty(LOGIN), 'Collection should be empty!'
            debug_test("-> [ok (collection was not empty)]")
        else:
            debug_test("-> [ok (collection was empty)]")

    debug_test()
    debug_test("2. Import collection")
    _main(['-v', '--login', LOGIN, '--password', PASSWORD,
          'collection-import', COLLECTION_CSV_PATH])
    debug_test("-> [ok]")

    #
    debug_test()
    debug_test("3. Export collection as CSV")
    actual_file = tmpdir.join('actual-collection.csv').strpath
    assert not os.path.exists(actual_file)
    _main(['-v', '--login', LOGIN, '--password', PASSWORD,
          'collection-export', actual_file])
    assert os.path.isfile(actual_file)
    debug_test("-> [ok]")

    #
    debug_test()
    debug_test("4. Compare CSV files")
    compare_csv_files(actual_file, COLLECTION_CSV_PATH)
    debug_test("Comparison OK!")

    debug_test()
    debug_test("End-to-end test on collection commands is successful!")
Example #8
0
def test_collection(tmpdir):
    """
    End-2-end test to verify collection-delete/export/import services
    """

    debug_test()
    debug_test("End-to-end test is executed in %s" % tmpdir)

    #
    debug_test()
    debug_test("1. Fetch current collection as CSV")
    delete_list_file = tmpdir.join('delete-collection.csv').strpath
    assert not os.path.exists(delete_list_file)
    _main(['-v', '--login', LOGIN, '--password', PASSWORD,
          'collection-export', delete_list_file])
    assert os.path.isfile(delete_list_file)
    debug_test("-> [ok]")

    #
    debug_test()
    debug_test("2. Delete everything from collection")
    try:
        _main(['-v', '--login', LOGIN, '--password', PASSWORD,
              'collection-delete', '--force', delete_list_file])
    except BaseException as e:
        assert False, "Delete command should not fail: %s" % e

    #
    debug_test()
    debug_test("3. Test that collection is empty")
    delete_check_file = tmpdir.join('delete-check-collection.csv').strpath
    assert not os.path.exists(delete_check_file)
    _main(['-v', '--login', LOGIN, '--password', PASSWORD,
          'collection-export', delete_check_file])
    reader_check_empty = csv.DictReader(open(delete_check_file, 'rU'))
    try:
        reader_check_empty.next()
        assert False, 'Collection should be empty!'
    except StopIteration:
        pass
    debug_test("-> [ok]")

    #
    debug_test()
    debug_test("4. Import collection")
    _main(['-v', '--login', LOGIN, '--password', PASSWORD,
          'collection-import', COLLECTION_CSV_PATH])
    debug_test("-> [ok]")

    #
    debug_test()
    debug_test("5. Export collection as CSV")
    actual_file = tmpdir.join('actual-collection.csv').strpath
    assert not os.path.exists(actual_file)
    _main(['-v', '--login', LOGIN, '--password', PASSWORD,
          'collection-export', actual_file])
    assert os.path.isfile(actual_file)
    debug_test("-> [ok]")

    #
    debug_test()
    debug_test("6. Compare CSV files")
    compare_csv_files(actual_file, COLLECTION_CSV_PATH)
    debug_test("Comparison OK!")

    debug_test()
    debug_test("End-to-end test on collection commands is successful!")