Your code works properly, but you can just put model.train() and model.eval() right before the corresponding for loop for training and validating, not do it for every loop.
# Train the model
oneEpochLossList_train = []
model.train()
for i, batch in enumerate(train_loader):
   ...

# Test the model with current parameters
oneEpochLossList_test = []
model.eval()
for j, batch in enumerate(test_loader):
    ...