Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f7c587b

Browse files
author
renzon
committed
Implementada versão Inicial de Conexao, Sessao e Usuario
1 parent 6759e31 commit f7c587b

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

libpythonpro/spam/db.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Sessao:
2+
contador = 0
3+
usuarios = []
4+
5+
def salvar(self, usuario):
6+
Sessao.contador += 1
7+
usuario.id = Sessao.contador
8+
self.usuarios.append(usuario)
9+
10+
def listar(self):
11+
return self.usuarios
12+
13+
def roll_back(self):
14+
pass
15+
16+
def fechar(self):
17+
pass
18+
19+
20+
class Conexao:
21+
def gerar_sessao(self):
22+
return Sessao()
23+
24+
def fechar(self):
25+
pass

libpythonpro/spam/modelos.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Usuario:
2+
def __init__(self, nome):
3+
self.nome = nome
4+
self.id = None

libpythonpro/tests/test_spam/test_usuarios.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from libpythonpro.spam.db import Conexao
2+
from libpythonpro.spam.modelos import Usuario
3+
4+
15
def test_salvar_usuario():
26
conexao = Conexao()
37
sessao = conexao.gerar_sessao()
@@ -15,7 +19,7 @@ def test_listar_usuarios():
1519
usuarios = [Usuario(nome='Renzo'), Usuario(nome='Luciano')]
1620
for usuario in usuarios:
1721
sessao.salvar(usuario)
18-
assert usuario == sessao.listar()
22+
assert usuarios == sessao.listar()
1923
sessao.roll_back()
2024
sessao.fechar()
2125
conexao.fechar()

0 commit comments

Comments
 (0)