Skip to content

Commit b65dc7c

Browse files
committed
Add unittests
1 parent e6f38a5 commit b65dc7c

File tree

6 files changed

+365
-25
lines changed

6 files changed

+365
-25
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import unittest
2+
from pathlib import Path
3+
from typing import List
4+
from scripts.get_answered_questions import get_answered_questions, get_question_list
5+
6+
7+
def open_test_case_file(n: int) -> List[bytes]:
8+
tests_path = Path(__file__).parent.joinpath()
9+
10+
with open(f'{tests_path}/testcases/testcase{n}.md', 'rb') as f:
11+
file_list = [line.rstrip() for line in f.readlines()]
12+
return file_list
13+
14+
15+
class QuestionCount(unittest.TestCase):
16+
17+
def test_case_1(self):
18+
raw_list = open_test_case_file(1)
19+
question_list = get_question_list(raw_list)
20+
answers = get_answered_questions(question_list)
21+
22+
self.assertEqual(len(question_list), 11)
23+
self.assertEqual(answers, 3)
24+
25+
def test_case_2(self):
26+
raw_list = open_test_case_file(2)
27+
question_list = get_question_list(raw_list)
28+
answers = get_answered_questions(question_list)
29+
30+
self.assertEqual(len(question_list), 16)
31+
self.assertEqual(answers, 11)

tests/syntax_checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def count_details(file_list):
3636
if b'</details>' in line:
3737
details_final_count += 1
3838

39-
return details_count, details_final_count
39+
return details_count == details_final_count
4040

4141

4242
def check_details_tag(file_list):

