<commit_before>use saliweb::Test;
use Test::More 'no_plan';
use Test::Exception;
use File::Temp;

BEGIN {
    use_ok('cryptosite');
}

my $t = new saliweb::Test('cryptosite');

# Check job submission

# Check get_submit_page with PDB ID
{
    my $self = $t->make_frontend();
    my $cgi = $self->cgi;

    my $tmpdir = File::Temp::tempdir(CLEANUP=>1);
    ok(chdir($tmpdir), "chdir into tempdir");
    ok(mkdir("incoming"), "mkdir incoming");
    ok(open(FH, "> test.pdb"), "Open test.pdb");
    print FH "REMARK\nATOM      2  CA  ALA     1      26.711  14.576   5.091\n";
    ok(close(FH), "Close test.pdb");
    open(FH, "test.pdb");

    $cgi->param('input_pdb', \*FH);
    $cgi->param('email', '<EMAIL>');
    $cgi->param('chain', 'A');
    my $ret = $self->get_submit_page();
    like($ret, qr/Job Submitted.*You can check on your job/ms,
         "submit page HTML");


    chdir('/') # Allow the temporary directory to be deleted
}

# Test check_pdb_name
{
    throws_ok { cryptosite::check_pdb_name("") }
              saliweb::frontend::InputValidationError,
              "check_pdb_name (bad name)";
    like($@, qr/No coordinate file has been submitted!/,
         "check_pdb_name (bad name, error message)");

    cryptosite::check_pdb_name("ok.pdb");
}

# Test check_chain
{
    throws_ok { cryptosite::check_chain("x") }
              saliweb::frontend::InputValidationError,<commit_msg>Test submit page failures.<commit_after>use saliweb::Test;
use Test::More 'no_plan';
use Test::Exception;
use File::Temp;

BEGIN {
    use_ok('cryptosite');
}

my $t = new saliweb::Test('cryptosite');

# Check job submission

# Check get_submit_page with uploaded PDB
{
    my $self = $t->make_frontend();
    my $cgi = $self->cgi;

    my $tmpdir = File::Temp::tempdir(CLEANUP=>1);
    ok(chdir($tmpdir), "chdir into tempdir");
    ok(mkdir("incoming"), "mkdir incoming");

    $cgi->param('email', '<EMAIL>');
    $cgi->param('chain', 'A');

    throws_ok { $self->get_submit_page() }
              saliweb::frontend::InputValidationError,
              'submit_page, no uploaded PDB';
    like($@, qr/No coordinate file has been submitted/,
         'submit_page, no uploaded PDB, error message');

    ok(open(FH, "> test.pdb"), "Open test.pdb");
    ok(close(FH), "Close test.pdb");
    open(FH, "test.pdb");
    $cgi->param('input_pdb', \*FH);

    throws_ok { $self->get_submit_page() }
              saliweb::frontend::InputValidationError,
              'submit_page, empty uploaded PDB';
    like($@, qr/You have uploaded an empty file/,
         'submit_page, empty uploaded PDB, error message');

    ok(open(FH, "> test.pdb"), "Open test.pdb");
    print FH "REMARK\nATOM      2  CA  ALA     1      26.711  14.576   5.091\n";
    ok(close(FH), "Close test.pdb");
    open(FH, "test.pdb");

    $cgi->param('input_pdb', \*FH);
    my $ret = $self->get_submit_page();
    like($ret, qr/Job Submitted.*You can check on your job/ms,
         "submit page HTML");


    chdir('/') # Allow the temporary directory to be deleted
}

# Test check_pdb_name
{
    throws_ok { cryptosite::check_pdb_name("") }
              saliweb::frontend::InputValidationError,
              "check_pdb_name (bad name)";
    like($@, qr/No coordinate file has been submitted!/,
         "check_pdb_name (bad name, error message)");

    cryptosite::check_pdb_name("ok.pdb");
}

# Test check_chain
{
    throws_ok { cryptosite::check_chain("x") }
              saliweb::frontend::InputValidationError,
{'fraction_non_alphanumeric': 0.1656160458452722, 'fraction_numerical': 0.009742120343839542, 'mean_word_length': 3.175837320574163, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4413200', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1204, 'n_words': 277}