-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_docker.py
176 lines (143 loc) · 4.57 KB
/
setup_docker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# pylint: disable=C0413
"""
Set the applications to run inside docker containers.
"""
from os import path
from inspect import cleandoc
import django
django.setup()
from django.contrib.auth import get_user_model
# Own
from main_app.models import Tasks
from task_statistics_app.models import TasksStatistics
def create_super_user() -> None:
"""
This method was created to able tests run locally on Docker.
"""
User = get_user_model()
if not User.objects.filter(username="root").exists():
User.objects.create_superuser("root", "[email protected]", "toor123456")
def create_tasks() -> None:
"""
This method was created to able tests run locally on Docker.
"""
if not Tasks.objects.filter(task_title="Nth Fibonacci Sequence"):
Tasks.objects.create(
task_title="Nth Fibonacci Sequence",
task_description="Write a function that takes in an "
"integer (n) and returns the nth "
"Fibonacci number.",
task_starter="def nth_fib(n: int) -> int:\n\tpass",
task_tests=cleandoc(
'''
import pytest
from .user_solution import *
@pytest.mark.fib_test_case
def test_fib_first():
"""
Test for fib when n = 2
"""
assert 1 == nth_fib(2)
@pytest.mark.fib_test_case
def test_fib_second():
"""
Test for fib when n = 6
"""
assert 8 == nth_fib(6)
@pytest.mark.fib_test_case
def test_fib_third():
"""
Test for fib when n = 19
"""
assert 4181 == nth_fib(19)
''',
),
)
TasksStatistics.objects.create(
task_title=Tasks.objects.get(task_title="Nth Fibonacci Sequence"),
sum_of_all_tries_per_task=0,
sum_of_all_successful_submission_per_task=0,
)
if not Tasks.objects.filter(task_title="Palindrome Checker"):
Tasks.objects.create(
task_title="Palindrome Checker",
task_description="Write a function that takes in a non-empty string and that returns a "
"boolean representing "
"whether the string is palindrome.",
task_starter="def palindrome(string: str) -> bool:\n\tpass",
task_tests=cleandoc(
'''
import pytest
from .user_solution import *
@pytest.mark.palindrome_test_case
def test_palindrome_first():
"""
Palindrome('abcdcba') should return true.
"""
assert palindrome('abcdcba') is True
@pytest.mark.palindrome_test_case
def test_palindrome_second():
"""
Palindrome('nope') should return true.
"""
assert palindrome('nope') is False
@pytest.mark.palindrome_test_case
def test_palindrome_third():
"""
Palindrome('aaaaaaaaaa') should return true.
"""
assert palindrome('aaaaaaaaaa') is True
@pytest.mark.palindrome_test_case
def test_palindrome_fourth():
"""
Palindrome('not a palindrome') should return false.
"""
assert palindrome('not a palindrome') is False
@pytest.mark.palindrome_test_case
def test_palindrome_fifth():
"""
Palindrome('a') should return true.
"""
assert palindrome('a') is True
@pytest.mark.palindrome_test_case
def test_palindrome_sixth():
"""
Palindrome('test') should return false.
"""
assert palindrome('test') is False
@pytest.mark.palindrome_test_case
def test_palindrome_seventh():
"""
Palindrome('sedes') should return true.
"""
assert palindrome('sedes') is True
@pytest.mark.palindrome_test_case
def test_palindrome_eighth():
"""
Palindrome('almostomla') should return false.
"""
assert palindrome('almostomla') is False
''',
),
)
TasksStatistics.objects.create(
task_title=Tasks.objects.get(task_title="Palindrome Checker"),
sum_of_all_tries_per_task=0,
sum_of_all_successful_submission_per_task=0,
)
def create_blank_user_solution_file() -> None:
"""
This method was created because functional tests running locally throws errors is use_solution
file doesn't exists.
"""
expected_file_loc = path.join(
path.dirname(path.realpath(__file__)),
"remote_code_execution_app",
"tests",
"user_solution.py",
)
with open(expected_file_loc, "a"):
pass
if __name__ == "__main__":
create_super_user()
create_tasks()