Guest User

Untitled

a guest
Oct 17th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. #!perl
  2. use strict;
  3. use warnings;
  4. use Test::More;
  5. use JSON;
  6. use HTTP::Request::Common qw(PUT POST DELETE);
  7.  
  8. use lib 't/lib';
  9.  
  10. use A;
  11. use Lynx::Constants 'DEFAULT_COMPUTERGROUP_NAME';
  12.  
  13. my $mech = A->mech({ live_only => 1, login => 0 });
  14. my $schema = A->schema({ test => 0, deploy => 0 });
  15.  
  16. my ($computer_group, $computer);
  17.  
  18. my $computers = $schema->resultset('Computer')->search({ name => 'testcomputer' });
  19. my $computer_groups = $schema->resultset('ComputerGroup')->search({ name => 'test group' });
  20.  
  21. subtest 'setup' => sub {
  22. $mech->get( "/cgi/logon.plx?UserID=admin&Password=lynx" );
  23. $mech->content_lacks( 'Login Error', 'Login as admin');
  24.  
  25. $computers->delete;
  26.  
  27. for ($computer_groups->get_column('id')->all) {
  28. my $url = "/app/admin/computer_groups/$_";
  29. $mech->request(DELETE $url,
  30. Accept => 'application/json',
  31. );
  32. ok($mech->success, "DELETE $url");
  33. }
  34.  
  35. is($computer_groups->count, 0, 'no test group yet');
  36.  
  37. $mech->request(POST '/app/admin/computer_groups',
  38. Accept => 'application/json',
  39. content_type => 'application/json',
  40. Content => encode_json({
  41. data => {
  42. is_active => \1,
  43. name => 'test group',
  44. profile => '{}',
  45. }
  46. })
  47. );
  48. ok($mech->success, "POST /app/admin/computer_groups");
  49.  
  50. is($computer_groups->count, 1, 'test group created');
  51.  
  52. $computer_group = $computer_groups->single;
  53.  
  54. is($computers->count, 0, 'no test computer yet');
  55.  
  56. $computer = $computers->create({
  57. group_id => $computer_group->id,
  58. user => 'unknown',
  59. version => 'unknown',
  60. is_active => 1,
  61. });
  62.  
  63. is($computers->count, 1, 'test computer created');
  64.  
  65. $mech->get( "/cgi/logon.plx?Option=Logout" );
  66.  
  67. $mech->get( "/cgi/logon.plx?UserID=test&Password=test" );
  68. $mech->content_lacks( 'Login Error', 'Login as test');
  69.  
  70. $mech->request(PUT '/app/computers/remove_by_id',
  71. Accept => 'application/json',
  72. content_type => 'application/json',
  73. Content => encode_json({
  74. ids => [$computers->get_column('id')->all]
  75. })
  76. );
  77. ok($mech->success, "PUT /app/computers/remove_by_id");
  78. $computer->discard_changes;
  79. ok(!$computer->is_active, 'computer deactivated');
  80. };
  81.  
  82. $mech->get( "/cgi/logon.plx?Option=Logout" );
  83. $mech->get( "/cgi/logon.plx?UserID=admin&Password=lynx" );
  84. $mech->content_lacks( 'Login Error', 'Login as admin');
  85.  
  86. for ($computer_groups->get_column('id')->all) {
  87. my $url = "/app/admin/computer_groups/$_";
  88. $mech->request(DELETE $url,
  89. Accept => 'application/json',
  90. );
  91. use Devel::Dwarn;
  92. ok($mech->success, "DELETE $url") or Ddie $mech->content;
  93. }
  94.  
  95. $computer->discard_changes;
  96.  
  97. is($computer->group->name, DEFAULT_COMPUTERGROUP_NAME, 'computer correctly got pointed at DCG');
  98.  
  99. subtest 'teardown' => sub {
  100. $computers->delete;
  101. is($computer_groups->count, 0, 'test group removed');
  102. is($computers->count, 0, 'test computer removed');
  103. };
  104.  
  105.  
  106. done_testing;
Add Comment
Please, Sign In to add comment