tests/syntax_checker_unittest.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,42 @@
33
44
Yes, we do write tests for our tests.
55
"""
6-
import unittest
7-
# import pathlib
6+
from pathlib import Path
7+
from typing import List
8+
from unittest import TestCase
9+
from tests import syntax_checker
810

9-
# from tests import *
10-
# from scripts import get_answered_questions
1111

12+
def open_test_case_file(n: int) -> List[bytes]:
13+
tests_path = Path(__file__).parent.joinpath()
1214

13-
def open_test_case_file(n: int):
14-
pass
15-
# p = pathlib.Path(
16-
# rf'D:\PycharmProjects\devops-interview-questions\scripts\tests\' + '
17-
# testcase{n}.md')
15+
with open(f'{tests_path}/testcases/testcase{n}.md', 'rb') as f:
16+
file_list = [line.rstrip() for line in f.readlines()]
17+
return file_list
1818

19-
# with open(p, 'rb') as f:
20-
# file_list = [line.rstrip() for line in f.readlines()]
21-
# return file_list
2219

20+
test_case_1 = open_test_case_file(1)
21+
test_case_2 = open_test_case_file(2)
22+
test_case_3 = open_test_case_file(3)
2323

24-
class QuestionCount(unittest.TestCase):
25-
solutions = (
2624

27-
)
25+
class TestSyntax(TestCase):
2826

29-
def test_count_case_1(self):
30-
pass
31-
# raw_list = open_test_case_file(1)
32-
# question_list = get_question_list(raw_list)
33-
# answers = get_answered_questions.n_answers(question_list)
27+
def test_details_count_case1(self):
28+
self.assertTrue(syntax_checker.count_details(test_case_1))
3429

35-
# self.assertEqual(len(question_list), 21)
36-
# self.assertEqual(answers, 2)
30+
def test_details_count_case2(self):
31+
self.assertTrue(syntax_checker.count_details(test_case_2))
3732

38-
def test_count_case_2(self):
39-
pass
33+
def test_details_errors_1(self):
34+
syntax_checker.check_details_tag(test_case_1)
35+
self.assertFalse(syntax_checker.errors)
36+
37+
def test_details_errors_2(self):
38+
syntax_checker.check_details_tag(test_case_2)
39+
self.assertFalse(syntax_checker.errors)
40+
#
41+
# def test_details_error_exist_1(self):
42+
# syntax_checker.check_details_tag(test_case_3)
43+
# print(syntax_checker.errors)
44+
# self.assertEqual(len(syntax_checker.errors), 3)

tests/testcases/testcase1.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<details>
2+
<summary>What is Docker? What are you using it for?</summary><br><b>
3+
</b></details>
4+
5+
<details>
6+
<summary>How containers are different from VMs?</summary><br><b>
7+
8+
The primary difference between containers and VMs is that containers allow you to virtualize
9+
multiple workloads on the operating system while in the case of VMs the hardware is being virtualized to
10+
run multiple machines each with its own OS.
11+
</b></details>
12+
13+
<details>
14+
<summary>In which scenarios would you use containers and in which you would prefer to use VMs?</summary><br><b>
15+
16+
You should choose VMs when:
17+
* you need run an application which requires all the resources and functionalities of an OS
18+
* you need full isolation and security
19+
20+
You should choose containers when:
21+
* you need a lightweight solution
22+
* Running multiple versions or instances of a single application
23+
</b></details>
24+
25+
<details>
26+
<summary>Explain Docker architecture</summary><br><b>
27+
</b></details>
28+
29+
<details>
30+
<summary>Describe in detail what happens when you run `docker run hello-world`?</summary><br><b>
31+
32+
Docker CLI passes your request to Docker daemon.
33+
Docker daemon downloads the image from Docker Hub
34+
Docker daemon creates a new container by using the image it downloaded
35+
Docker daemon redirects output from container to Docker CLI which redirects it to the standard output
36+
</b></details>
37+
38+
<details>
39+
<summary>How do you run a container?</summary><br><b>
40+
</b></details>
41+
42+
<details>
43+
<summary>What `docker commit` does?. When will you use it?</summary><br><b>
44+
</b></details>
45+
46+
<details>
47+
<summary>How would you transfer data from one container into another?</summary><br><b>
48+
</b></details>
49+
50+
<details>
51+
<summary>What happens to data of the container when a container exists?</summary><br><b>
52+
</b></details>
53+
54+
<details>
55+
<summary>Explain what each of the following commands do:
56+
57+
* docker run
58+
* docker rm
59+
* docker ps
60+
* docker pull
61+
* docker build
62+
* docker commit</summary><br><b>
63+
</b></details>
64+
65+
<details>
66+
<summary>How do you remove old, non running, containers?</summary><br><b>
67+
</b></details>

tests/testcases/testcase2.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
<details>
2+
<summary>Explain the following code:
3+
4+
<code>:(){ :|:& };:</code>
5+
6+
</summary><br><b>
7+
</b></details>
8+
9+
<details>
10+
<summary>Can you give an example to some Bash best practices?</summary><br><b>
11+
</b></details>
12+
13+
<details>
14+
<summary>What is the ternary operator? How do you use it in bash?</summary><br><b>
15+
16+
A short way of using if/else. An example:
17+
18+
[[ $a = 1 ]] && b="yes, equal" || b="nope"
19+
</b></details>
20+
21+
<details>
22+
<summary>What does the following code do and when would you use it?
23+
24+
<code>diff <(ls /tmp) <(ls /var/tmp)</code>
25+
26+
</summary><br>
27+
It is called 'process substitution'. It provides a way to pass the output of a command to another command when using a pipe <code>|</code> is not possible. It can be used when a command does not support <code>STDIN</code> or you need the output of multiple commands.
28+
https://superuser.com/a/1060002/167769
29+
</details>
30+
31+
32+
## SQL
33+
34+
<a name="sql-beginner"></a>
35+
#### :baby: Beginner
36+
37+
<details>
38+
<summary>What does SQL stand for?</summary><br><b>
39+
40+
Structured Query Language
41+
42+
</b></details>
43+
44+
<details>
45+
<summary>How is SQL Different from NoSQL</summary><br><b>
46+
47+
The main difference is that SQL databases are structured (data is stored in the form of
48+
tables with rows and columns - like an excel spreadsheet table) while NoSQL is
49+
unstructured, and the data storage can vary depending on how the NoSQL DB is set up, such
50+
as key-value pair, document-oriented, etc.
51+
</b></details>
52+
53+
<details>
54+
<summary>What does it mean when a database is ACID compliant?</summary><br>
55+
56+
ACID stands for Atomicity, Consistency, Isolation, Durability. In order to be ACID compliant, the database much meet each of the four criteria
57+
58+
**Atomicity** - When a change occurs to the database, it should either succeed or fail as a whole.
59+
60+
For example, if you were to update a table, the update should completely execute. If it only partially executes, the
61+
update is considered failed as a whole, and will not go through - the DB will revert back to it's original
62+
state before the update occurred. It should also be mentioned that Atomicity ensures that each
63+
transaction is completed as it's own stand alone "unit" - if any part fails, the whole statement fails.
64+
65+
**Consistency** - any change made to the database should bring it from one valid state into the next.
66+
67+
For example, if you make a change to the DB, it shouldn't corrupt it. Consistency is upheld by checks and constraints that
68+
are pre-defined in the DB. For example, if you tried to change a value from a string to an int when the column
69+
should be of datatype string, a consistent DB would not allow this transaction to go through, and the action would
70+
not be executed
71+
72+
**Isolation** - this ensures that a database will never be seen "mid-update" - as multiple transactions are running at
73+
the same time, it should still leave the DB in the same state as if the transactions were being run sequentially.
74+
75+
For example, let's say that 20 other people were making changes to the database at the same time. At the
76+
time you executed your query, 15 of the 20 changes had gone through, but 5 were still in progress. You should
77+
only see the 15 changes that had completed - you wouldn't see the database mid-update as the change goes through.
78+
79+
**Durability** - Once a change is committed, it will remain committed regardless of what happens
80+
(power failure, system crash, etc.). This means that all completed transactions
81+
must be recorded in non-volatile memory.
82+
83+
Note that SQL is by nature ACID compliant. Certain NoSQL DB's can be ACID compliant depending on
84+
how they operate, but as a general rule of thumb, NoSQL DB's are not considered ACID compliant
85+
</details>
86+
87+
<details>
88+
<summary>When is it best to use SQL? NoSQL?</summary><br><b>
89+
90+
SQL - Best used when data integrity is crucial. SQL is typically implemented with many
91+
businesses and areas within the finance field due to it's ACID compliance.
92+
93+
NoSQL - Great if you need to scale things quickly. NoSQL was designed with web applications
94+
in mind, so it works great if you need to quickly spread the same information around to
95+
multiple servers
96+
97+
Additionally, since NoSQL does not adhere to the strict table with columns and rows structure
98+
that Relational Databases require, you can store different data types together.
99+
</b></details>
100+
101+
<details>
102+
<summary>What is a Cartesian Product?</summary><br>
103+
104+
A Cartesian product is when all rows from the first table are joined to all rows in the second
105+
table. This can be done implicitly by not defining a key to join, or explicitly by
106+
calling a CROSS JOIN on two tables, such as below:
107+
108+
Select * from customers **CROSS JOIN** orders;
109+
110+
Note that a Cartesian product can also be a bad thing - when performing a join
111+
on two tables in which both do not have unique keys, this could cause the returned information
112+
to be incorrect.
113+
</details>
114+
115+
##### SQL Specific Questions
116+
117+
For these questions, we will be using the Customers and Orders tables shown below:
118+
119+
**Customers**
120+
121+
Customer_ID | Customer_Name | Items_in_cart | Cash_spent_to_Date
122+
------------ | ------------- | ------------- | -------------
123+
100204 | John Smith | 0 | 20.00
124+
100205 | Jane Smith | 3 | 40.00
125+
100206 | Bobby Frank | 1 | 100.20
126+
127+
**ORDERS**
128+
129+
Customer_ID | Order_ID | Item | Price | Date_sold
130+
------------ | ------------- | ------------- | ------------- | -------------
131+
100206 | A123 | Rubber Ducky | 2.20 | 2019-09-18
132+
100206 | A123 | Bubble Bath | 8.00 | 2019-09-18
133+
100206 | Q987 | 80-Pack TP | 90.00 | 2019-09-20
134+
100205 | Z001 | Cat Food - Tuna Fish | 10.00 | 2019-08-05
135+
100205 | Z001 | Cat Food - Chicken | 10.00 | 2019-08-05
136+
100205 | Z001 | Cat Food - Beef | 10.00 | 2019-08-05
137+
100205 | Z001 | Cat Food - Kitty quesadilla | 10.00 | 2019-08-05
138+
100204 | X202 | Coffee | 20.00 | 2019-04-29
139+
140+
<details>
141+
<summary>How would I select all fields from this table?</summary><br><b>
142+
143+
Select * <br>
144+
From Customers;
145+
</b></details>
146+
147+
<details>
148+
<summary>How many items are in John's cart?</summary><br><b>
149+
150+
Select Items_in_cart <br>
151+
From Customers <br>
152+
Where Customer_Name = "John Smith";
153+
</b></details>
154+
155+
<details>
156+
<summary>What is the sum of all the cash spent across all customers?</summary><br><b>
157+
158+
Select SUM(Cash_spent_to_Date) as SUM_CASH <br>
159+
From Customers;
160+
</b></details>
161+
162+
<details>
163+
<summary>Tell me about your last big project/task you worked on</summary><br><b>
164+
</b></details>
165+
166+
<details>
167+
<summary>What was most challenging part in the project you worked on?</summary><br><b>
168+
</b></details>
169+
170+
<details>
171+
<summary>Why do you want to work here?</summary><br><b>
172+
</b></details>
173+
174+
<details>
175+
<summary>How did you hear about us?</summary><br><b>
176+
177+
Tell them how did you hear about them :D
178+
Relax, there is no wrong or right answer here...I think.
179+
</b></details>

0 commit comments

Comments
 (0)