MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / TestWriteUsersInPGAdmin

Function TestWriteUsersInPGAdmin

internal/pgadmin/users_test.go:25–255  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestWriteUsersInPGAdmin(t *testing.T) {
26 ctx := context.Background()
27 cluster := &v1beta1.PostgresCluster{
28 ObjectMeta: metav1.ObjectMeta{
29 Name: "testcluster",
30 Namespace: "testnamespace",
31 },
32 Spec: v1beta1.PostgresClusterSpec{
33 Port: initialize.Int32(5432),
34 },
35 }
36
37 t.Run("Arguments", func(t *testing.T) {
38 expected := errors.New("pass-through")
39 exec := func(
40 _ context.Context, stdin io.Reader, stdout, stderr io.Writer, command ...string,
41 ) error {
42 assert.Assert(t, stdin != nil, "should send stdin")
43 assert.Assert(t, stdout != nil, "should capture stdout")
44 assert.Assert(t, stderr != nil, "should capture stderr")
45
46 assert.Check(t, !strings.ContainsRune(strings.Join(command, ""), '\t'),
47 "Python should not be indented with tabs")
48
49 assert.DeepEqual(t, command, []string{"python", "-c", `
50import sys
51import types
52
53cluster = types.SimpleNamespace()
54(cluster.name, cluster.hostname, cluster.port) = sys.argv[1:]
55
56import importlib.util
57import os
58import sys
59
60spec = importlib.util.find_spec('.pgadmin', (
61 importlib.util.find_spec('pgadmin4') or
62 importlib.util.find_spec('pgadmin4-web')
63).name)
64root = os.path.dirname(spec.submodule_search_locations[0])
65if sys.path[0] != root:
66 sys.path.insert(0, root)
67
68import copy
69import json
70import sys
71
72from pgadmin import create_app
73from pgadmin.model import db, Role, User, Server, ServerGroup
74from pgadmin.utils.constants import INTERNAL
75from pgadmin.utils.crypto import encrypt
76
77with create_app().app_context():
78
79 admin = db.session.query(User).filter_by(id=1).first()
80 admin.active = False
81 admin.email = ''
82 admin.password = ''

Callers

nothing calls this directly

Calls 4

Int32Function · 0.92
Flake8Function · 0.92
WriteUsersInPGAdminFunction · 0.85
EqualMethod · 0.45

Tested by

no test coverage detected